diff --git a/src/BusinessLogic/AdminAPI/GeneralSettings/Requests/GeneralSettingsRequest.php b/src/BusinessLogic/AdminAPI/GeneralSettings/Requests/GeneralSettingsRequest.php index 01c4f06..5190712 100644 --- a/src/BusinessLogic/AdminAPI/GeneralSettings/Requests/GeneralSettingsRequest.php +++ b/src/BusinessLogic/AdminAPI/GeneralSettings/Requests/GeneralSettingsRequest.php @@ -37,25 +37,57 @@ class GeneralSettingsRequest extends Request */ private $excludedProducts; + /** + * @var bool + */ + private $enabledForServices; + + /** + * @var bool + */ + private $allowFirstServicePaymentDelay; + + /** + * @var bool + */ + private $allowServiceRegItems; + + /** + * @var string + */ + private $defaultServicesEndDate; + /** * @param bool $sendOrderReportsPeriodicallyToSeQura * @param bool|null $showSeQuraCheckoutAsHostedPage * @param string[]|null $allowedIPAddresses * @param string[]|null $excludedProducts * @param string[]|null $excludedCategories + * @param bool $enabledForServices + * @param bool $allowFirstServicePaymentDelay + * @param bool $allowServiceRegItems + * @param string $defaultServicesEndDate */ public function __construct( bool $sendOrderReportsPeriodicallyToSeQura, ?bool $showSeQuraCheckoutAsHostedPage, ?array $allowedIPAddresses, ?array $excludedProducts, - ?array $excludedCategories + ?array $excludedCategories, + bool $enabledForServices, + bool $allowFirstServicePaymentDelay, + bool $allowServiceRegItems, + string $defaultServicesEndDate ) { $this->sendOrderReportsPeriodicallyToSeQura = $sendOrderReportsPeriodicallyToSeQura; $this->showSeQuraCheckoutAsHostedPage = $showSeQuraCheckoutAsHostedPage; $this->allowedIPAddresses = $allowedIPAddresses; $this->excludedProducts = $excludedProducts; $this->excludedCategories = $excludedCategories; + $this->enabledForServices = $enabledForServices; + $this->allowFirstServicePaymentDelay = $allowFirstServicePaymentDelay; + $this->allowServiceRegItems = $allowServiceRegItems; + $this->defaultServicesEndDate = $defaultServicesEndDate; } /** @@ -70,7 +102,11 @@ public function transformToDomainModel(): object $this->showSeQuraCheckoutAsHostedPage, $this->allowedIPAddresses, $this->excludedProducts, - $this->excludedCategories + $this->excludedCategories, + $this->enabledForServices, + $this->allowFirstServicePaymentDelay, + $this->allowServiceRegItems, + $this->defaultServicesEndDate ); } } diff --git a/src/BusinessLogic/AdminAPI/GeneralSettings/Responses/GeneralSettingsResponse.php b/src/BusinessLogic/AdminAPI/GeneralSettings/Responses/GeneralSettingsResponse.php index 3f82baa..eac21f8 100644 --- a/src/BusinessLogic/AdminAPI/GeneralSettings/Responses/GeneralSettingsResponse.php +++ b/src/BusinessLogic/AdminAPI/GeneralSettings/Responses/GeneralSettingsResponse.php @@ -39,6 +39,10 @@ public function toArray(): array 'allowedIPAddresses' => $this->generalSettings->getAllowedIPAddresses(), 'excludedProducts' => $this->generalSettings->getExcludedProducts(), 'excludedCategories' => $this->generalSettings->getExcludedCategories(), + 'enabledForServices' => $this->generalSettings->isEnabledForServices(), + 'allowFirstServicePaymentDelay' => $this->generalSettings->isAllowFirstServicePaymentDelay(), + 'allowServiceRegItems' => $this->generalSettings->isAllowServiceRegItems(), + 'defaultServicesEndDate' => $this->generalSettings->getDefaultServicesEndDate() ]; } } diff --git a/tests/BusinessLogic/AdminAPI/GeneralSettings/GeneralSettingsControllerTest.php b/tests/BusinessLogic/AdminAPI/GeneralSettings/GeneralSettingsControllerTest.php index 5606cbb..15f9916 100644 --- a/tests/BusinessLogic/AdminAPI/GeneralSettings/GeneralSettingsControllerTest.php +++ b/tests/BusinessLogic/AdminAPI/GeneralSettings/GeneralSettingsControllerTest.php @@ -31,6 +31,9 @@ class GeneralSettingsControllerTest extends BaseTestCase */ private $generalSettingsRepository; + private $dummyGeneralSettings; + private $dummyGeneralSettingsRequest; + public function setUp(): void { parent::setUp(); @@ -40,6 +43,30 @@ public function setUp(): void }); $this->generalSettingsRepository = TestServiceRegister::getService(GeneralSettingsRepositoryInterface::class); + + $this->dummyGeneralSettings = new GeneralSettings( + true, + true, + ['address 1', 'address 2'], + ['sku 1', 'sku 2'], + ['1', '2'], + false, + true, + true, + 'P1Y' + ); + + $this->dummyGeneralSettingsRequest = new GeneralSettingsRequest( + true, + true, + ['address 1', 'address 2'], + ['sku 1', 'sku 2'], + ['1', '2'], + false, + true, + true, + 'P1Y' + ); } /** @@ -89,13 +116,7 @@ public function testGetCategoriesResponseToArray(): void public function testIsGetGeneralSettingsResponseSuccessful(): void { // Arrange - $this->generalSettingsRepository->setGeneralSettings(new GeneralSettings( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - )); + $this->generalSettingsRepository->setGeneralSettings($this->dummyGeneralSettings); // Act $response = AdminAPI::get()->generalSettings('1')->getGeneralSettings(); @@ -110,13 +131,7 @@ public function testIsGetGeneralSettingsResponseSuccessful(): void public function testGetCountryConfigurationResponse(): void { // Arrange - $generalSettings = new GeneralSettings( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); + $generalSettings = $this->dummyGeneralSettings; StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$generalSettings]); $expectedResponse = new GeneralSettingsResponse($generalSettings); @@ -134,13 +149,7 @@ public function testGetCountryConfigurationResponse(): void public function testGetGeneralSettingsResponseToArray(): void { // Arrange - $generalSettings = new GeneralSettings( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); + $generalSettings = $this->dummyGeneralSettings; StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$generalSettings]); @@ -165,17 +174,8 @@ public function testGetNonExistingGeneralSettingsResponseToArray(): void public function testIsSaveResponseSuccessful(): void { - // Arrange - $generalSettings = new GeneralSettingsRequest( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); - // Act - $response = AdminAPI::get()->generalSettings('1')->saveGeneralSettings($generalSettings); + $response = AdminAPI::get()->generalSettings('1')->saveGeneralSettings($this->dummyGeneralSettingsRequest); // Assert self::assertTrue($response->isSuccessful()); @@ -183,17 +183,8 @@ public function testIsSaveResponseSuccessful(): void public function testSaveResponse(): void { - // Arrange - $generalSettings = new GeneralSettingsRequest( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); - // Act - $response = AdminAPI::get()->generalSettings('1')->saveGeneralSettings($generalSettings); + $response = AdminAPI::get()->generalSettings('1')->saveGeneralSettings($this->dummyGeneralSettingsRequest); $expectedResponse = new SuccessfulGeneralSettingsResponse(); // Assert @@ -202,17 +193,8 @@ public function testSaveResponse(): void public function testSaveResponseToArray(): void { - // Arrange - $generalSettings = new GeneralSettingsRequest( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); - // Act - $response = AdminAPI::get()->generalSettings('1')->saveGeneralSettings($generalSettings); + $response = AdminAPI::get()->generalSettings('1')->saveGeneralSettings($this->dummyGeneralSettingsRequest); // Assert self::assertEquals([], $response->toArray()); @@ -223,23 +205,18 @@ public function testSaveResponseToArray(): void */ public function testIsUpdateResponseSuccessful(): void { - // Arrange - $generalSettings = new GeneralSettings( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); - - StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$generalSettings]); + StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$this->dummyGeneralSettings]); $generalSettingsRequest = new GeneralSettingsRequest( false, false, ['address 3', 'address 4'], ['sku 3', 'sku 4'], - ['1', '2'] + ['1', '2'], + true, + false, + false, + 'P2Y' ); // Act @@ -254,23 +231,18 @@ public function testIsUpdateResponseSuccessful(): void */ public function testUpdateResponse(): void { - // Arrange - $generalSettings = new GeneralSettings( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); - - StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$generalSettings]); + StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$this->dummyGeneralSettings]); $generalSettingsRequest = new GeneralSettingsRequest( false, false, ['address 3', 'address 4'], ['sku 3', 'sku 4'], - ['1', '2'] + ['1', '2'], + true, + false, + false, + 'P2Y' ); // Act @@ -286,23 +258,18 @@ public function testUpdateResponse(): void */ public function testUpdateResponseToArray(): void { - // Arrange - $generalSettings = new GeneralSettings( - true, - true, - ['address 1', 'address 2'], - ['sku 1', 'sku 2'], - ['1', '2'] - ); - - StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$generalSettings]); + StoreContext::doWithStore('1', [$this->generalSettingsRepository, 'setGeneralSettings'], [$this->dummyGeneralSettings]); $generalSettingsRequest = new GeneralSettingsRequest( false, false, ['address 3', 'address 4'], ['sku 3', 'sku 4'], - ['1', '2'] + ['1', '2'], + true, + false, + false, + 'P2Y' ); // Act @@ -322,7 +289,11 @@ private function expectedToArrayResponse(): array 'showSeQuraCheckoutAsHostedPage' => true, 'allowedIPAddresses' => ['address 1', 'address 2'], 'excludedProducts' => ['sku 1', 'sku 2'], - 'excludedCategories' => ['1', '2'] + 'excludedCategories' => ['1', '2'], + 'enabledForServices' => false, + 'allowFirstServicePaymentDelay' => true, + 'allowServiceRegItems' => true, + 'defaultServicesEndDate' => 'P1Y' ]; } diff --git a/tests/BusinessLogic/Domain/GeneralSettings/Models/GeneralSettingsModelTest.php b/tests/BusinessLogic/Domain/GeneralSettings/Models/GeneralSettingsModelTest.php index 29da741..d957794 100644 --- a/tests/BusinessLogic/Domain/GeneralSettings/Models/GeneralSettingsModelTest.php +++ b/tests/BusinessLogic/Domain/GeneralSettings/Models/GeneralSettingsModelTest.php @@ -19,7 +19,11 @@ public function testSettersAndGetters(): void true, ['address 1', 'address 2', 'address 3'], ['sku 1', 'sku 2', 'sku 3'], - ['1', '2'] + ['1', '2'], + false, + true, + true, + 'P1Y' ); $generalSettings->setShowSeQuraCheckoutAsHostedPage(false); @@ -27,11 +31,19 @@ public function testSettersAndGetters(): void $generalSettings->setAllowedIPAddresses(['address 4', 'address 5']); $generalSettings->setExcludedProducts(['sku 4', 'sku 5']); $generalSettings->setExcludedCategories(['3', '4']); + $generalSettings->setEnabledForServices(true); + $generalSettings->setAllowFirstServicePaymentDelay(false); + $generalSettings->setAllowServiceRegItems(false); + $generalSettings->setDefaultServicesEndDate('P2Y'); self::assertFalse($generalSettings->isShowSeQuraCheckoutAsHostedPage()); self::assertFalse($generalSettings->isSendOrderReportsPeriodicallyToSeQura()); self::assertEquals(['address 4', 'address 5'], $generalSettings->getAllowedIPAddresses()); self::assertEquals(['sku 4', 'sku 5'], $generalSettings->getExcludedProducts()); self::assertEquals(['3', '4'], $generalSettings->getExcludedCategories()); + self::assertTrue($generalSettings->isEnabledForServices()); + self::assertFalse($generalSettings->isAllowFirstServicePaymentDelay()); + self::assertFalse($generalSettings->isAllowServiceRegItems()); + self::assertEquals('P2Y', $generalSettings->getDefaultServicesEndDate()); } }