Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock refactor #94

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions app/__test__/page.test.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions app/business/invoice/revenue.command.ts

This file was deleted.

21 changes: 0 additions & 21 deletions app/business/invoice/revenue.query.ts

This file was deleted.

29 changes: 0 additions & 29 deletions app/dashboard/components/dashboard-nav-links.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions app/dashboard/components/side-nav.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/dashboard/invoices/page.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions app/dashboard/layout.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/dashboard/loading.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions app/dashboard/page.tsx

This file was deleted.

38 changes: 38 additions & 0 deletions app/mocks/actions/lecture-action.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { SearchLectures } from '@/app/business/lecture/search-lecture.query';
import { TakenLectures } from '@/app/business/lecture/taken-lecture.query';
import { mockDatabaseStore } from '../data';

export interface MockLectureAction {
getTakenLectures: () => TakenLectures;
getSearchLectures: () => SearchLectures;
addTakenLecture: (lectureId: number) => boolean;
deleteTakenLecture: (lectureId: number) => boolean;
}

export const mockLectureAction: MockLectureAction = {
getTakenLectures: () => mockDatabaseStore.takenLectures,
getSearchLectures: () => mockDatabaseStore.searchLectures,
deleteTakenLecture: (lectureId) => {
if (mockDatabaseStore.takenLectures.takenLectures.find((lecture) => lecture.id === lectureId)) {
mockDatabaseStore.takenLectures.takenLectures = mockDatabaseStore.takenLectures.takenLectures.filter(
(lecture) => lecture.id !== lectureId,
);
return true;
}
return false;
},
addTakenLecture: (lectureId) => {
mockDatabaseStore.takenLectures.takenLectures = [
...mockDatabaseStore.takenLectures.takenLectures,
{
id: lectureId,
year: '2023',
semester: '2ํ•™๊ธฐ',
lectureCode: 'HECD140',
lectureName: '์ถ”๊ฐ€ํ•œ๊ณผ๋ชฉ',
credit: 3,
},
];
return true;
},
};
10 changes: 10 additions & 0 deletions app/mocks/actions/result-action.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { type ResultCategoryDetailInfo } from '../../business/result/result.query';
import { mockDatabaseStore } from '../data';

export interface MockResultAction {
getResultCategoryDetailInfo: () => ResultCategoryDetailInfo;
}

export const mockResultAction: MockResultAction = {
getResultCategoryDetailInfo: () => mockDatabaseStore.resultCategoryDetailInfo,
};
50 changes: 50 additions & 0 deletions app/mocks/actions/user-action.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { SignInRequestBody, SignUpRequestBody, UserInfoResponse } from '@/app/business/user/user.type';
import { MockUser } from '../data';
import { mockDatabaseStore } from '../data';

export interface MockUserACtion {
getUser: (authId: string) => MockUser | undefined;
createUser: (user: SignUpRequestBody) => boolean;
signIn: (userData: SignInRequestBody) => boolean;
getUserInfo: (authId: string) => UserInfoResponse;
}

export const mockUserAction: MockUserACtion = {
getUser: (authId: string) => mockDatabaseStore.users.find((user) => user.authId === authId),
createUser: (user: SignUpRequestBody) => {
if (mockDatabaseStore.users.find((u) => u.authId === user.authId || u.studentNumber === user.studentNumber)) {
return false;
}
mockDatabaseStore.users = [
...mockDatabaseStore.users,
{
...user,
isSumbitted: false,
major: '์œต์†Œ์ž…๋‹ˆ๋‹ค',
name: '๋ชจํ‚น์ด2',
},
];
return true;
},
signIn: (userData: SignInRequestBody) => {
const user = mockDatabaseStore.users.find((u) => u.authId === userData.authId && u.password === userData.password);
return !!user;
},
getUserInfo: (authId: string) => {
const user = mockDatabaseStore.users.find((u) => u.authId === authId);
if (!user) {
return {
studentNumber: '',
studentName: '',
major: '',
isSumbitted: false,
};
}
return {
studentNumber: user.studentNumber,
studentName: user.name,
major: user.major,
isSumbitted: user.isSumbitted,
};
},
};
File renamed without changes.
48 changes: 48 additions & 0 deletions app/mocks/data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { takenLectures, resultCategoryDetailInfo, searchLectures } from './data.mock';
import { SearchLectures } from '@/app/business/lecture/search-lecture.query';
import { TakenLectures } from '@/app/business/lecture/taken-lecture.query';
import { ResultCategoryDetailInfo } from '@/app/business/result/result.query';

export interface MockUser {
authId: string;
password: string;
studentNumber: string;
engLv: string;
major: string;
isSumbitted: boolean;
name: string;
}

interface MockDatabaseState {
takenLectures: TakenLectures;
resultCategoryDetailInfo: ResultCategoryDetailInfo;
users: MockUser[];
searchLectures: SearchLectures;
}

const initialState: MockDatabaseState = {
takenLectures: takenLectures,
resultCategoryDetailInfo: resultCategoryDetailInfo,
users: [
{
authId: 'admin',
password: 'admin',
studentNumber: '60000000',
engLv: 'ENG12',
isSumbitted: false,
major: '์œต์†Œ์ž…๋‹ˆ๋‹ค',
name: '๋ชจํ‚น์ด',
},
],
searchLectures: searchLectures,
};

function initStore(): MockDatabaseState {
return JSON.parse(JSON.stringify(initialState));
}

export let mockDatabaseStore = initStore();

export const resetMockDB = () => {
mockDatabaseStore = initStore();
};
Comment on lines +40 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db.mock.ts๊ฐ€ ์•„๋‹ˆ๋ผ data ํด๋”์— ์žˆ๋Š” ์ด์œ ๊ฐ€ ๋”ฐ๋กœ ์žˆ์„๊นŒ์š”?

Loading
Loading