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

Feature #194 도메인 모델 객체 테스트 추가 #195

Merged
merged 5 commits into from
Dec 2, 2024
Merged
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
1 change: 1 addition & 0 deletions apps/frontend/src/feature/codeView/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model';
193 changes: 193 additions & 0 deletions apps/frontend/src/feature/codeView/model/model.test.ts
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);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CANT_VIEW_EXT, LANGUAGES_EXT } from './constant';
import { CANT_VIEW_EXT, LANGUAGES_EXT } from '@/feature/codeView/constant';

export interface CodeFileDto {
filename: string;
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/feature/history/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model';
125 changes: 125 additions & 0 deletions apps/frontend/src/feature/history/model/model.test.ts
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);
}
);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HISTORY_STATUS } from './constant';
import { HistoryStatus } from './type';
import { HISTORY_STATUS } from '@/feature/history/constant';
import { HistoryStatus } from '@/feature/history/type';

export interface HistoryDto {
id: string;
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/feature/lotus/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model';
Loading
Loading