-
Notifications
You must be signed in to change notification settings - Fork 1
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
Mock refactor #94
Changes from all commits
81251de
8eeccf0
cf1b8a4
c42bac2
7041074
adecc53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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; | ||
}, | ||
}; |
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, | ||
}; |
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, | ||
}; | ||
}, | ||
}; |
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(); | ||
}; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db.mock.ts๊ฐ ์๋๋ผ data ํด๋์ ์๋ ์ด์ ๊ฐ ๋ฐ๋ก ์์๊น์?