const schema = require('../fixtures/schema_public.json'); describe('Email Verifcation', () => { beforeEach(() => { cy.server(); }); it('forwards to homepage if confirmation key is correct', () => { cy.viewport('macbook-15'); cy.mockGraphql({ schema: schema, // endpoint: '/api/graphql' operations: { Registration: variables => { return { registration: { errors: [], message: "success", success: true } } }, } }); cy.visit('/verify-email?confirmation=abcd1234&id=12'); // user should be logged in at that stage. As the cookie cannot be set at the right time // we just check if the user gets redirected to the login page as we can't log her in cy.url().should('include', 'login?redirect=%2F'); }); it('displays error if key is incorrect', () => { cy.viewport('macbook-15'); cy.mockGraphql({ schema: schema, // endpoint: '/api/graphql' operations: { Registration: variables => { return { registration: { errors: [ { field: "invalid_key" } ], message: "", success: false } } }, } }); cy.visit('/verify-email?confirmation=abcd1234&id=12'); cy.get('[data-cy="code-nok-msg"]').contains('Der angegebene Verifizierungscode ist falsch oder abgelaufen.'); cy.get('[data-cy="code-ok-msg"]').should('not.exist'); }); it('displays error if an error occured', () => { cy.viewport('macbook-15'); cy.mockGraphql({ schema: schema, // endpoint: '/api/graphql' operations: { Registration: variables => { return { registration: { errors: [ { field: "unkown_error" } ], message: "", success: false } } }, } }); cy.visit('/verify-email?confirmation=abcd1234&id=12'); cy.get('[data-cy="code-nok-msg"]').contains('Ein Fehler ist aufgetreten. Bitte kontaktieren Sie den Administrator.'); }); it('forwards to coupon page if user has no valid license', () => { cy.viewport('macbook-15'); cy.mockGraphql({ schema: schema, // endpoint: '/api/graphql' operations: { Registration: variables => { return { registration: { errors: [ { field: "no_valid_license" } ], message: "", success: false } } }, } }); cy.visit('/verify-email?confirmation=abcd1234&id=12'); // user should be logged in at that stage. As the cookie cannot be set at the right time // we just check if the user gets redirected to the coupon page as we can't log her in cy.url().should('include', 'login?redirect=%2Flicense-activation'); }); });