Skip to content

Commit

Permalink
Merge branch 'pr/664' into release/2.29.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin-Magmodules committed Jul 25, 2023
2 parents ea994dd + 4582e74 commit db6ee3c
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 71 deletions.
4 changes: 1 addition & 3 deletions Service/Order/PartialInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public function createFromShipment(ShipmentInterface $shipment)
/** @var OrderInterface $order */
$order = $shipment->getOrder();

if (!$this->createInvoiceOnShipment->execute($order) ||
$this->mollieHelper->getInvoiceMoment($order->getStoreId()) != InvoiceMoment::ON_SHIPMENT
) {
if (!$this->createInvoiceOnShipment->execute($order)) {
return null;
}

Expand Down
139 changes: 96 additions & 43 deletions Test/End-2-end/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ module.exports = defineConfig({
},
e2e: {
experimentalWebKitSupport: true,
setupNodeEvents(on, config) {
async setupNodeEvents(on, config) {
require('./cypress/plugins/index.js')(on, config);
require('./cypress/plugins/disable-successful-videos.js')(on, config);

return new Promise((resolve, reject) => {
var https = require('follow-redirects').https;
var fs = require('fs');
// Retrieve available method
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 baseUrl = config.baseUrl;
const urlObj = new URL(baseUrl);
const hostname = urlObj.hostname;

const query = `
const query = `
query {
molliePaymentMethods(input:{amount:100, currency:"EUR"}) {
methods {
Expand All @@ -37,52 +37,105 @@ module.exports = defineConfig({
}
`;

var options = {
'method': 'GET',
'hostname': hostname,
'path': '/graphql?query=' + encodeURIComponent(query),
'headers': {
'Content-Type': 'application/json',
// 'Cookie': 'XDEBUG_SESSION=PHPSTORM'
},
'maxRedirects': 20
};
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 + '". One moment please...');
var req = https.request(options, function (res) {
var chunks = [];
console.log('Requesting Mollie payment methods from "' + baseUrl + '". One moment please...');
var req = https.request(options, function (res) {
var chunks = [];

res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("data", function (chunk) {
chunks.push(chunk);
});

res.on("end", function (chunk) {
const body = Buffer.concat(chunks);
res.on("end", function (chunk) {
const body = Buffer.concat(chunks);

const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => {
return data.code
})
const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => {
return data.code
})

config.env.mollie_available_methods = methods;
config.env.mollie_available_methods = methods;

console.log('Available Mollie payment methods: ', methods);
console.log('Available Mollie payment methods: ', methods);

resolve(config);
});
resolve(config);
});

res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});
res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});

var postData = JSON.stringify({
query: '',
variables: {}
});
req.end();
});

req.end();
// retrieve admin token
await new Promise((resolve, reject) => {
const baseUrl = config.baseUrl;
const urlObj = new URL(baseUrl);
const hostname = urlObj.hostname;

const username = 'exampleuser';
const password = 'examplepassword123';

var options = {
'method': 'POST',
'hostname': hostname,
'path': '/rest/all/V1/integration/admin/token',
'headers': {
'accept': 'application/json',
'Content-Type': 'application/json',
// 'Cookie': 'XDEBUG_SESSION=PHPSTORM'
},
'body': JSON.stringify({
'username': username,
'password': password,
}),
};

console.log('Requesting admin token from "' + baseUrl + '". One moment please...');
var https = require('follow-redirects').https;
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);

if (res.statusCode !== 200) {
console.error('Received invalid status code', res.statusCode, body.toString());
reject(body.toString());
}

console.log('Received admin token', body.toString(), res.statusCode);
config.env.admin_token = JSON.parse(body.toString());

resolve(config);
});

res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});

req.write(options.body);
req.end();
});

return config;
},
},
});
12 changes: 9 additions & 3 deletions Test/End-2-end/cypress/e2e/magento/backend/manual-capture.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('Manual capture works as expected', () => {

ordersPage.assertOrderStatusIs('Processing');

ordersPage.assertOrderHasInvoice();
cy.get('@order-id').then((orderId) => {
ordersPage.assertOrderHasInvoice(orderId);
});
});

it('C1064182: Validate that with manual capture enabled the invoice is created when a shipment is created', () => {
Expand Down Expand Up @@ -83,12 +85,16 @@ describe('Manual capture works as expected', () => {

ordersPage.assertOrderStatusIs('Processing');

ordersPage.assertOrderHasNoInvoices();
cy.get('@order-id').then((orderId) => {
ordersPage.assertOrderHasNoInvoices(orderId);
});

ordersPage.ship();

shipmentPage.ship();

ordersPage.assertOrderHasInvoice();
cy.get('@order-id').then((orderId) => {
ordersPage.assertOrderHasInvoice(orderId);
});
});
});
11 changes: 5 additions & 6 deletions Test/End-2-end/cypress/support/actions/backend/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ export default class Configuration {
cy.visit(element.attr('href'));
});

cy.contains('Currency Setup').should('be.visible');
cy.get('.mollie-tab').contains(section).click({force: true});

// When this is not visible, the page is not loaded yet.
cy.get('#system_config_tabs .mollie-tab').click();
cy.url().should('include', 'admin/system_config/edit/section/mollie_');

cy.get('.mollie-tab').contains(section).click();
cy.wait(1000);

// Wait for JS to load
cy.get('.mollie-tab').should('have.class', '_show');
cy.get('.mollie-tab._show', {timeout: 60000}).should('be.visible');

cy.get('.entry-edit').contains(group).then(element => {
if (!element.hasClass('open')) {
cy.get(element).click();
}
});

cy.get('label').contains(field).parents('tr').find(':input').select(value);
cy.get('label').contains(field).parents('tr').find(':input').select(value, {force: true});

cy.get('#save').click();

Expand Down
32 changes: 16 additions & 16 deletions Test/End-2-end/cypress/support/pages/backend/OrdersPage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import MagentoRestApi from "Services/MagentoRestApi";

const magentoRestApi = new MagentoRestApi();

export default class OrdersPage {
openLatestOrder() {
cy.visit('/admin/sales/order/index/');
Expand Down Expand Up @@ -29,27 +33,23 @@ export default class OrdersPage {
cy.get('.mollie-payment-status').contains(status);
}

assertOrderHasInvoice() {
cy.get('#sales_order_view_tabs_order_invoices').click();

// Can be really slow
cy.get('.spinner', {timeout: 30000}).should('not.be.visible');

cy.get('#sales_order_view_tabs_order_invoices_content tbody').should('be.visible');
cy.get('#sales_order_view_tabs_order_invoices_content').should('contain', '1 records found');
assertOrderHasInvoice(orderId, count = 1) {
magentoRestApi.getInvoicesByOrderId(orderId)
.then(response => {
expect(response.total_count).to.equal(count);
});
}

assertOrderHasNoInvoices() {
cy.get('#sales_order_view_tabs_order_invoices').click();

// Can be really slow
cy.get('.spinner', {timeout: 30000}).should('not.be.visible');

cy.get('#sales_order_view_tabs_order_invoices_content tbody').should('be.visible');
cy.get('#sales_order_view_tabs_order_invoices_content').should('contain', '0 records found');
assertOrderHasNoInvoices(orderId) {
magentoRestApi.getInvoicesByOrderId(orderId)
.then(response => {
expect(response.total_count).to.equal(0);
});
}

ship() {
cy.get('#order_ship').should('be.enabled').click();

cy.url().should('include', '/admin/order_shipment/new/order_id/');
}
}
5 changes: 5 additions & 0 deletions Test/End-2-end/cypress/support/pages/backend/ShipmentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export default class ShipmentPage {

ship() {
cy.get('#system_messages').should('have.length.gte', 0);

// Last element on the page so javascript has time to load
cy.get('.magento-version').should('be.visible');
cy.wait(500);

cy.get('[data-ui-id="order-items-submit-button"]').should('be.enabled').click();

cy.get('[data-ui-id="sales-order-tabs-tab-sales-order-view-tabs"] .ui-state-active').should('be.visible');
Expand Down
16 changes: 16 additions & 0 deletions Test/End-2-end/cypress/support/services/MagentoRestApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default class MagentoRestApi {

getInvoicesByOrderId(orderId) {
cy.log('bearer', Cypress.env('admin_token'))

return cy.request({
method: 'GET',
url: '/rest/all/V1/invoices?searchCriteria[filter_groups][0][filters][0][field]=order_id&searchCriteria[filter_groups][0][filters][0][value]=' + orderId,
headers: {
'accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + Cypress.env('admin_token'),
}
}).then(response => response.body);
}
}

0 comments on commit db6ee3c

Please sign in to comment.