-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* test(#194): 도메인 UserModel 테스트 * refactor(#194): 파일이름 pagination type에서 model로 변경 * test(#194): 도메인 LotusModel 테스트 * test(#194): 도메인 HistoryModel 테스트 * test(#194): 도메인 CodeViewModel 테스트
- Loading branch information
Showing
14 changed files
with
464 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { CodeFileModel } from './model'; | ||
|
||
describe('CodeFileModel', () => { | ||
it.each([ | ||
{ | ||
description: '올바른 DTO를 받아 CodeFileModel을 생성합니다.', | ||
dto: { | ||
filename: 'example.js', | ||
language: 'JavaScript', | ||
content: 'console.log("Hello, world!");' | ||
}, | ||
expected: { | ||
filename: 'example.js', | ||
language: 'JavaScript', | ||
content: 'console.log("Hello, world!");', | ||
ext: 'js' | ||
} | ||
}, | ||
{ | ||
description: '비어있는 값은 빈 값으로 처리합니다.', | ||
dto: { | ||
filename: '', | ||
language: '', | ||
content: '' | ||
}, | ||
expected: { | ||
filename: '', | ||
language: '', | ||
content: '', | ||
ext: '' | ||
} | ||
} | ||
])('$description', ({ dto, expected }) => { | ||
// Given | ||
const model = new CodeFileModel(dto); | ||
|
||
//When | ||
|
||
// Then: 필드 검증 | ||
expect(model).toMatchObject(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
description: 'README 파일일 경우 isREADME가 true입니다.', | ||
dto: { | ||
filename: 'README.md', | ||
language: 'Markdown', | ||
content: '# Hello World' | ||
}, | ||
expected: true | ||
}, | ||
{ | ||
description: 'README 파일이 아닐 경우 isREADME가 false입니다.', | ||
dto: { | ||
filename: 'example.js', | ||
language: 'JavaScript', | ||
content: 'console.log("Hello, world!");' | ||
}, | ||
expected: false | ||
} | ||
])('$description', ({ dto, expected }) => { | ||
// Given | ||
const model = new CodeFileModel(dto); | ||
|
||
//When | ||
|
||
// Then: isREADME getter 확인 | ||
expect(model.isREADME).toBe(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
description: '마크다운 파일인 경우 isMarkdown가 true입니다.', | ||
dto: { | ||
filename: 'example.md', | ||
language: 'Markdown', | ||
content: '# Hello World' | ||
}, | ||
expected: true | ||
}, | ||
{ | ||
description: '마크다운 파일이 아닌 경우 isMarkdown가 false입니다.', | ||
dto: { | ||
filename: 'example.js', | ||
language: 'JavaScript', | ||
content: 'console.log("Hello, world!");' | ||
}, | ||
expected: false | ||
} | ||
])('$description', ({ dto, expected }) => { | ||
// Given | ||
const model = new CodeFileModel(dto); | ||
|
||
//When | ||
|
||
// Then: isMarkdown getter 확인 | ||
expect(model.isMarkdown).toBe(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
description: '지원하는 확장자 형식인 경우 canView가 true입니다.', | ||
dto: { | ||
filename: 'example.md', | ||
language: 'Markdown', | ||
content: '# Hello World' | ||
}, | ||
expected: true | ||
}, | ||
{ | ||
description: '지원하지 않는 확장자의 경우 canView가 false입니다.', | ||
dto: { | ||
filename: 'example.png', | ||
language: 'Binary', | ||
content: '' | ||
}, | ||
expected: false | ||
} | ||
])('$description', ({ dto, expected }) => { | ||
// Given | ||
const model = new CodeFileModel(dto); | ||
|
||
//When | ||
|
||
// Then: canView getter 확인 | ||
expect(model.canView).toBe(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
description: 'README 파일이 존재하는 경우 getDefaultFile은 README 파일을 반환합니다.', | ||
files: [ | ||
new CodeFileModel({ filename: 'README.md', language: 'Markdown', content: '# Hello' }), | ||
new CodeFileModel({ filename: 'example.js', language: 'JavaScript', content: 'console.log("test");' }), | ||
new CodeFileModel({ filename: 'example.md', language: 'Markdown', content: 'hola' }) | ||
], | ||
expected: 'README.md' | ||
}, | ||
{ | ||
description: 'README 파일이 없고 마크다운 파일이 존재하는 경우 getDefaultFile은 마크다운 파일을 반환합니다.', | ||
files: [ | ||
new CodeFileModel({ filename: 'example.md', language: 'Markdown', content: '# Hello' }), | ||
new CodeFileModel({ filename: 'example.js', language: 'JavaScript', content: 'console.log("test");' }) | ||
], | ||
expected: 'example.md' | ||
}, | ||
{ | ||
description: 'README 파일과 마크다운 파일이 없는 경우 getDefaultFile은 undefined를 반환합니다.', | ||
files: [ | ||
new CodeFileModel({ filename: 'example.js', language: 'JavaScript', content: 'console.log("test");' }), | ||
new CodeFileModel({ filename: 'example.py', language: 'Python', content: 'print("Hello")' }) | ||
], | ||
expected: undefined | ||
} | ||
])('$description', ({ files, expected }) => { | ||
//Given | ||
|
||
//When | ||
const defaultFile = CodeFileModel.getDefaultFile(files); | ||
|
||
//Then | ||
expect(defaultFile?.filename).toBe(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
description: '지원하는 언어파일인 경우 언어에 맞는 content를 마크다운 문자열로 반환합니다', | ||
dto: { | ||
filename: 'example.js', | ||
language: 'JavaScript', | ||
content: 'console.log("Hello, world!");' | ||
}, | ||
expected: '```js\nconsole.log("Hello, world!");\n ```' | ||
}, | ||
{ | ||
description: '지원하지 않는 언어 파일이나, 언어 파일이 아닌 경우 그냥 content를 반환합니다', | ||
dto: { | ||
filename: 'example.txt', | ||
language: 'Text', | ||
content: 'Just some text' | ||
}, | ||
expected: 'Just some text' | ||
} | ||
])('$description', ({ dto, expected }) => { | ||
// Given | ||
const model = new CodeFileModel(dto); | ||
|
||
// Then: toMarkdown 확인 | ||
expect(model.toMarkdown()).toBe(expected); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
apps/frontend/src/feature/codeView/model.ts → ...ntend/src/feature/codeView/model/model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { HistoryModel } from './model'; | ||
import { HISTORY_STATUS } from '@/feature/history/constant'; | ||
|
||
describe('HistoryModel', () => { | ||
it.each([ | ||
{ | ||
description: '올바른 DTO를 받아 HistoryModel을 생성합니다.', | ||
dto: { | ||
id: '1', | ||
status: HISTORY_STATUS.SUCCESS, | ||
date: '2024-01-01T00:00:00.000Z', | ||
input: 'some input', | ||
output: 'some output', | ||
filename: 'file1.txt' | ||
}, | ||
expected: { | ||
id: '1', | ||
status: HISTORY_STATUS.SUCCESS, | ||
date: new Date('2024-01-01T00:00:00.000Z'), | ||
input: 'some input', | ||
output: 'some output', | ||
filename: 'file1.txt' | ||
} | ||
}, | ||
{ | ||
description: '잘못된 status를 받아 HistoryModel을 생성하면 status는 ERROR로 설정됩니다.', | ||
dto: { | ||
id: '2', | ||
status: 'INVALID_STATUS', | ||
date: '2024-02-01T00:00:00.000Z', | ||
input: 'input2', | ||
output: 'output2', | ||
filename: 'file2.txt' | ||
}, | ||
expected: { | ||
id: '2', | ||
status: HISTORY_STATUS.ERROR, | ||
date: new Date('2024-02-01T00:00:00.000Z'), | ||
input: 'input2', | ||
output: 'output2', | ||
filename: 'file2.txt' | ||
} | ||
} | ||
])('$description', ({ dto, expected }) => { | ||
// Given | ||
const historyModel = new HistoryModel(dto); | ||
|
||
// Then: 객체 속성 검증 | ||
expect(historyModel).toMatchObject(expected); | ||
}); | ||
|
||
it('getPendingHistoriesId는 HistoryModel[]을 인자로 받아 PENDING 상태인 HistoryId를 반환합니다.', () => { | ||
// Given | ||
const expected = ['1', '3']; | ||
const histories = [ | ||
new HistoryModel({ | ||
id: '1', | ||
status: HISTORY_STATUS.PENDING, | ||
date: '2024-01-01T00:00:00.000Z', | ||
input: 'input1', | ||
output: 'output1', | ||
filename: 'file1.txt' | ||
}), | ||
new HistoryModel({ | ||
id: '2', | ||
status: HISTORY_STATUS.SUCCESS, | ||
date: '2024-02-01T00:00:00.000Z', | ||
input: 'input2', | ||
output: 'output2', | ||
filename: 'file2.txt' | ||
}), | ||
new HistoryModel({ | ||
id: '3', | ||
status: HISTORY_STATUS.PENDING, | ||
date: '2024-03-01T00:00:00.000Z', | ||
input: 'input3', | ||
output: 'output3', | ||
filename: 'file3.txt' | ||
}) | ||
]; | ||
|
||
// When | ||
const pendingIds = HistoryModel.getPendingHistoriesId(histories); | ||
|
||
// Then | ||
expect(pendingIds).toEqual(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
history: new HistoryModel({ | ||
id: '1', | ||
status: HISTORY_STATUS.SUCCESS, | ||
date: '2024-01-01T00:00:00.000Z', | ||
input: 'input1', | ||
output: 'output1', | ||
filename: 'file1.txt' | ||
}), | ||
status: HISTORY_STATUS.SUCCESS, | ||
expected: true | ||
}, | ||
{ | ||
history: new HistoryModel({ | ||
id: '2', | ||
status: HISTORY_STATUS.ERROR, | ||
date: '2024-02-01T00:00:00.000Z', | ||
input: 'input2', | ||
output: 'output2', | ||
filename: 'file2.txt' | ||
}), | ||
status: HISTORY_STATUS.PENDING, | ||
expected: false | ||
} | ||
])( | ||
'isStatus를 통해 history의 status를 검증할 수 있습니다. ($history.status 일때 history.isStatus($status)는 $expected 입니다.)', | ||
({ history, status, expected }) => { | ||
//Given | ||
//When | ||
|
||
//Then | ||
expect(history.isStatus(status)).toBe(expected); | ||
} | ||
); | ||
}); |
4 changes: 2 additions & 2 deletions
4
apps/frontend/src/feature/history/model.ts → ...ontend/src/feature/history/model/model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model'; |
Oops, something went wrong.