@@ -2,12 +2,25 @@ const { findMatch, cancelMatch } = require('../services/matchingService');
2
2
const { getCurrentMatchedPair, deleteAllMatchedPairs } = require ( '../database/matchedPairDb' ) ;
3
3
const mongoose = require ( 'mongoose' ) ;
4
4
const { MongoMemoryServer } = require ( 'mongodb-memory-server' ) ;
5
+ const config = require ( '../config/config' ) ;
6
+ const axios = require ( 'axios' ) ;
7
+ const MockAdapter = require ( 'axios-mock-adapter' ) ;
5
8
6
9
jest . setTimeout ( 200000 ) ;
7
10
8
11
describe ( 'Matching Service' , ( ) => {
9
12
10
13
let mongod ;
14
+
15
+ const testQuestion = {
16
+ _id : new mongoose . Types . ObjectId ( "65378371752185e6e1b5b342" ) ,
17
+ title : "test1" ,
18
+ description : "test1 desp" ,
19
+ complexity : "Test" ,
20
+ category : "Test" ,
21
+ language :"Test" ,
22
+ userTags : [ ] ,
23
+ } ;
11
24
12
25
beforeAll ( async ( ) => {
13
26
mongod = await MongoMemoryServer . create ( ) ;
@@ -19,6 +32,14 @@ describe('Matching Service', () => {
19
32
} ) ;
20
33
21
34
console . log ( "testDB connected" ) ;
35
+
36
+ const mock = new MockAdapter ( axios ) ;
37
+
38
+ mock . onPost ( `${ config . questionServiceUrl } /match` )
39
+ . reply ( 200 , {
40
+ questionId : "65378371752185e6e1b5b342" ,
41
+ question : testQuestion ,
42
+ } ) ;
22
43
} ) ;
23
44
24
45
afterAll ( async ( ) => {
@@ -144,7 +165,7 @@ describe('Matching Service', () => {
144
165
status : 'success' ,
145
166
isMatched : true ,
146
167
sessionId : matchPair . sessionId ,
147
- questionId : null ,
168
+ questionId : testQuestion . _id ,
148
169
collaboratorId : javaRequest2 . id ,
149
170
request : javaRequest1
150
171
}
@@ -153,7 +174,7 @@ describe('Matching Service', () => {
153
174
status : 'success' ,
154
175
isMatched : true ,
155
176
sessionId : matchPair . sessionId ,
156
- questionId : null ,
177
+ questionId : testQuestion . _id ,
157
178
collaboratorId : javaRequest1 . id ,
158
179
request : javaRequest2
159
180
}
@@ -209,7 +230,7 @@ describe('Matching Service', () => {
209
230
status : 'success' ,
210
231
isMatched : true ,
211
232
sessionId : matchPair . sessionId ,
212
- questionId : null ,
233
+ questionId : testQuestion . _id ,
213
234
collaboratorId : cppFullRequest2 . id ,
214
235
request : cppFullRequest1
215
236
}
@@ -218,7 +239,7 @@ describe('Matching Service', () => {
218
239
status : 'success' ,
219
240
isMatched : true ,
220
241
sessionId : matchPair . sessionId ,
221
- questionId : null ,
242
+ questionId : testQuestion . _id ,
222
243
collaboratorId : cppFullRequest1 . id ,
223
244
request : cppFullRequest2
224
245
}
@@ -297,7 +318,7 @@ describe('Matching Service', () => {
297
318
test ( 'Cancel an existing match' , async ( ) => {
298
319
const [ matchResult , cancelResult ] = await Promise . all ( [
299
320
findMatch ( javaRequest1 ) ,
300
- new Promise ( resolve => setTimeout ( resolve , 5000 ) ) . then ( ( ) => cancelMatch ( javaRequest1 . id ) )
321
+ new Promise ( resolve => setTimeout ( resolve , 8000 ) ) . then ( ( ) => cancelMatch ( javaRequest1 . id ) )
301
322
] ) ;
302
323
303
324
const expectResult1 = {
0 commit comments