diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 6d2ed56f5..81fd2c55e 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -2,7 +2,7 @@ name: 'Alpha Build' on: push: - branches: [v5000/last-updates] + branches: [v5000/backend-fix] jobs: frontend: diff --git a/backend/src/index.ts b/backend/src/index.ts index d76bb0948..69775771b 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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); @@ -244,6 +242,9 @@ db().then(() => { passportInit(); game(io); + // Auth + app.use('/api/auth', heavyLoadLimiter, authRouter); + // Stripe app.use('/api/stripe', stripeRouter()); @@ -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(); - } } }); diff --git a/integration/cypress.config.js b/integration/cypress.config.js index 916e52efc..26b766e89 100644 --- a/integration/cypress.config.js +++ b/integration/cypress.config.js @@ -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. diff --git a/integration/cypress/e2e/test.cy.js b/integration/cypress/e2e/test.cy.js deleted file mode 100644 index 908be29db..000000000 --- a/integration/cypress/e2e/test.cy.js +++ /dev/null @@ -1,165 +0,0 @@ -describe('Home Page', () => { - it('Should load correctly', () => { - cy.visit('/'); - - cy.wait(+Cypress.env('backend_delay')); - - cy.get('#content').get('h1').should('contain', 'Welcome!'); - }); -}); - - -function get(name, rest) { - return cy.get(`[data-cy=${name}]${rest ?? ''}`); -} - - - -describe('Post workflow', () => { - it('Should login and write a post', () => { - cy.visit('/'); - - // We need to wait until the backend is ready - cy.wait(+Cypress.env('backend_delay')); - - // Close cookie banner - cy.get('.wpcc-btn').click(); - - 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').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(); - - cy.wait(+Cypress.env('backend_delay')); - - // The post should still be there - cy.get('#content').should('contain', 'Slava Ukraini!'); - }); - - it('Should change language and translate the app', () => { - cy.visit('/'); - - cy.wait(+Cypress.env('backend_delay')); - - // Close cookie banner - cy.get('.wpcc-btn').click(); - - 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').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').type('{esc}'); - - // Home page should now be in French - cy.get('#content').should('contain', 'Bienvenue, Zelensky'); - - // Logout - get('account-menu').click(); - get('account-menu-logout').click(); - - }); - - it('Should be able to create a new account', () => { - cy.session('create-account', () => { - const id = Date.now(); - - cy.visit('/'); - - cy.wait(+Cypress.env('backend_delay')); - - // Close cookie banner - cy.get('.wpcc-btn').click(); - - // 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').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').should('contain', 'This is a message'); - - // Close - get('open-chat-button').click({force: true}); - }); - }); - - it('Should be able to delete an account', () => { - cy.session('delete-account', () => { - const id = Date.now(); - - cy.visit('/'); - - cy.wait(+Cypress.env('backend_delay')); - - // Close cookie banner - cy.get('.wpcc-btn').click(); - - // 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(); - - cy.wait(+Cypress.env('backend_delay')); - - // 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').get('h1').should('contain', 'Welcome!'); - }); - }); -}); diff --git a/integration/cypress/e2e/test.cy.ts b/integration/cypress/e2e/test.cy.ts new file mode 100644 index 000000000..df623eede --- /dev/null +++ b/integration/cypress/e2e/test.cy.ts @@ -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!'); + }); +}); diff --git a/integration/cypress/tsconfig.json b/integration/cypress/tsconfig.json new file mode 100644 index 000000000..83fb87e55 --- /dev/null +++ b/integration/cypress/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress", "node"] + }, + "include": ["**/*.ts"] +} \ No newline at end of file diff --git a/integration/docker-compose.ci.alpha.yml b/integration/docker-compose.ci.alpha.yml index 505aea970..95c16e1ea 100644 --- a/integration/docker-compose.ci.alpha.yml +++ b/integration/docker-compose.ci.alpha.yml @@ -7,7 +7,7 @@ services: - frontend environment: - CYPRESS_baseUrl=http://frontend - - CYPRESS_backend_delay=10000 + - CYPRESS_backend_delay=30000 working_dir: /e2e volumes: - ./:/e2e diff --git a/integration/docker-compose.ci.canary.yml b/integration/docker-compose.ci.canary.yml index 9779a08a2..7761dffaa 100644 --- a/integration/docker-compose.ci.canary.yml +++ b/integration/docker-compose.ci.canary.yml @@ -7,7 +7,7 @@ services: - frontend environment: - CYPRESS_baseUrl=http://frontend - - CYPRESS_backend_delay=10000 + - CYPRESS_backend_delay=30000 working_dir: /e2e volumes: - ./:/e2e diff --git a/integration/docker-compose.ci.master.yml b/integration/docker-compose.ci.master.yml index 893e8b8fb..702672923 100644 --- a/integration/docker-compose.ci.master.yml +++ b/integration/docker-compose.ci.master.yml @@ -7,7 +7,7 @@ services: - frontend environment: - CYPRESS_baseUrl=http://frontend - - CYPRESS_backend_delay=10000 + - CYPRESS_backend_delay=30000 working_dir: /e2e volumes: - ./:/e2e diff --git a/integration/package.json b/integration/package.json index a05ecdb2f..d894f741c 100644 --- a/integration/package.json +++ b/integration/package.json @@ -14,5 +14,8 @@ "license": "ISC", "devDependencies": { "cypress": "^12.6.0" + }, + "dependencies": { + "typescript": "^4.9.5" } } diff --git a/integration/yarn.lock b/integration/yarn.lock index cfa85724b..2d9237296 100644 --- a/integration/yarn.lock +++ b/integration/yarn.lock @@ -1065,6 +1065,11 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== +typescript@^4.9.5: + version "4.9.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" + integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== + universalify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"