|
| 1 | +import * as request from 'supertest'; |
| 2 | +import { app, createMember, memberFixture } from 'test/setup'; |
| 3 | + |
| 4 | +describe('POST /api/project', () => { |
| 5 | + const createProjectPayload = { |
| 6 | + title: 'Lesser', |
| 7 | + subject: '애자일한 프로젝트 관리 툴', |
| 8 | + }; |
| 9 | + |
| 10 | + it('should return 201', async () => { |
| 11 | + const { accessToken } = await createMember(memberFixture, app); |
| 12 | + |
| 13 | + const response = await request(app.getHttpServer()) |
| 14 | + .post('/api/project') |
| 15 | + .set('Authorization', `Bearer ${accessToken}`) |
| 16 | + .send(createProjectPayload); |
| 17 | + |
| 18 | + expect(response.status).toBe(201); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should return 400', async () => { |
| 22 | + const response = await request(app.getHttpServer()) |
| 23 | + .post('/api/project') |
| 24 | + .send({ |
| 25 | + invalidProperty: 'invalidProperty', |
| 26 | + }); |
| 27 | + |
| 28 | + expect(response.status).toBe(400); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return 401 (Bearer Token is missing)', async () => { |
| 32 | + const response = await request(app.getHttpServer()) |
| 33 | + .post('/api/project') |
| 34 | + .send(createProjectPayload); |
| 35 | + |
| 36 | + expect(response.status).toBe(401); |
| 37 | + expect(response.body.message).toBe('Bearer Token is missing'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should return 401 (Expired:accessToken) when given invalid access token', async () => { |
| 41 | + const response = await request(app.getHttpServer()) |
| 42 | + .post('/api/project') |
| 43 | + .set('Authorization', `Bearer invalidToken`) |
| 44 | + .send(createProjectPayload); |
| 45 | + |
| 46 | + expect(response.status).toBe(401); |
| 47 | + expect(response.body.message).toBe('Expired:accessToken'); |
| 48 | + }); |
| 49 | +}); |
0 commit comments