From 2bbbe6ee6c5605c586027891653bd4917bbf9afd Mon Sep 17 00:00:00 2001 From: ola-9 Date: Fri, 2 Jun 2023 17:09:09 +0300 Subject: [PATCH 1/4] Login bug https://github.com/hexlet-rus/runit/issues/277 --- backend/__fixtures__/testData.json | 4 ++++ backend/__tests__/auth.e2e-spec.ts | 11 +++++++++++ backend/src/auth/local.strategy.ts | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/__fixtures__/testData.json b/backend/__fixtures__/testData.json index 86972739..57fca4ad 100644 --- a/backend/__fixtures__/testData.json +++ b/backend/__fixtures__/testData.json @@ -57,6 +57,10 @@ "email": "undefined@mail.ru", "password": "NotFound404" }, + "loginUpperCase" : { + "email": "NULL@YANDEX.RU", + "password": "Deleted410" + }, "profile": { "currentUser": { "id": 1, diff --git a/backend/__tests__/auth.e2e-spec.ts b/backend/__tests__/auth.e2e-spec.ts index 9f3e19d8..1d925ead 100644 --- a/backend/__tests__/auth.e2e-spec.ts +++ b/backend/__tests__/auth.e2e-spec.ts @@ -22,6 +22,8 @@ describe('AuthController (e2e)', () => { let usersData: Users[]; let jwtService: JwtService; + // все тесты проходят если beforeEach + // beforeEach(async () => { beforeAll(async () => { moduleFixture = await Test.createTestingModule({ imports: [ @@ -62,6 +64,15 @@ describe('AuthController (e2e)', () => { expect(body.token).toBeDefined(); }); + it('/login upperCase', async () => { + const { body } = await request(app.getHttpServer()) + .post(`/login`) + .send(testData.loginUpperCase) + // .send({ email: 'UNDEFINED@MAIL.RU', password: 'NotFound404' }) + .expect(201); + expect(body.token).toBeDefined(); + }); + it('/logout', async () => { const token = jwtService.sign(testData.sign); return request(app.getHttpServer()) diff --git a/backend/src/auth/local.strategy.ts b/backend/src/auth/local.strategy.ts index a66c217f..18d00daf 100644 --- a/backend/src/auth/local.strategy.ts +++ b/backend/src/auth/local.strategy.ts @@ -12,7 +12,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) { } async validate(email: string, password: string): Promise { - const user = await this.authService.validateUser(email, password); + const user = await this.authService.validateUser(email.toLowerCase(), password); if (!user) { throw new UnauthorizedException(); } From 46af242d082686be43b0ac8f3686bfe96fbb04c5 Mon Sep 17 00:00:00 2001 From: ola-9 Date: Sat, 3 Jun 2023 16:54:29 +0300 Subject: [PATCH 2/4] fix routes and frontend tests fix routes; complete frontend tests --- frontend/src/components/Navbar.jsx | 2 +- playwright.config.ts | 5 +++-- tests/example.spec.ts | 4 ++-- tests/workflow.spec.ts | 14 ++++++++------ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index 15a4f56e..518ca40d 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -29,7 +29,7 @@ export function Navbar() { className="d-flex align-items-baseline" to={ auth.isLoggedIn - ? routes.profilePagePath() // Затем вставим редирект на страницу со снипетами + ? routes.defaultProfilePagePath() // Затем вставим редирект на страницу со снипетами : routes.lendingPath() } > diff --git a/playwright.config.ts b/playwright.config.ts index a7167a34..2abdf95d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -88,7 +88,8 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'make start-backend', - port: 5001, + command: 'npm run start:frontend', + port: 3000, + reuseExistingServer: !process.env.CI, }, }); diff --git a/tests/example.spec.ts b/tests/example.spec.ts index 8c7d6272..79ed4471 100644 --- a/tests/example.spec.ts +++ b/tests/example.spec.ts @@ -1,14 +1,14 @@ import { test, expect } from '@playwright/test'; test('has title', async ({ page }) => { - await page.goto('http://localhost:5001'); + await page.goto('http://localhost:3000'); // Expect a title "to contain" a substring. await expect(page).toHaveTitle(/Run IT/); }); test('get started link', async ({ page }) => { - await page.goto('http://localhost:5001'); + await page.goto('http://localhost:3000'); // Click the get started link. await page.getByRole('button', { name: 'Начать кодить' }).first().click(); diff --git a/tests/workflow.spec.ts b/tests/workflow.spec.ts index 21f4643e..4203e2c1 100644 --- a/tests/workflow.spec.ts +++ b/tests/workflow.spec.ts @@ -1,18 +1,20 @@ import { test, expect } from '@playwright/test'; +/* TODO: Тесты каждый раз создают пользователя...? */ test('work', async ({ page }) => { - await page.goto('http://localhost:5001'); + const randomNum = Math.round(Math.random() * 1000 + Math.random() * 100); + await page.goto('http://localhost:3000'); await page.getByRole('button', { name: 'Регистрация' }).click(); - await page.getByLabel('Электронная почта').fill('test@test.test'); - await page.getByLabel('Логин').fill('test'); - await page.getByLabel('Пароль', { exact: true }).fill('password'); - await page.getByLabel('Подтвердить пароль').fill('password'); + await page.getByLabel('Электронная почта').fill(`test${randomNum}@test.test`); + await page.getByLabel('Логин').fill(`test${randomNum}`); + await page.getByLabel('Пароль', { exact: true }).fill('12345678'); + await page.getByLabel('Подтвердить пароль').fill('12345678'); await page.getByRole('button', { name: 'Зарегистрироваться' }).click(); await page.getByRole('button', { name: 'Новый сниппет' }).click(); await page.getByRole('button', { name: 'Сохранить' }).click(); - await page.getByRole('textbox', { name: 'Editor content;Press Alt+F1 for Accessibility Options.' }).fill('console.log(\'hello\');'); + await page.getByRole('textbox', { name: 'Editor content;Press Alt+F1 for Accessibility Options.' }).fill('// Write your code in JS\nconsole.log(\'Hello\');'); await page.getByRole('button', { name: 'Запустить' }).click(); await expect(page.locator(':text("hello")')).toBeVisible(); From 52299f0d5c9f353fbe781ffcf441064780922be8 Mon Sep 17 00:00:00 2001 From: ola-9 Date: Sat, 3 Jun 2023 20:09:04 +0300 Subject: [PATCH 3/4] fix playwright config --- playwright.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright.config.ts b/playwright.config.ts index 2abdf95d..d6825003 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -88,7 +88,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'npm run start:frontend', + command: 'npm run start', port: 3000, reuseExistingServer: !process.env.CI, }, From 4f0b335d0ec6621de2fe6651fe706cec03f1f535 Mon Sep 17 00:00:00 2001 From: ola-9 Date: Mon, 5 Jun 2023 22:39:21 +0300 Subject: [PATCH 4/4] cleanup comments, add details --- backend/__tests__/auth.e2e-spec.ts | 4 ++-- tests/workflow.spec.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/__tests__/auth.e2e-spec.ts b/backend/__tests__/auth.e2e-spec.ts index 1d925ead..8d8a3e08 100644 --- a/backend/__tests__/auth.e2e-spec.ts +++ b/backend/__tests__/auth.e2e-spec.ts @@ -22,7 +22,8 @@ describe('AuthController (e2e)', () => { let usersData: Users[]; let jwtService: JwtService; - // все тесты проходят если beforeEach + // FIXME: все тесты проходят если beforeEach + // заново полный setup -> надо перенести в хуки сброс аппа между тестами // beforeEach(async () => { beforeAll(async () => { moduleFixture = await Test.createTestingModule({ @@ -68,7 +69,6 @@ describe('AuthController (e2e)', () => { const { body } = await request(app.getHttpServer()) .post(`/login`) .send(testData.loginUpperCase) - // .send({ email: 'UNDEFINED@MAIL.RU', password: 'NotFound404' }) .expect(201); expect(body.token).toBeDefined(); }); diff --git a/tests/workflow.spec.ts b/tests/workflow.spec.ts index 4203e2c1..94bd84f7 100644 --- a/tests/workflow.spec.ts +++ b/tests/workflow.spec.ts @@ -1,6 +1,7 @@ import { test, expect } from '@playwright/test'; -/* TODO: Тесты каждый раз создают пользователя...? */ +/* TODO: Тесты каждый раз создают пользователя в приложении, +все должно происходит в тестовом окружении */ test('work', async ({ page }) => { const randomNum = Math.round(Math.random() * 1000 + Math.random() * 100); await page.goto('http://localhost:3000');