Skip to content

Commit 4ba301e

Browse files
committed
expect chai
1 parent 26ecc5d commit 4ba301e

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

apps/meteor/tests/unit/app/lib/server/functions/getRoomByNameOrIdWithOptionToJoin.spec.ts

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
132132
errorOnEmpty: true,
133133
});
134134

135-
Sinon.assert.calledOnceWithExactly(RoomsStub.findOneByIdOrName, 'general');
135+
expect(RoomsStub.findOneByIdOrName.calledOnceWithExactly('general')).to.equal(true);
136136
expect(result).to.equal(room);
137137
});
138138

@@ -150,7 +150,7 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
150150
errorOnEmpty: true,
151151
});
152152

153-
Sinon.assert.calledOnceWithExactly(RoomsStub.findOneByIdOrName, 'random');
153+
expect(RoomsStub.findOneByIdOrName.calledOnceWithExactly('random')).to.equal(true);
154154
expect(result).to.equal(room);
155155
});
156156

@@ -265,11 +265,15 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
265265
errorOnEmpty: true,
266266
});
267267

268-
Sinon.assert.calledOnceWithExactly(SubscriptionsStub.findOneByRoomIdAndUserId, 'room6', baseUser._id, { projection: { _id: 1 } });
269-
Sinon.assert.calledOnceWithExactly(RoomServiceStub.join, {
270-
room,
271-
user: baseUser,
272-
});
268+
expect(SubscriptionsStub.findOneByRoomIdAndUserId.calledOnceWithExactly('room6', baseUser._id, { projection: { _id: 1 } })).to.equal(
269+
true,
270+
);
271+
expect(
272+
RoomServiceStub.join.calledOnceWithExactly({
273+
room,
274+
user: baseUser,
275+
}),
276+
).to.equal(true);
273277
expect(result).to.equal(room);
274278
});
275279

@@ -286,8 +290,8 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
286290
errorOnEmpty: true,
287291
});
288292

289-
Sinon.assert.notCalled(SubscriptionsStub.findOneByRoomIdAndUserId);
290-
Sinon.assert.notCalled(RoomServiceStub.join);
293+
expect(SubscriptionsStub.findOneByRoomIdAndUserId.notCalled).to.equal(true);
294+
expect(RoomServiceStub.join.notCalled).to.equal(true);
291295
expect(result).to.equal(room);
292296
});
293297

@@ -304,8 +308,8 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
304308
errorOnEmpty: true,
305309
});
306310

307-
Sinon.assert.notCalled(SubscriptionsStub.findOneByRoomIdAndUserId);
308-
Sinon.assert.notCalled(RoomServiceStub.join);
311+
expect(SubscriptionsStub.findOneByRoomIdAndUserId.notCalled).to.equal(true);
312+
expect(RoomServiceStub.join.notCalled).to.equal(true);
309313
expect(result).to.equal(room);
310314
});
311315

@@ -323,8 +327,10 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
323327
errorOnEmpty: true,
324328
});
325329

326-
Sinon.assert.calledOnceWithExactly(SubscriptionsStub.findOneByRoomIdAndUserId, 'room9', baseUser._id, { projection: { _id: 1 } });
327-
Sinon.assert.notCalled(RoomServiceStub.join);
330+
expect(SubscriptionsStub.findOneByRoomIdAndUserId.calledOnceWithExactly('room9', baseUser._id, { projection: { _id: 1 } })).to.equal(
331+
true,
332+
);
333+
expect(RoomServiceStub.join.notCalled).to.equal(true);
328334
expect(result).to.equal(room);
329335
});
330336
});
@@ -346,10 +352,12 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
346352
errorOnEmpty: true,
347353
});
348354

