Skip to content

Commit

Permalink
Add new properties to GeneralSettingsResponse and GeneralSettingsRequ…
Browse files Browse the repository at this point in the history
…est classes
  • Loading branch information
Michel Escalante Álvarez authored and m1k3lm committed Jun 12, 2024
1 parent e6adba2 commit 766ef62
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class GeneralSettingsControllerTest extends BaseTestCase
*/
private $generalSettingsRepository;

private $dummyGeneralSettings;
private $dummyGeneralSettingsRequest;

public function setUp(): void
{
parent::setUp();
Expand All @@ -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'
);
}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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]);

Expand All @@ -165,35 +174,17 @@ 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());
}

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
Expand All @@ -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());
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,31 @@ 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);
$generalSettings->setSendOrderReportsPeriodicallyToSeQura(false);
$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());
}
}

0 comments on commit 766ef62

Please sign in to comment.