Skip to content

Commit 282dbf1

Browse files
committed
Fixed test cases involving ranks schema change.
1 parent 95cc1f4 commit 282dbf1

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

app/socket-apis/__tests__/get-top-ranked-whys-for-point.js

+20
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ describe('getTopRankedWhysForPoint', () => {
8787
_id: new ObjectId(),
8888
parentId: why._id.toString(),
8989
userId: USER1,
90+
round: why.round,
91+
stage: 'pre',
92+
category: why.category,
93+
discussionId: 'discussion-1',
9094
})
9195
}
9296
})
@@ -117,6 +121,10 @@ describe('getTopRankedWhysForPoint', () => {
117121
_id: new ObjectId(),
118122
parentId: why._id.toString(),
119123
userId: USER1,
124+
round: why.round,
125+
stage: 'pre',
126+
category: why.category,
127+
discussionId: 'discussion-1',
120128
})
121129
}
122130
})
@@ -147,6 +155,10 @@ describe('getTopRankedWhysForPoint', () => {
147155
_id: new ObjectId(),
148156
parentId: why._id.toString(),
149157
userId: USER1,
158+
round: why.round,
159+
stage: 'pre',
160+
category: why.category,
161+
discussionId: 'discussion-1',
150162
})
151163
}
152164
})
@@ -177,6 +189,10 @@ describe('getTopRankedWhysForPoint', () => {
177189
_id: new ObjectId(),
178190
parentId: why._id.toString(),
179191
userId: USER1,
192+
round: why.round,
193+
stage: 'pre',
194+
category: why.category,
195+
discussionId: 'discussion-1',
180196
})
181197
}
182198
})
@@ -207,6 +223,10 @@ describe('getTopRankedWhysForPoint', () => {
207223
_id: new ObjectId(),
208224
parentId: why._id.toString(),
209225
userId: USER1,
226+
round: why.round,
227+
stage: 'pre',
228+
category: why.category,
229+
discussionId: 'discussion-1',
210230
})
211231
}
212232
})

app/socket-apis/__tests__/rank-why.js

+36-3
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,62 @@ beforeEach(async () => {
2121
for (let collection of collections) {
2222
await collection.deleteMany({})
2323
}
24+
25+
jest.spyOn(console, 'error').mockImplementation(() => {})
26+
})
27+
28+
afterEach(async () => {
29+
console.error.mockRestore()
2430
})
31+
2532
afterAll(async () => {
2633
await Mongo.disconnect()
2734
await MemoryServer.stop()
2835
})
2936

3037
test('Insert a new rank document', async () => {
31-
const rankObj = { _id: RANK2, parentId: 'parent-id-1', round: 1, rank: 'most' }
38+
const rankObj = {
39+
_id: RANK2,
40+
parentId: 'parent-id-1',
41+
round: 1,
42+
rank: 'most',
43+
stage: 'pre',
44+
category: 'category-1',
45+
discussionId: 'discussion-1',
46+
}
3247

3348
const cb = jest.fn()
3449

3550
await rankWhy.call({ synuser: { id: USER1 } }, rankObj, cb)
3651

3752
expect(cb).toHaveBeenCalledTimes(1)
53+
3854
const rank = await Mongo.db.collection('ranks').findOne({ parentId: 'parent-id-1', userId: USER1 })
3955
expect(rank).toEqual({ ...rankObj, userId: USER1 })
4056
})
4157

4258
test('Update an existing rank document with a different rank', async () => {
43-
const existingRank = { _id: RANK1, parentId: 'parent-id-1', userId: USER1, round: 1, rank: 'most' }
59+
const existingRank = {
60+
_id: RANK1,
61+
parentId: 'parent-id-1',
62+
userId: USER1,
63+
round: 1,
64+
rank: 'most',
65+
stage: 'pre',
66+
category: 'category-1',
67+
discussionId: 'discussion-1',
68+
}
4469
await Mongo.db.collection('ranks').insertOne(existingRank)
4570

46-
const updatedRankObj = { _id: RANK1, parentId: 'parent-id-1', round: 1, rank: 'least' }
71+
const updatedRankObj = {
72+
_id: RANK1,
73+
parentId: 'parent-id-1',
74+
round: 1,
75+
rank: 'least',
76+
stage: 'pre',
77+
category: 'category-1',
78+
discussionId: 'discussion-1',
79+
}
4780

4881
const cb = jest.fn()
4982

app/socket-apis/rank-why.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Ranks = require('../models/ranks')
44

55
async function validateRankObj(rankObj) {
66
// Basic validation to check required fields
7-
if (!rankObj.parentId || !rankObj.round || !rankObj.rank) {
7+
if (!rankObj.parentId || !rankObj.round || !rankObj.rank || !rankObj.discussionId || !rankObj.stage) {
88
console.log('Validation result: not valid')
99
return false
1010
}

0 commit comments

Comments
 (0)