Skip to content

Commit

Permalink
OXDEV-7557 Improve the structure of SettingMutation Cests
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 14, 2023
1 parent c9ce469 commit 33c67e5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 89 deletions.
114 changes: 45 additions & 69 deletions tests/Codeception/Acceptance/ModuleSettingMutationsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ public function testChangeIntegerSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runChangeIntegerMutationAndGetResult($I, 'intSetting', 124);

$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data']['changeModuleSettingInteger'];
$I->assertSame('intSetting', $setting['name']);
$I->assertSame(124, $setting['value']);
}

private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, string $name, int $value): array
{
$I->sendGQLQuery(
'mutation m($name: ID!, $value: Int!, $moduleId: String!){
changeModuleSettingInteger(name: $name, value: $value, moduleId: $moduleId) {
Expand All @@ -41,31 +30,27 @@ private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, strin
}
}',
[
'name' => $name,
'value' => $value,
'name' => 'intSetting',
'value' => 124,
'moduleId' => self::TEST_MODULE_ID
]
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
}
$result = $I->grabJsonResponseAsArray();

public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runFloatMutationAndGetResult($I, 'floatSetting', 1.24);
$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data']['changeModuleSettingFloat'];
$I->assertSame('floatSetting', $setting['name']);
$I->assertSame(1.24, $setting['value']);
$setting = $result['data']['changeModuleSettingInteger'];
$I->assertSame('intSetting', $setting['name']);
$I->assertSame(124, $setting['value']);
}

private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name, float $value): array
public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: Float!, $moduleId: String!){
changeModuleSettingFloat(name: $name, value: $value, moduleId: $moduleId) {
Expand All @@ -74,32 +59,27 @@ private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name,
}
}',
[
'name' => $name,
'value' => $value,
'name' => 'floatSetting',
'value' => 1.24,
'moduleId' => self::TEST_MODULE_ID
]
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
}

public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runChangeBooleanMutationAndGetResult($I, 'boolSetting', false);
$result = $I->grabJsonResponseAsArray();

$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data']['changeModuleSettingBoolean'];
$I->assertSame('boolSetting', $setting['name']);
$I->assertSame(false, $setting['value']);
$setting = $result['data']['changeModuleSettingFloat'];
$I->assertSame('floatSetting', $setting['name']);
$I->assertSame(1.24, $setting['value']);
}

private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, string $name, bool $value): array
public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: Boolean!, $moduleId: String!){
changeModuleSettingBoolean(name: $name, value: $value, moduleId: $moduleId) {
Expand All @@ -108,32 +88,27 @@ private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, strin
}
}',
[
'name' => $name,
'value' => $value,
'name' => 'boolSetting',
'value' => false,
'moduleId' => self::TEST_MODULE_ID
]
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
}

public function testChangeStringSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runChangeStringMutationAndGetResult($I, 'stringSetting', 'default');
$result = $I->grabJsonResponseAsArray();

$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data']['changeModuleSettingString'];
$I->assertSame('stringSetting', $setting['name']);
$I->assertSame('default', $setting['value']);
$setting = $result['data']['changeModuleSettingBoolean'];
$I->assertSame('boolSetting', $setting['name']);
$I->assertSame(false, $setting['value']);
}

private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array
public function testChangeStringSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: String!, $moduleId: String!){
changeModuleSettingString(name: $name, value: $value, moduleId: $moduleId) {
Expand All @@ -142,32 +117,27 @@ private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string
}
}',
[
'name' => $name,
'value' => $value,
'name' => 'stringSetting',
'value' => 'default',
'moduleId' => self::TEST_MODULE_ID
]
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
}

public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runChangeCollectionMutationAndGetResult($I, 'arraySetting', '[3, "interesting", "values"]');
$result = $I->grabJsonResponseAsArray();

$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data']['changeModuleSettingCollection'];
$I->assertSame('arraySetting', $setting['name']);
$I->assertSame('[3, "interesting", "values"]', $setting['value']);
$setting = $result['data']['changeModuleSettingString'];
$I->assertSame('stringSetting', $setting['name']);
$I->assertSame('default', $setting['value']);
}

