Skip to content

Commit

Permalink
Fixing e2e tests for good (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Feb 26, 2023
1 parent 59977df commit af0d8a6
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Alpha Build'

on:
push:
branches: [v5000/last-updates]
branches: [v5000/backend-fix]

jobs:
frontend:
Expand Down
34 changes: 22 additions & 12 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ app.get('/healthz', async (_, res) => {
res.status(200).send();
});

app.use('/api/auth', heavyLoadLimiter, authRouter);

io.use(function (socket, next) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sessionMiddleware(socket.request as any, {} as any, next as any);
Expand All @@ -244,6 +242,9 @@ db().then(() => {
passportInit();
game(io);

// Auth
app.use('/api/auth', heavyLoadLimiter, authRouter);

// Stripe
app.use('/api/stripe', stripeRouter());

Expand Down Expand Up @@ -423,24 +424,33 @@ db().then(() => {
registerPayload.name,
identity.emailVerification!
);
const userView = await getUserView(identity.id);
if (userView) {
res.status(200).send({
loggedIn: false,
user: userView.toJson(),
});
} else {
res.status(500).send();
}
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
req.logIn(identity.toIds(), (err: any) => {
req.logIn(identity.toIds(), async (err: any) => {
if (err) {
console.log('Cannot login Error: ', err);
res.status(500).send('Cannot login');
}
const userView = await getUserView(identity.id);
if (userView) {
res.status(200).send({
loggedIn: true,
user: userView.toJson(),
});
} else {
res.status(500).send();
}
});
}
const userView = await getUserView(identity.id);
if (userView) {
res.status(200).send({
loggedIn: !identity.emailVerification,
user: userView.toJson(),
});
} else {
res.status(500).send();
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion integration/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { defineConfig } = require('cypress')

module.exports = defineConfig({
env: {
backend_delay: 2000,
backend_delay: 10000,
},
e2e: {
// We've imported your old cypress plugins here.
Expand Down
165 changes: 0 additions & 165 deletions integration/cypress/e2e/test.cy.js

This file was deleted.

116 changes: 116 additions & 0 deletions integration/cypress/e2e/test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const timeout = +Cypress.env('backend_delay');

describe('Home Page', () => {
it('Should load correctly', () => {
cy.visit('/');

cy.get('#content').get('h1', { timeout }).should('contain', 'Welcome!');
});
});

function get(name: string, rest?: string) {
return cy.get(`[data-cy=${name}]${rest ?? ''}`, { timeout });
}

describe('Post workflow', () => {
beforeEach(() => {
cy.setCookie('wpcc', 'dismiss');
});

it('Should login and write a post', () => {
cy.visit('/');

get('anon-tab').click();
get('anon-input').focus().type('Zelensky');
get('anon-login-button').click();

// Home page should display the user name
cy.get('#content', { timeout }).should('contain', 'Welcome, Zelensky');

// And then allow creating a new session
get('new-session-button').click();

// And write a post
get('column-input').first().focus().type('Slava Ukraini!{enter}');

// Reload the page
cy.reload();

// The post should still be there
cy.get('#content', { timeout }).should('contain', 'Slava Ukraini!');
});

it('Should change language and translate the app', () => {
cy.visit('/');

get('anon-tab').click();
get('anon-input').focus().type('Zelensky');
get('anon-login-button').click();

// Home page should display the user name
cy.get('#content', { timeout }).should('contain', 'Welcome, Zelensky');

// Change language
get('side-panel-toggle').click();
get('language-picker').click();
get('language-picker-item-fr-FR').click();

// Exit panel
cy.get('body', { timeout }).type('{esc}');

// Home page should now be in French
cy.get('#content', { timeout }).should('contain', 'Bienvenue, Zelensky');

// Logout
get('account-menu').click();
get('account-menu-logout').click();
});

it('Should be able to create and delete a new account', () => {
const id = Date.now();

cy.visit('/');

// Select the account tab
get('account-tab').click();

// Select register
get('register').click();

// Add some data
get('register-name').type('V Zelensky');
get('register-email').type(`vlad.zelensky.${id}@ukraine.ua`);
get('register-password').type('A-str0ng-Pa33!çà');

// Register
get('register-button').click();

// Create a new session, and add some messages
get('new-session-button').click();

// And write a post
get('column-input').first().focus().type('Slava Ukraini!{enter}');
cy.get('#content', { timeout }).should('contain', 'Slava Ukraini!');

// And some chat
get('open-chat-button').click({ force: true });
get('chat-input').focus().type('This is a message{enter}');
cy.get('#content', { timeout }).should('contain', 'This is a message');

// Close
get('open-chat-button').click({ force: true });

// Go to the user admin and delete the account
get('account-menu').click();
get('account-menu-account').click();
get('delete-account-button').click();
get('delete-modal-sessions').click();
get('delete-modal-posts').click();
get('delete-modal-votes').click();
get('delete-modal-delete-button').click();
get('delete-modal-confirm').click();

// We should be back to the home page
cy.get('body', { timeout }).get('h1').should('contain', 'Welcome!');
});
});
8 changes: 8 additions & 0 deletions integration/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion integration/docker-compose.ci.alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- frontend
environment:
- CYPRESS_baseUrl=http://frontend
- CYPRESS_backend_delay=10000
- CYPRESS_backend_delay=30000
working_dir: /e2e
volumes:
- ./:/e2e
Expand Down
2 changes: 1 addition & 1 deletion integration/docker-compose.ci.canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- frontend
environment:
- CYPRESS_baseUrl=http://frontend
- CYPRESS_backend_delay=10000
- CYPRESS_backend_delay=30000
working_dir: /e2e
volumes:
- ./:/e2e
Expand Down
Loading

0 comments on commit af0d8a6

Please sign in to comment.