Skip to content

Commit d08a3b1

Browse files
committed
test: 테스트 코드 추가
1 parent 54a10f8 commit d08a3b1

File tree

5 files changed

+73
-36
lines changed

5 files changed

+73
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nestjs-swagger-instance-creator",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "This is a library that reads information from Swagger decorators and creates instances.",
55
"main": "dist/cjs/index.js",
66
"repository": "git@github.com:hypernova1/swagger-default-instance-creator.git",

test/dto/comment.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
3+
export default class Comment {
4+
@ApiProperty({
5+
description: '댓글 아이디',
6+
default: 1,
7+
})
8+
id: number | undefined;
9+
10+
@ApiProperty({
11+
description: '내용',
12+
default: '잘 봤습니다.'
13+
})
14+
content: string | undefined;
15+
}

test/dto/post.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
import Comment from './comment';
3+
4+
export default class Post {
5+
@ApiProperty({
6+
description: '글 아이디',
7+
default: 1,
8+
})
9+
id: string | undefined;
10+
11+
@ApiProperty({
12+
description: 'post title',
13+
default: 'hello',
14+
required: true,
15+
})
16+
title: string | undefined;
17+
18+
@ApiProperty({
19+
description: 'post content',
20+
default: 'world',
21+
required: false,
22+
23+
})
24+
content: string | undefined;
25+
26+
@ApiProperty({
27+
description: '댓글 목록',
28+
type: Comment,
29+
isArray: true,
30+
default: Comment,
31+
})
32+
comments: Comment[] | undefined;
33+
}

test/dto/user.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
import Post from './post';
3+
4+
export default class User {
5+
@ApiProperty({
6+
description: 'name',
7+
default: 'melchor',
8+
required: true,
9+
})
10+
name: string | undefined;
11+
12+
@ApiProperty({
13+
description: 'post list',
14+
type: Post,
15+
isArray: true,
16+
default: Post,
17+
required: false,
18+
})
19+
posts: Post[] | undefined;
20+
}

test/index.spec.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,15 @@
11
import { createSwaggerDefaultDto, updateSwaggerDto } from '../src';
22
import {ApiProperty} from "@nestjs/swagger";
3-
4-
class Post {
5-
@ApiProperty({
6-
description: 'post title',
7-
default: 'hello',
8-
required: true,
9-
})
10-
title: string | undefined;
11-
12-
@ApiProperty({
13-
description: 'post content',
14-
default: 'world',
15-
required: false,
16-
17-
})
18-
content: string | undefined;
19-
}
20-
21-
class User {
22-
@ApiProperty({
23-
description: 'name',
24-
default: 'melchor',
25-
required: true,
26-
})
27-
name: string | undefined;
28-
29-
@ApiProperty({
30-
description: 'post list',
31-
type: Post,
32-
isArray: true,
33-
default: Post,
34-
required: false,
35-
})
36-
posts: Post[] | undefined;
37-
}
3+
import User from './dto/user';
384

395

406
describe('test', () => {
417
it('create default instance', () => {
428
const instance = createSwaggerDefaultDto(User);
439
expect(instance.name).toBeDefined();
10+
expect(instance.posts?.length).toEqual(1);
11+
// @ts-ignore
12+
expect(instance.posts[0].comments);
4413
});
4514

4615
it('create default instance without required fields', () => {

0 commit comments

Comments
 (0)