From 1e480c5c640dc00b2d842e7dcbc94174bd50f50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 13 Oct 2020 15:46:11 +0200 Subject: [PATCH] wip dynamically switching gateways --- cypress/fixtures/example.json | 13 +++++--- .../checkout_credit_card.spec.js | 7 +++- .../client_portal/stripe_credit_card.spec.js | 7 +++- cypress/support/commands.js | 32 +++++++++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json index da18d9352a17..f0300d2d471c 100644 --- a/cypress/fixtures/example.json +++ b/cypress/fixtures/example.json @@ -1,5 +1,10 @@ { - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} \ No newline at end of file + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes", + + "first": "VolejRejNm", + "second": "Wpmbk5ezJn", + + "url": "http://localhost:8000" +} diff --git a/cypress/integration/client_portal/checkout_credit_card.spec.js b/cypress/integration/client_portal/checkout_credit_card.spec.js index 32cb01d6ce09..d7e9930ab36d 100644 --- a/cypress/integration/client_portal/checkout_credit_card.spec.js +++ b/cypress/integration/client_portal/checkout_credit_card.spec.js @@ -1,5 +1,10 @@ +import { second } from '../../fixtures/example.json'; + describe('Checkout Credit Card Payments', () => { - beforeEach(() => cy.clientLogin()); + beforeEach(() => { + // cy.useGateway(second); + cy.clientLogin(); + }); it('should be able to complete payment using checkout credit card', () => { cy.visit('/client/invoices'); diff --git a/cypress/integration/client_portal/stripe_credit_card.spec.js b/cypress/integration/client_portal/stripe_credit_card.spec.js index 0cacbb1bfad4..08edafcfd2f5 100644 --- a/cypress/integration/client_portal/stripe_credit_card.spec.js +++ b/cypress/integration/client_portal/stripe_credit_card.spec.js @@ -1,5 +1,10 @@ +import { first } from '../../fixtures/example.json' + describe('Stripe Credit Card Payments', () => { - beforeEach(() => cy.clientLogin()); + beforeEach(() => { + // cy.useGateway(first); + cy.clientLogin(); + }); it('should be able to add credit card using Stripe', () => { cy.visit('/client/payment_methods'); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 6c784fa9d14c..93673ec6ca38 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,6 +23,8 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) +const axios = require('axios'); +const fixture = require('../fixtures/example.json'); Cypress.Commands.add('clientLogin', () => { cy.visit('/client/login'); @@ -74,3 +76,33 @@ Cypress.Commands.add('getWithinIframe', (targetElement) => .its('document') .getInDocument(targetElement) ); + +Cypress.Commands.add('useGateway', (gateway) => { + let body = { + settings: { + entity: 'App\\Models\\Client', + industry_id: '', + size_id: '', + currency_id: '1', + company_gateway_ids: gateway, + }, + }; + + let options = { + headers: { + 'X-Api-Secret': 'superdoopersecrethere', + 'X-Api-Token': + 'S0x8behDk8HG8PI0i8RXdpf2AVud5b993pE8vata7xmm4RgW6u3NeGC8ibWIUjZv', + 'X-Requested-With': 'XMLHttpRequest', + }, + }; + + axios + .put( + `http://localhost:8000/api/v1/clients/${fixture.first}`, + body, + options + ) + .then((response) => console.log(response)) + .catch((error) => console.log(error.message)); +});