From e0ca3b4ef6985b2ea8e7d0adeaa9161dcef63424 Mon Sep 17 00:00:00 2001 From: eldpswp99 Date: Thu, 12 Oct 2023 20:24:26 +0900 Subject: [PATCH] add test --- backend/src/test/auth/login.spec.ts | 15 +++++++++++++-- backend/src/test/utils.ts | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 backend/src/test/utils.ts diff --git a/backend/src/test/auth/login.spec.ts b/backend/src/test/auth/login.spec.ts index af3d6e2..cd73f59 100644 --- a/backend/src/test/auth/login.spec.ts +++ b/backend/src/test/auth/login.spec.ts @@ -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; @@ -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); + }); }); diff --git a/backend/src/test/utils.ts b/backend/src/test/utils.ts new file mode 100644 index 0000000..362d7e7 --- /dev/null +++ b/backend/src/test/utils.ts @@ -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); + } +}