private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array
public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: String!, $moduleId: String!){
changeModuleSettingCollection(name: $name, value: $value, moduleId: $moduleId) {
Expand All @@ -176,14 +146,20 @@ private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, st
}
}',
[
'name' => $name,
'value' => $value,
'name' => 'arraySetting',
'value' => '[3, "interesting", "values"]',
'moduleId' => self::TEST_MODULE_ID
]
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
$result = $I->grabJsonResponseAsArray();

$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data']['changeModuleSettingCollection'];
$I->assertSame('arraySetting', $setting['name']);
$I->assertSame('[3, "interesting", "values"]', $setting['value']);
}
}
3 changes: 2 additions & 1 deletion tests/Codeception/Acceptance/NotAuthorizedAccessCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ protected function assertQueryNotFoundErrorInResult(
): void {
$errorMessage = $result['errors'][0]['message'];
$I->assertSame(
'Cannot query field "' . $query . '" on type "' . ucfirst($queryType) . '".', $errorMessage
'Cannot query field "' . $query . '" on type "' . ucfirst($queryType) . '".',
$errorMessage
);
}
}
59 changes: 40 additions & 19 deletions tests/Codeception/Acceptance/ThemeSettingMutationsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ public function testChangeIntegerSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation{
changeThemeSettingInteger(name: "intSettingEditable", value: 124, themeId: "' . $this->getTestThemeName(
) . '") {
'mutation m($name: ID!, $value: Int!, $themeId: String!){
changeThemeSettingInteger(name: $name, value: $value, themeId: $themeId) {
name
value
}
}'
}',
[
'name' => 'intSettingEditable',
'value' => 124,
'themeId' => self::TEST_THEME_ID
]
);

$I->seeResponseIsJson();
Expand All @@ -47,13 +51,17 @@ public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation{
changeThemeSettingFloat(name: "floatSettingEditable", value: 1.24, themeId: "' . $this->getTestThemeName(
) . '") {
'mutation m($name: ID!, $value: Float!, $themeId: String!){
changeThemeSettingFloat(name: $name, value: $value, themeId: $themeId) {
name
value
}
}'
}',
[
'name' => 'floatSettingEditable',
'value' => 1.24,
'themeId' => self::TEST_THEME_ID
]
);

$I->seeResponseIsJson();
Expand All @@ -71,13 +79,17 @@ public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation{
changeThemeSettingBoolean(name: "boolSettingEditable", value: true, themeId: "' . $this->getTestThemeName(
) . '") {
'mutation m($name: ID!, $value: Boolean!, $themeId: String!){
changeThemeSettingBoolean(name: $name, value: $value, themeId: $themeId) {
name
value
}
}'
}',
[
'name' => 'boolSettingEditable',
'value' => true,
'themeId' => self::TEST_THEME_ID
]
);

$I->seeResponseIsJson();
Expand All @@ -95,13 +107,17 @@ public function testChangeStringSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation{
changeThemeSettingString(name: "stringSetting", value: "default", themeId: "' . $this->getTestThemeName(
) . '") {
'mutation m($name: ID!, $value: String!, $themeId: String!){
changeThemeSettingString(name: $name, value: $value, themeId: $themeId) {
name
value
}
}'
}',
[
'name' => 'stringSetting',
'value' => 'default',
'themeId' => self::TEST_THEME_ID
]
);

$I->seeResponseIsJson();
Expand All @@ -119,12 +135,17 @@ public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation{
changeThemeSettingCollection(name: "arraySetting", themeId: "' . $this->getTestThemeName() . '", value: "[3, \"interesting\", \"values\"]") {
'mutation m($name: ID!, $value: String!, $themeId: String!){
changeThemeSettingCollection(name: $name, value: $value, themeId: $themeId) {
name
value
}
}'
}',
[
'name' => 'arraySetting',
'value' => '[3, "interesting", "values"]',
'themeId' => self::TEST_THEME_ID
]
);

$I->seeResponseIsJson();
Expand Down

0 comments on commit 33c67e5

Please sign in to comment.