Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
eldpswp99 committed Oct 12, 2023
1 parent 8f0c9f2 commit e0ca3b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions backend/src/test/auth/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as supertest from 'supertest';
import { User } from '../../user/models/user.entity';
import { UserFixture } from '../fixture/user.fixture';
import { HttpStatus } from '@nestjs/common';
import { validateDtoKeys } from '../utils';

describe('login test', () => {
let testServer: NestExpressApplication;
Expand Down Expand Up @@ -69,6 +70,16 @@ describe('login test', () => {
expect(user.password).not.toEqual('world');
});

it.todo('access token 과 refresh token을 주저야 한다.');
it.todo('Response body 형식 체크');
it('Response body 형식 체크', async () => {
const { body } = await supertest(testServer.getHttpServer())
.post('/auth/login')
.send({
username: 'hello',
password: 'world',
})
.expect(HttpStatus.CREATED);

validateDtoKeys(body, ['accessToken', 'refreshToken']);
expect(body.accessToken).not.toEqual(body.refreshToken);
});
});
6 changes: 6 additions & 0 deletions backend/src/test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function validateDtoKeys(dto: any, keys: string[]) {
const dtoKeys = Object.keys(dto);
for (const key of keys) {
expect(dtoKeys).toContain(key);
}
}

0 comments on commit e0ca3b4

Please sign in to comment.