Skip to content

Commit

Permalink
begin Call endpoint with CMS reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Freoua-Alma committed Feb 13, 2024
1 parent 336845d commit 431642e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Endpoints/Insurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function getSubscription($subscriptionIds)
return $response->json;
}

public function sendCustomerCart($cmsReferenceArray)
{
$this->insuranceValidator->checkCmsReference($cmsReferenceArray);
}

/**
* @param array $subscriptionArray
* @param string|null $paymentId
Expand Down
22 changes: 22 additions & 0 deletions src/Lib/InsuranceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,26 @@ public function checkSubscriptionIds($subscriptionIds)
));
}
}

/**
* Throw Exception if payload isn't valid
* @throws ParametersException
*/
public function checkCmsReference($cmsReferenceArray)
{
if (is_array($cmsReferenceArray) && !empty($cmsReferenceArray)) {
foreach ($cmsReferenceArray as $cmsReference) {
if (!is_string($cmsReference)) {
throw new ParametersException(sprintf(
'Invalid parameters : %s',
json_encode($cmsReferenceArray)
));
}
}
}
throw new ParametersException(sprintf(
'Invalid parameters : %s',
json_encode($cmsReferenceArray)
));
}
}
15 changes: 15 additions & 0 deletions tests/Unit/Legacy/Endpoints/InsuranceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,19 @@ public function testGetSubscriptionsReturnApiResponse($subscriptionIds, $json)

$this->assertEquals($json, $this->insuranceMock->getSubscription($subscriptionIds));
}


/**
* @return void
*/
public function testGivenInvalidCmsReferenceArrayReturnFalse()
{
//$this->assertFalse($this->insuranceMock->sendCustomerCart($cmsReferenceArray));
}

public function testSendCustomerCartCallApiPostCustomerCartWithCmsReferencesArray()
{


}
}
56 changes: 56 additions & 0 deletions tests/Unit/Legacy/Lib/InsuranceValidatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Alma\API\Tests\Unit\Legacy\Lib;

use Alma\API\Exceptions\ParametersException;
use Alma\API\Lib\InsuranceValidator;
use PHPUnit\Framework\TestCase;

class InsuranceValidatorTest extends TestCase
{


/**
* @dataProvider checkCmsReferenceInvalidPayloadDataProvider
* @param $invalidPayload
* @return void
* @throws ParametersException
*/
public function testCheckCmsReferenceWithInvalidPayloadThrowParameterException($invalidPayload)
{
$this->expectException(ParametersException::class);
$insuranceValidator = new InsuranceValidator();
$insuranceValidator->checkCmsReference($invalidPayload);
}

public function checkCmsReferenceInvalidPayloadDataProvider()
{
return [
'String payload' =>
[
'payload' => 'mb-024, mb-048'
],
'Empty string payload' =>
[
'payload' => ''
],
'Object payload' =>
[
'payload' => new \stdClass()
],
'Empty array' =>
[
'payload' => []
],
'Int payload' =>
[
'payload' => 123
],
'Bool payload' => [
'payload' => true
],
'Object payload in array' => [
'payload' => ['1236', new \stdClass()]
],
];
}}

0 comments on commit 431642e

Please sign in to comment.