Skip to content

Commit

Permalink
fix: change type naming MockUser to SignUpRequestBody
Browse files Browse the repository at this point in the history
  • Loading branch information
yougyung committed May 11, 2024
1 parent e1b285b commit eacbef1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/business/user/user.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { FormState } from '@/app/ui/view/molecule/form/form-root';
import { API_PATH } from '../api-path';
import { MockUser as SignUpRequestBody, SignInRequestBody, ValidateTokenResponse } from './user.type';
import { SignUpRequestBody, SignInRequestBody, ValidateTokenResponse } from './user.type';
import { httpErrorHandler } from '@/app/utils/http/http-error-handler';
import { BadRequestError } from '@/app/utils/http/http-error';
import {
Expand Down
2 changes: 1 addition & 1 deletion app/business/user/user.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface SignInRequestBody {
password: string;
}

export interface MockUser {
export interface SignUpRequestBody {
authId: string;
password: string;
studentNumber: string;
Expand Down
12 changes: 8 additions & 4 deletions app/mocks/db.mock.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { MockUser, UserInfoResponse } from './../business/user/user.type';
import { SearchLectures } from '../business/lecture/search-lecture.query';
import { TakenLectures } from '../business/lecture/taken-lecture.query';
import { CreditResponse, ResultCategoryDetailResponse } from '../business/result/result.type';
import { MockUser as SignUpRequestBody, SignInRequestBody } from '../business/user/user.type';
import {
SignUpRequestBody,
SignInRequestBody,
UserInfoResponse,
InitUserInfoResponse,
} from '../business/user/user.type';
import { takenLectures, credits, searchLectures, userInfo, users, resultCategoryDetailInfo } from './data.mock';

interface MockDatabaseState {
takenLectures: TakenLectures;
resultCategoryDetailInfo: ResultCategoryDetailResponse;
credits: CreditResponse[];
users: MockUser[];
users: SignUpRequestBody[];
searchLectures: SearchLectures;
userInfo: UserInfoResponse;
}
Expand All @@ -22,7 +26,7 @@ type MockDatabaseAction = {
createUser: (user: SignUpRequestBody) => boolean;
signIn: (userData: SignInRequestBody) => boolean;
getCredits: () => CreditResponse[];
getUserInfo: (authId: string) => UserInfoResponse;
getUserInfo: (authId: string) => UserInfoResponse | InitUserInfoResponse;
getResultCategoryDetailInfo: () => ResultCategoryDetailResponse;
};

Expand Down
30 changes: 17 additions & 13 deletions app/mocks/handlers/user-handler.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { HttpResponse, http, delay } from 'msw';
import { API_PATH } from '../../business/api-path';
import { mockDatabase } from '../db.mock';
import {
MockUser as SignUpRequestBody,
SignUpRequestBody,
SignInRequestBody,
SignInResponse,
ValidateTokenResponse,
UserInfoResponse,
InitUserInfoResponse,
} from '@/app/business/user/user.type';
import { ErrorResponseData } from '@/app/utils/http/http-error-handler';

Expand All @@ -31,20 +32,23 @@ export const userHandlers = [
accessToken: 'fake-access-token',
});
}),
http.get<never, never, UserInfoResponse | ErrorResponseData>(API_PATH.user, async ({ request }) => {
const accessToken = request.headers.get('Authorization')?.replace('Bearer ', '');
if (accessToken === 'undefined' || !accessToken) {
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 });
}
const userInfo = mockDatabase.getUserInfo(mockDecryptToken(accessToken).authId);
await delay(3000);
http.get<never, never, UserInfoResponse | InitUserInfoResponse | ErrorResponseData>(
API_PATH.user,
async ({ request }) => {
const accessToken = request.headers.get('Authorization')?.replace('Bearer ', '');
if (accessToken === 'undefined' || !accessToken) {
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 });
}
const userInfo = mockDatabase.getUserInfo(mockDecryptToken(accessToken).authId);
await delay(3000);

if (!userInfo) {
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 });
}
if (!userInfo) {
return HttpResponse.json({ status: 401, message: 'Unauthorized' }, { status: 401 });
}

return HttpResponse.json(userInfo);
}),
return HttpResponse.json(userInfo);
},
),

http.post<never, SignUpRequestBody, never>(`${API_PATH.user}/sign-up`, async ({ request }) => {
const userData = await request.json();
Expand Down

0 comments on commit eacbef1

Please sign in to comment.