349-
Sinon.assert.calledOnceWithExactly(UsersStub.findOne, {
350-
$or: [{ _id: 'other' }, { username: 'other' }],
351-
});
352-
Sinon.assert.calledOnce(RoomsStub.findOneDirectRoomContainingAllUserIDs);
355+
expect(
356+
UsersStub.findOne.calledOnceWithExactly({
357+
$or: [{ _id: 'other' }, { username: 'other' }],
358+
}),
359+
).to.equal(true);
360+
expect(RoomsStub.findOneDirectRoomContainingAllUserIDs.calledOnce).to.equal(true);
353361

354362
const callArgs = RoomsStub.findOneDirectRoomContainingAllUserIDs.getCall(0).args[0];
355363
expect(callArgs).to.be.an('array');
@@ -372,9 +380,11 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
372380
errorOnEmpty: true,
373381
});
374382

375-
Sinon.assert.calledOnceWithExactly(UsersStub.findOne, {
376-
$or: [{ _id: 'other2' }, { username: 'other2' }],
377-
});
383+
expect(
384+
UsersStub.findOne.calledOnceWithExactly({
385+
$or: [{ _id: 'other2' }, { username: 'other2' }],
386+
}),
387+
).to.equal(true);
378388
expect(result).to.equal(dmRoom);
379389
});
380390

@@ -393,9 +403,11 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
393403
errorOnEmpty: true,
394404
});
395405

396-
Sinon.assert.calledOnceWithExactly(UsersStub.findOne, {
397-
$or: [{ _id: 'plain' }, { username: 'plain' }],
398-
});
406+
expect(
407+
UsersStub.findOne.calledOnceWithExactly({
408+
$or: [{ _id: 'plain' }, { username: 'plain' }],
409+
}),
410+
).to.equal(true);
399411
expect(result).to.equal(dmRoom);
400412
});
401413
});
@@ -416,8 +428,8 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
416428
errorOnEmpty: true,
417429
});
418430

419-
Sinon.assert.calledOnceWithExactly(UsersStub.findOneById, 'idOnly');
420-
Sinon.assert.notCalled(UsersStub.findOne);
431+
expect(UsersStub.findOneById.calledOnceWithExactly('idOnly')).to.equal(true);
432+
expect(UsersStub.findOne.notCalled).to.equal(true);
421433
expect(result).to.equal(dmRoom);
422434
});
423435

@@ -435,7 +447,7 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
435447
errorOnEmpty: true,
436448
});
437449

438-
Sinon.assert.calledOnceWithExactly(RoomsStub.findOneById, 'idRoom');
450+
expect(RoomsStub.findOneById.calledOnceWithExactly('idRoom')).to.equal(true);
439451
expect(result).to.equal(dmRoom);
440452
});
441453
});
@@ -462,7 +474,7 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
462474

463475
expect(caught).to.be.an('object');
464476
expect(caught.error).to.equal('invalid-channel');
465-
Sinon.assert.notCalled(createDirectMessageStub);
477+
expect(createDirectMessageStub.notCalled).to.equal(true);
466478
});
467479

468480
it('should return null when roomUser not found and errorOnEmpty=false', async () => {
@@ -480,7 +492,7 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
480492
});
481493

482494
expect(result).to.equal(null);
483-
Sinon.assert.notCalled(createDirectMessageStub);
495+
expect(createDirectMessageStub.notCalled).to.equal(true);
484496
});
485497

486498
it('should create a new direct message when roomUser exists and room is not found', async () => {
@@ -498,8 +510,8 @@ describe('getRoomByNameOrIdWithOptionToJoin', () => {
498510
errorOnEmpty: true,
499511
});
500512

501-
Sinon.assert.calledOnceWithExactly(createDirectMessageStub, ['createMe'], baseUser._id);
502-
Sinon.assert.calledWith(RoomsStub.findOneById, 'newDirectRoomId');
513+
expect(createDirectMessageStub.calledOnceWithExactly(['createMe'], baseUser._id)).to.equal(true);
514+
expect(RoomsStub.findOneById.calledWith('newDirectRoomId')).to.equal(true);
503515
expect(result).to.deep.equal({ _id: 'newDirectRoomId', t: 'd' });
504516
});
505517
});

0 commit comments

Comments
 (0)