1
1
import { Test , TestingModule } from '@nestjs/testing' ;
2
- import { ParticipantApiController , Participant , Friend , Inbound , Outbound } from './participant.controller' ;
2
+ import {
3
+ ParticipantApiController ,
4
+ Participant ,
5
+ Friend ,
6
+ Inbound ,
7
+ Outbound ,
8
+ } from './participant.controller' ;
3
9
import { Friend as FriendEntity } from '../entity/friend' ;
4
10
import { Participant as ParticipantEntity } from '../entity/participant' ;
5
- import { ParticipantService , OutboundService , InboundService , InboundModel , OutboundModel , ParticipantModel } from './participant.service' ;
11
+ import {
12
+ ParticipantService ,
13
+ OutboundService ,
14
+ InboundService ,
15
+ InboundModel ,
16
+ OutboundModel ,
17
+ ParticipantModel ,
18
+ } from './participant.service' ;
6
19
import { SearchService } from '../search.service' ;
7
20
8
21
describe ( 'ParticipantApiController' , ( ) => {
@@ -23,8 +36,19 @@ describe('ParticipantApiController', () => {
23
36
fe . toParticipantId = 2 ;
24
37
const pm1 : ParticipantModel = new ParticipantModel ( 1 , 'Hello World!' ) ;
25
38
const pm2 : ParticipantModel = new ParticipantModel ( 2 , 'foo bar' ) ;
26
- const im : InboundModel = new InboundModel ( pm1 , pm2 , nowAsDate , 'test subject' , 'test story' ) ;
27
- const om : OutboundModel = new OutboundModel ( pm1 , nowAsDate , 'test subject' , 'test story' ) ;
39
+ const im : InboundModel = new InboundModel (
40
+ pm1 ,
41
+ pm2 ,
42
+ nowAsDate ,
43
+ 'test subject' ,
44
+ 'test story' ,
45
+ ) ;
46
+ const om : OutboundModel = new OutboundModel (
47
+ pm1 ,
48
+ nowAsDate ,
49
+ 'test subject' ,
50
+ 'test story' ,
51
+ ) ;
28
52
const app : TestingModule = await Test . createTestingModule ( {
29
53
imports : [ ] ,
30
54
controllers : [ ParticipantApiController ] ,
@@ -38,17 +62,17 @@ describe('ParticipantApiController', () => {
38
62
} ,
39
63
} ,
40
64
{
41
- provide : 'ParticipantRepository ' ,
65
+ provide : 'PARTICIPANT_REPOSITORY ' ,
42
66
useValue : {
43
67
findOneBy : jest . fn ( ) . mockReturnValue ( Promise . resolve ( pe ) ) ,
44
68
save : jest . fn ( ) . mockImplementation ( ( ) => {
45
69
participantSaved ++ ;
46
70
return Promise . resolve ( pe ) ;
47
- } )
48
- }
71
+ } ) ,
72
+ } ,
49
73
} ,
50
74
{
51
- provide : 'FriendRepository ' ,
75
+ provide : 'FRIEND_REPOSITORY ' ,
52
76
useValue : {
53
77
save : jest . fn ( ) . mockImplementation ( ( ) => {
54
78
friendSaved ++ ;
@@ -75,7 +99,7 @@ describe('ParticipantApiController', () => {
75
99
useValue : {
76
100
get : jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ im ] ) ) ,
77
101
save : jest . fn ( ) . mockImplementation ( ( ) => {
78
- inboundSaved ++ ; nowAsDate
102
+ inboundSaved ++ ;
79
103
return Promise . resolve ( im ) ;
80
104
} ) ,
81
105
} ,
@@ -89,8 +113,7 @@ describe('ParticipantApiController', () => {
89
113
} ,
90
114
ParticipantService ,
91
115
] ,
92
- } )
93
- . compile ( ) ;
116
+ } ) . compile ( ) ;
94
117
95
118
appController = app . get < ParticipantApiController > ( ParticipantApiController ) ;
96
119
} ) ;
@@ -105,6 +128,7 @@ describe('ParticipantApiController', () => {
105
128
const p : Participant = new Participant ( 1 , 'Hello World!' ) ;
106
129
const t : Participant | undefined = await appController ?. addParticipant ( p ) ;
107
130
expect ( participantSaved ) . toBeGreaterThan ( 0 ) ;
131
+ expect ( t ) . toStrictEqual ( p ) ;
108
132
} ) ;
109
133
} ) ;
110
134
describe ( 'friend' , ( ) => {
@@ -145,9 +169,12 @@ describe('ParticipantApiController', () => {
145
169
} ) ;
146
170
it ( 'add should call underlying repository add' , async ( ) => {
147
171
const p1 : Participant = new Participant ( 1 , 'Hello World!' ) ;
148
- const p2 : Participant = new Participant ( 2 , 'foo bar' ) ;
149
- const f : Friend = new Friend ( 1 , p1 . link , p2 . link ) ;
150
- const o : Outbound = new Outbound ( p1 . link , nowAsDate , 'test subject' , 'test story' ) ;
172
+ const o : Outbound = new Outbound (
173
+ p1 . link ,
174
+ nowAsDate ,
175
+ 'test subject' ,
176
+ 'test story' ,
177
+ ) ;
151
178
const t : Outbound | undefined = await appController ?. addOutbound ( 1 , o ) ;
152
179
expect ( outboundSaved ) . toBeGreaterThan ( 0 ) ;
153
180
expect ( inboundSaved ) . toBeGreaterThan ( 0 ) ;
0 commit comments