From 18d114080c2b9b9f97c657c20ea601ca28d3237b Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 10 Jan 2024 12:03:39 +0100 Subject: [PATCH 1/2] Fix tests --- Helper/Tests.php | 4 +- Test/End-2-end/cypress.config.js | 109 +++++++++++++------------------ 2 files changed, 48 insertions(+), 65 deletions(-) diff --git a/Helper/Tests.php b/Helper/Tests.php index f502f68cac7..d4ec1570364 100644 --- a/Helper/Tests.php +++ b/Helper/Tests.php @@ -49,7 +49,7 @@ public function getMethods($testKey = null, $liveKey = null) try { $availableMethods = []; $mollieApi = $this->mollieModel->loadMollieApi($testKey); - $methods = $mollieApi->methods->allAvailable(); + $methods = $mollieApi->methods->allAvailable() ?? []; foreach ($methods as $apiMethod) { $availableMethods[] = ucfirst($apiMethod->id); @@ -79,7 +79,7 @@ public function getMethods($testKey = null, $liveKey = null) try { $availableMethods = []; $mollieApi = $this->mollieModel->loadMollieApi($liveKey); - $methods = $mollieApi->methods->allAvailable(); + $methods = $mollieApi->methods->allAvailable() ?? []; foreach ($methods as $apiMethod) { $availableMethods[] = ucfirst($apiMethod->id); diff --git a/Test/End-2-end/cypress.config.js b/Test/End-2-end/cypress.config.js index b17b6b0b823..28aa5cb145c 100644 --- a/Test/End-2-end/cypress.config.js +++ b/Test/End-2-end/cypress.config.js @@ -18,82 +18,65 @@ module.exports = defineConfig({ require('./cypress/plugins/disable-successful-videos.js')(on, config); // Retrieve available method - await new Promise((methodsPromiseResolve, reject) => { + await new Promise((resolve, reject) => { var https = require('follow-redirects').https; const baseUrl = config.baseUrl; const urlObj = new URL(baseUrl); const hostname = urlObj.hostname; - const currencies = ['EUR', 'CHF']; + const query = ` + query { + molliePaymentMethods(input:{amount:100, currency:null}) { + methods { + code + image + name + } + } + } + `; - let promises = []; + var options = { + 'method': 'GET', + 'hostname': hostname, + 'path': '/graphql?query=' + encodeURIComponent(query), + 'headers': { + 'Content-Type': 'application/json', + // 'Cookie': 'XDEBUG_SESSION=PHPSTORM' + }, + 'maxRedirects': 20 + }; - currencies.forEach(currency => { - const query = ` - query { - molliePaymentMethods(input:{amount:100, currency:"${currency}"}) { - methods { - code - image - name - } - } - } - `; - - var options = { - 'method': 'GET', - 'hostname': hostname, - 'path': '/graphql?query=' + encodeURIComponent(query), - 'headers': { - 'Content-Type': 'application/json', - // 'Cookie': 'XDEBUG_SESSION=PHPSTORM' - }, - 'maxRedirects': 20 - }; - - console.log(`Requesting Mollie payment methods from "${baseUrl}" for ${currency}. One moment please...`); - const promise = new Promise((resolve, reject) => { - var req = https.request(options, function (res) { - var chunks = []; - - res.on("data", function (chunk) { - chunks.push(chunk); - }); - - res.on("end", function (chunk) { - const body = Buffer.concat(chunks); - - const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => { - return data.code - }) - - console.log(`Available Mollie payment methods for ${currency}: `, methods); - - resolve(methods); - }); - - res.on("error", function (error) { - console.error('Error while fetching Mollie Payment methods', error); - reject(error); - }); - }); - - req.end(); - }); + console.log('Requesting Mollie payment methods from "' + baseUrl + '". One moment please...'); + var req = https.request(options, function (res) { + var chunks = []; - promises.push(promise); - }); + res.on("data", function (chunk) { + chunks.push(chunk); + }); + + res.on("end", function (chunk) { + const body = Buffer.concat(chunks); + + const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => { + return data.code + }) - Promise.all(promises).then((values) => { - const methods = [].concat(...values); - config.env.mollie_available_methods = [...new Set(methods)]; + config.env.mollie_available_methods = methods; - console.log('Available Mollie payment methods: ', config.env.mollie_available_methods); + console.log('Available Mollie payment methods: ', methods); - methodsPromiseResolve(); + resolve(config); + }); + + res.on("error", function (error) { + console.error('Error while fetching Mollie Payment methods', error); + reject(error); + }); }); + + req.end(); }); // retrieve admin token From c5f09b39da417214d42cb6dec9be2bd0322617f1 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 10 Jan 2024 13:16:06 +0100 Subject: [PATCH 2/2] Fix tests --- GraphQL/Resolver/General/MolliePaymentMethods.php | 4 ++-- .../GraphQL/Resolver/General/MolliePaymentMethodsTest.php | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/GraphQL/Resolver/General/MolliePaymentMethods.php b/GraphQL/Resolver/General/MolliePaymentMethods.php index 31d435fd241..a254eb68f80 100644 --- a/GraphQL/Resolver/General/MolliePaymentMethods.php +++ b/GraphQL/Resolver/General/MolliePaymentMethods.php @@ -64,7 +64,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $storeId = $context->getExtensionAttributes()->getStore()->getId(); - $apiMethods = $this->getMethods($amount, $currency, $storeId); + $apiMethods = $this->getMethods($amount, $currency, $storeId) ?? []; $methods = []; /** @var Method $method */ @@ -90,7 +90,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value ]; } - public function getMethods(float $amount, ?string $currency, int $storeId): MethodCollection + public function getMethods(float $amount, ?string $currency, int $storeId): ?MethodCollection { $mollieApiClient = $this->mollieApiClient->loadByStore($storeId); diff --git a/Test/Integration/GraphQL/Resolver/General/MolliePaymentMethodsTest.php b/Test/Integration/GraphQL/Resolver/General/MolliePaymentMethodsTest.php index a3f6cdafcc7..44d1109f60e 100644 --- a/Test/Integration/GraphQL/Resolver/General/MolliePaymentMethodsTest.php +++ b/Test/Integration/GraphQL/Resolver/General/MolliePaymentMethodsTest.php @@ -150,8 +150,14 @@ private function callEndpoint($methods): array { $this->loadFakeEncryptor()->addReturnValue('', 'test_dummyapikeythatisvalidandislongenough'); + $methodCollection = new \Mollie\Api\Resources\MethodCollection(count($methods), null); + foreach ($methods as $method) { + $methodCollection[] = $method; + } + $methodsEndpointMock = $this->createMock(MethodEndpoint::class); - $methodsEndpointMock->method('allActive')->willReturn($methods); + $methodsEndpointMock->method('allActive')->willReturn($methodCollection); + $methodsEndpointMock->method('allAvailable')->willReturn($methodCollection); $mollieApiMock = $this->createMock(MollieApiClient::class); $mollieApiMock->methods = $methodsEndpointMock;