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..8d8a3e08 100644 --- a/backend/__tests__/auth.e2e-spec.ts +++ b/backend/__tests__/auth.e2e-spec.ts @@ -22,6 +22,9 @@ describe('AuthController (e2e)', () => { let usersData: Users[]; let jwtService: JwtService; + // FIXME: все тесты проходят если beforeEach + // заново полный setup -> надо перенести в хуки сброс аппа между тестами + // beforeEach(async () => { beforeAll(async () => { moduleFixture = await Test.createTestingModule({ imports: [ @@ -62,6 +65,14 @@ describe('AuthController (e2e)', () => { expect(body.token).toBeDefined(); }); + it('/login upperCase', async () => { + const { body } = await request(app.getHttpServer()) + .post(`/login`) + .send(testData.loginUpperCase) + .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(); } 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..d6825003 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', + 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..94bd84f7 100644 --- a/tests/workflow.spec.ts +++ b/tests/workflow.spec.ts @@ -1,18 +1,21 @@ 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();