From 91e932104974a130605c5fdf7173d21649c8546e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 5 Feb 2021 13:06:47 +0100 Subject: [PATCH] wip --- cypress.json | 2 +- .../authorize.net_credit_card.spec.js | 106 ++++++++++++++++++ .../client_portal/stripe_credit_card.spec.js | 51 ++++----- cypress/support/commands.js | 24 +--- .../livewire/payment-methods-table.blade.php | 2 +- 5 files changed, 137 insertions(+), 48 deletions(-) create mode 100644 cypress/integration/client_portal/authorize.net_credit_card.spec.js diff --git a/cypress.json b/cypress.json index 4e694ea4f01e..9741c8963d7e 100644 --- a/cypress.json +++ b/cypress.json @@ -1,6 +1,6 @@ { "video": false, - "baseUrl": "http://localhost:8080/", + "baseUrl": "https://localhost:8080/", "chromeWebSecurity": false, "env": { "runningEnvironment": "docker" diff --git a/cypress/integration/client_portal/authorize.net_credit_card.spec.js b/cypress/integration/client_portal/authorize.net_credit_card.spec.js new file mode 100644 index 000000000000..4d830920cefb --- /dev/null +++ b/cypress/integration/client_portal/authorize.net_credit_card.spec.js @@ -0,0 +1,106 @@ +/** + * Invoice Ninja (https://invoiceninja.com) + * + * @link https://github.com/invoiceninja/invoiceninja source repository + * + * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) + * + * @license https://opensource.org/licenses/AAL + */ + +describe.skip('Authorize.net: Credit card test', () => { + before(() => { + cy.artisan('migrate:fresh --seed'); + cy.artisan('ninja:create-single-account authorizenet'); + }); + + beforeEach(() => { + cy.viewport('macbook-13'); + cy.wait(5000); + cy.clientLogin(); + }); + + afterEach(() => { + cy.visit('/client/logout').visit('/client/login'); + }); + + it('should pay with new card', function () { + cy.visit('/client/invoices').then((contentWindow) => { + cy.get('[data-cy=pay-now]').first().click() + .get('[data-cy=pay-now-dropdown]').click() + .get('[data-cy=pay-with-0]').click(); + + cy.get('#card_number').type('4007000000027') + .get('#cardholder_name').type('Invoice Ninja Rocks') + .get('[class=expiry]').type('12/28') + .get('[name=cvc]').type('100'); + + cy.get('#pay-now').click(); + }); + + cy.location('pathname', {timeout: 60000}).should('include', '/client/payments/VolejRejNm'); + }); + + it('should pay with new card & save credit card for future use', function () { + cy.visit('/client/invoices').then((contentWindow) => { + cy.get('[data-cy=pay-now]').first().click() + .get('[data-cy=pay-now-dropdown]').click() + .get('[data-cy=pay-with-0]').click(); + + cy.get('#card_number').type('4007000000027') + .get('#cardholder_name').type('Invoice Ninja Rocks') + .get('[class=expiry]').type('12/28') + .get('[name=cvc]').type('100'); + + cy.get('[name=token-billing-checkbox]').first().check(); + + cy.get('#pay-now').click(); + }); + + cy.location('pathname', {timeout: 60000}).should('include', '/client/payments/Wpmbk5ezJn'); + }); + + it('should pay with saved card (token)', function () { + cy.visit('/client/invoices') + .get('[data-cy=pay-now]').first().click() + .get('[data-cy=pay-now-dropdown]').click() + .get('[data-cy=pay-with-0]').click(); + + cy.get('[name=payment-type]').first().check(); + + cy.get('#pay-now').click(); + + cy.wait(2000); + + cy.location('pathname', {timeout: 60000}).should('include', '/client/payments/Opnel5aKBz'); + }); + + + it('should be able to remove payment method', function () { + cy.visit('/client/payment_methods') + .get('[data-cy=view-payment-method]').click(); + + cy.get('#open-delete-popup').click(); + + cy.get('[data-cy=confirm-payment-removal]').click(); + + cy.url().should('contain', '/client/payment_methods'); + + cy.get('body').contains('Payment method has been successfully removed.'); + }); + + it('should be able to add credit card (standalone)', function () { + cy.visit('/client/payment_methods') + .get('[data-cy=add-payment-method]').click() + .get('[data-cy=add-credit-card-link]').click(); + + cy.get('#card_number').type('4007000000027') + .get('#cardholder_name').type('Invoice Ninja Rocks') + .get('[class=expiry]').type('12/28') + .get('[name=cvc]').type('100'); + + cy.get('#card_button').click(); + + cy.location('pathname', {timeout: 60000}.should('include', '/client/payment_methods')); + }); +}); diff --git a/cypress/integration/client_portal/stripe_credit_card.spec.js b/cypress/integration/client_portal/stripe_credit_card.spec.js index ce80b83becff..ff206248fdc0 100644 --- a/cypress/integration/client_portal/stripe_credit_card.spec.js +++ b/cypress/integration/client_portal/stripe_credit_card.spec.js @@ -10,15 +10,14 @@ describe('Stripe: Credit card testing', () => { }); afterEach(() => { - cy.visit('/client/logout'); + cy.visit('/client/logout').visit('/client/login'); }); it('should pay with new card', function () { - cy.visit('/client/invoices'); - - cy.get('[data-cy=pay-now]').first().click(); - cy.get('[data-cy=pay-now-dropdown]').click(); - cy.get('[data-cy=pay-with-0]').click(); + cy.visit('/client/invoices') + .get('[data-cy=pay-now]').first().click() + .get('[data-cy=pay-now-dropdown]').click() + .get('[data-cy=pay-with-0]').click(); cy.get('#cardholder-name').type('Invoice Ninja Rocks'); cy.getWithinIframe('[name=cardnumber]').type('4242424242424242'); @@ -28,15 +27,14 @@ describe('Stripe: Credit card testing', () => { cy.get('#pay-now').click(); - cy.url().should('contain', '/client/payments/VolejRejNm'); + cy.location('pathname', {timeout: 60000}).should('include', '/client/payments/VolejRejNm'); }); it('should pay with new card & save credit card for future use', function () { - cy.visit('/client/invoices'); - - cy.get('[data-cy=pay-now]').first().click(); - cy.get('[data-cy=pay-now-dropdown]').click(); - cy.get('[data-cy=pay-with-0]').click(); + cy.visit('/client/invoices') + .get('[data-cy=pay-now]').first().click() + .get('[data-cy=pay-now-dropdown]').click() + .get('[data-cy=pay-with-0]').click(); cy.get('#cardholder-name').type('Invoice Ninja Rocks'); cy.getWithinIframe('[name=cardnumber]').type('4242424242424242'); @@ -48,27 +46,25 @@ describe('Stripe: Credit card testing', () => { cy.get('#pay-now').click(); - cy.url().should('contain', '/client/payments/Wpmbk5ezJn'); + cy.location('pathname', {timeout: 60000}).should('include', '/client/payments/Wpmbk5ezJn'); }); it('should pay with saved card (token)', function () { - cy.visit('/client/invoices'); - - cy.get('[data-cy=pay-now]').first().click(); - cy.get('[data-cy=pay-now-dropdown]').click(); - cy.get('[data-cy=pay-with-0]').click(); + cy.visit('/client/invoices') + .get('[data-cy=pay-now]').first().click() + .get('[data-cy=pay-now-dropdown]').click() + .get('[data-cy=pay-with-0]').click(); cy.get('[name=payment-type]').first().check(); cy.get('#pay-now').click(); - cy.url().should('contain', '/client/payments/Opnel5aKBz'); + cy.location('pathname', {timeout: 60000}).should('include', '/client/payments/Opnel5aKBz'); }); it('should be able to remove payment method', function () { - cy.visit('/client/payment_methods'); - - cy.get('[data-cy=view-payment-method]').click(); + cy.visit('/client/payment_methods') + .get('[data-cy=view-payment-method]').click(); cy.get('#open-delete-popup').click(); @@ -80,10 +76,9 @@ describe('Stripe: Credit card testing', () => { }); it('should be able to add credit card (standalone)', function () { - cy.visit('/client/payment_methods'); - - cy.get('[data-cy=add-payment-method]').click(); - cy.get('[data-cy=add-credit-card-link]').click(); + cy.visit('/client/payment_methods') + .get('[data-cy=add-payment-method]').click() + .get('[data-cy=add-credit-card-link]').click(); cy.get('#cardholder-name').type('Invoice Ninja Rocks'); cy.getWithinIframe('[name=cardnumber]').type('4242424242424242'); @@ -93,6 +88,8 @@ describe('Stripe: Credit card testing', () => { cy.get('#authorize-card').click(); - cy.url().should('contain', '/client/payment_methods'); + cy.location('pathname', {timeout: 60000}) + .should('include', '/client/payment_methods') + .get('[data-cy=pm-last4]').contains('**** 4242'); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 93673ec6ca38..ac6688e842cc 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -27,27 +27,13 @@ const axios = require('axios'); const fixture = require('../fixtures/example.json'); Cypress.Commands.add('clientLogin', () => { - cy.visit('/client/login'); - cy.get('#test_email') - .invoke('val') - .then((emailValue) => { - cy.get('#test_password') - .invoke('val') - .then((passwordValue) => { - cy.get('#email') - .type(emailValue) - .should('have.value', emailValue); - cy.get('#password') - .type(passwordValue) - .should('have.value', passwordValue); - cy.get('#loginBtn') - .contains('Login') - .click(); - }); - }); + cy.visit('/client/login') + .get('#email').type('user@example.com') + .get('#password').type('password') + .get('#loginBtn').click(); }); -Cypress.Commands.add('iframeLoaded', { prevSubject: 'element' }, ($iframe) => { +Cypress.Commands.add('iframeLoaded', {prevSubject: 'element'}, ($iframe) => { const contentWindow = $iframe.prop('contentWindow'); return new Promise((resolve) => { if (contentWindow) { diff --git a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php index f132f9f3dd46..c6216e448402 100644 --- a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php @@ -77,7 +77,7 @@ {{ $payment_method->meta->exp_month}} / {{ $payment_method->meta->exp_year }} @endif - + @isset($payment_method->meta->last4) **** {{ $payment_method->meta->last4 }} @endisset