Skip to content

Commit

Permalink
test: 토큰 인증 msw 작성 및 로그인, 토큰인증 mock data 작성 #179
Browse files Browse the repository at this point in the history
  • Loading branch information
seoye0ng committed Feb 20, 2024
1 parent c30b2b2 commit 489aeae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mocks/authHandler/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { http, HttpResponse } from 'msw';

import { MOCK_LOGIN_DATA, MOCK_TOKEN_DATA } from './mocks';

export const authHandlers = [
/* ----- 회원가입 api ----- */
http.post(`${process.env.NEXT_PUBLIC_BASE_URL}/member/join`, () => {
Expand All @@ -9,6 +11,17 @@ export const authHandlers = [

/* ----- 로그인 api ----- */
http.post(`${process.env.NEXT_PUBLIC_BASE_URL}/member/login`, () => {
return HttpResponse.json('로그인 성공!!');
return HttpResponse.json(MOCK_LOGIN_DATA);
}),

/* ----- refresh token api success ----- */
http.post(`${process.env.NEXT_PUBLIC_BASE_URL}/auth/validToken`, () => {
return HttpResponse.json(MOCK_TOKEN_DATA);
}),

/* ----- refresh token api error ----- */
http.post(`${process.env.NEXT_PUBLIC_BASE_URL}/auth/validToken`, () => {
return HttpResponse.json(Error);
}),

];
29 changes: 29 additions & 0 deletions src/mocks/authHandler/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* ----- 로그인 MOCK DATA ----- */
export const MOCK_LOGIN_DATA = {
status: 200,
code: 'BMC002',
message: '로그인 성공',
value: {
memberNo: 7251,
id: 'stest0123',
email: '[email protected]',
password: null,
gender: 'woman',
age: '30',
createdAt: '2024-02-19',
createdBy: 'admin',
modifiedAt: '2024-02-19',
modifiedBy: 'admin',
jwtToken: 'test-abcdefg1234--abc',
},
};

/* ----- 토큰 MOCK DATA ----- */
export const MOCK_TOKEN_DATA = {
status: 202,
code: 'BMC002',
message: '토큰 인증 성공',
value: {
jwtToken: 'success-test-abcdefg1234--abc',
},
};

0 comments on commit 489aeae

Please sign in to comment.