Skip to content

Commit

Permalink
Merge pull request #278 from ola-9/login
Browse files Browse the repository at this point in the history
Login bug
  • Loading branch information
fey authored Jun 6, 2023
2 parents 73ffe02 + 4f0b335 commit 83a88db
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions backend/__fixtures__/testData.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
"email": "[email protected]",
"password": "NotFound404"
},
"loginUpperCase" : {
"email": "[email protected]",
"password": "Deleted410"
},
"profile": {
"currentUser": {
"id": 1,
Expand Down
11 changes: 11 additions & 0 deletions backend/__tests__/auth.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/local.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) {
}

async validate(email: string, password: string): Promise<any> {
const user = await this.authService.validateUser(email, password);
const user = await this.authService.validateUser(email.toLowerCase(), password);
if (!user) {
throw new UnauthorizedException();
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function Navbar() {
className="d-flex align-items-baseline"
to={
auth.isLoggedIn
? routes.profilePagePath() // Затем вставим редирект на страницу со снипетами
? routes.defaultProfilePagePath() // Затем вставим редирект на страницу со снипетами
: routes.lendingPath()
}
>
Expand Down
5 changes: 3 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
4 changes: 2 additions & 2 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
15 changes: 9 additions & 6 deletions tests/workflow.spec.ts
Original file line number Diff line number Diff line change
@@ -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('[email protected]');
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();
Expand Down

0 comments on commit 83a88db

Please sign in to comment.