Skip to content

Commit b0d7e25

Browse files
committed
Feat: Wrtie test code
1 parent 9571453 commit b0d7e25

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

src/user/user.resolver.spec.ts

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22

3+
import { DataSource } from 'typeorm';
4+
35
import {
46
MockService,
57
MockServiceFactory,
@@ -27,6 +29,10 @@ describe('UserResolver', () => {
2729
provide: UserService,
2830
useFactory: MockServiceFactory.getMockService(UserService),
2931
},
32+
{
33+
provide: DataSource,
34+
useValue: undefined,
35+
},
3036
],
3137
}).compile();
3238

@@ -40,39 +46,31 @@ describe('UserResolver', () => {
4046
});
4147

4248
it('Calling "Get many user list" method', () => {
43-
const qs: GetManyInput<User> = {
49+
const condition: GetManyInput<User> = {
4450
where: { id: utilService.getRandomUUID },
4551
};
4652

47-
const gqlQuery = `
48-
query GetManyUserList {
49-
getManyUserList {
50-
data {
51-
id
52-
}
53-
}
54-
}
55-
`;
56-
57-
expect(resolver.getManyUserList(qs, gqlQuery)).not.toEqual(null);
58-
expect(mockedService.getMany).toHaveBeenCalledWith(qs, gqlQuery);
53+
const option = { relations: undefined, select: undefined };
54+
55+
expect(resolver.getManyUserList(condition, option)).not.toEqual(null);
56+
expect(mockedService.getMany).toHaveBeenCalledWith({
57+
...condition,
58+
...option,
59+
});
5960
});
6061

6162
it('Calling "Get one user list" method', () => {
62-
const qs: GetOneInput<User> = {
63+
const condition: GetOneInput<User> = {
6364
where: { id: utilService.getRandomUUID },
6465
};
6566

66-
const gqlQuery = `
67-
query GetOneUser ($input: GetOneInput!) {
68-
getOneUser (input:$input) {
69-
id
70-
}
71-
}
72-
`;
67+
const option = { relations: undefined, select: undefined };
7368

74-
expect(resolver.getOneUser(qs, gqlQuery)).not.toEqual(null);
75-
expect(mockedService.getOne).toHaveBeenCalledWith(qs, gqlQuery);
69+
expect(resolver.getOneUser(condition, option)).not.toEqual(null);
70+
expect(mockedService.getOne).toHaveBeenCalledWith({
71+
...condition,
72+
...option,
73+
});
7674
});
7775

7876
it('Calling "Create user" method', () => {
@@ -102,20 +100,14 @@ describe('UserResolver', () => {
102100
it('Calling "Get Me" method', () => {
103101
const user = new User();
104102

105-
const gqlQuery = `
106-
query {
107-
getMe {
108-
id
109-
}
110-
}
111-
`;
112-
113-
expect(resolver.getMe(user, gqlQuery)).not.toEqual(null);
114-
expect(mockedService.getOne).toHaveBeenCalledWith(
115-
{
116-
where: { id: user.id },
117-
},
118-
gqlQuery,
119-
);
103+
const condition: GetOneInput<User> = { where: { id: user.id } };
104+
105+
const option = { relations: undefined, select: undefined };
106+
107+
expect(resolver.getMe(user, option)).not.toEqual(null);
108+
expect(mockedService.getOne).toHaveBeenCalledWith({
109+
...condition,
110+
...option,
111+
});
120112
});
121113
});

src/user/user.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ describe('UserService', () => {
4444
});
4545

4646
it('Calling "Get many" method', () => {
47-
const qs: RepoQuery<User> = {
47+
const option: RepoQuery<User> = {
4848
where: { id: utilService.getRandomUUID },
4949
};
5050

51-
expect(service.getMany(qs)).not.toEqual(null);
51+
expect(service.getMany(option)).not.toEqual(null);
5252
expect(mockedRepository.getMany).toHaveBeenCalled();
5353
});
5454

5555
it('Calling "Get one" method', () => {
56-
const qs: OneRepoQuery<User> = {
56+
const option: OneRepoQuery<User> = {
5757
where: { id: utilService.getRandomUUID },
5858
};
5959

60-
expect(service.getOne(qs)).not.toEqual(null);
60+
expect(service.getOne(option)).not.toEqual(null);
6161
expect(mockedRepository.getOne).toHaveBeenCalled();
6262
});
6363

0 commit comments

Comments
 (0)