|
| 1 | +import supertest from 'supertest'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import app from '..'; |
| 5 | + |
| 6 | +describe('post /api/auth/log', () => { |
| 7 | + //root to login ok |
| 8 | + it('root login', async () => { |
| 9 | + const email = '[email protected]'; |
| 10 | + const password = '123456'; |
| 11 | + |
| 12 | + const res = await supertest(app) |
| 13 | + .post('/api/auth/login') |
| 14 | + .send({ email, password }); |
| 15 | + |
| 16 | + //check if result is ok |
| 17 | + expect(res.status).toBe(200); |
| 18 | + expect(res.body.ok).toEqual(true); |
| 19 | + //check if we not send pass in the result |
| 20 | + expect(res.body.user.password).toBeUndefined(); |
| 21 | + expect(res.body.user.password_hash).toBeUndefined(); |
| 22 | + }); |
| 23 | + |
| 24 | + //root to login KO user is BDD but passwork KO |
| 25 | + it('wrong password should return error', async () => { |
| 26 | + const email = '[email protected]'; |
| 27 | + const password = '1234'; |
| 28 | + |
| 29 | + const res = await supertest(app) |
| 30 | + .post('/api/auth/login') |
| 31 | + .send({ email, password }); |
| 32 | + |
| 33 | + //check if result is ok |
| 34 | + expect(res.body).toEqual({ |
| 35 | + message: 'User or password incorrect', |
| 36 | + ok: false, |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + //root to login KO user is not in BDD |
| 41 | + it('wrong mail should return error', async () => { |
| 42 | + const email = '[email protected]'; |
| 43 | + const password = '123456'; |
| 44 | + |
| 45 | + const res = await supertest(app) |
| 46 | + .post('/api/auth/login') |
| 47 | + .send({ email, password }); |
| 48 | + |
| 49 | + //check if result is ok |
| 50 | + expect(res.body).toEqual({ |
| 51 | + message: 'User or password incorrect', |
| 52 | + ok: false, |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments