Skip to content

Commit

Permalink
♻️ refactor: Rewrite tests to use assert.strictEqual.
Browse files Browse the repository at this point in the history
Instead of `assert.equal`. Fixes #980.
  • Loading branch information
make-github-pseudonymous-again committed May 22, 2024
1 parent 0f71df1 commit d4cbde9
Show file tree
Hide file tree
Showing 37 changed files with 308 additions and 269 deletions.
10 changes: 5 additions & 5 deletions imports/_test/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const _xorClient = (
b: Uint8ClampedArray,
): Uint8ClampedArray => {
const n = a.length;
assert.equal(b.length, n);
assert.strictEqual(b.length, n);
const delta = new Uint8ClampedArray(n);
for (let i = 0; i < n; ++i) {
// eslint-disable-next-line no-bitwise
Expand Down Expand Up @@ -97,25 +97,25 @@ const _assertSameDimensions = async (a: Sharp, b: Sharp): Promise<void> => {
hasAlpha: bHasAlpha,
} = await b.metadata();

assert.equal(
assert.strictEqual(
aWidth,
bWidth,
`Images have different widths: ${aWidth} !== ${bWidth}`,
);

assert.equal(
assert.strictEqual(
aHeight,
bHeight,
`Images have different heights: ${aHeight} !== ${bHeight}`,
);

assert.equal(
assert.strictEqual(
aChannels,
bChannels,
`Images have different number of channels: ${aChannels} !== ${bChannels}`,
);

assert.equal(
assert.strictEqual(
aHasAlpha,
bHasAlpha,
`Images have different alpha channel settings: ${aHasAlpha} !== ${bHasAlpha}`,
Expand Down
24 changes: 12 additions & 12 deletions imports/api/endpoint/allergies/changeColor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ server(__filename, () => {

const {upsertedId: allergyId} = await newAllergy({userId});

assert.equal(await Allergies.find({}).countAsync(), 1);
assert.equal(await Allergies.find({_id: allergyId}).countAsync(), 1);
assert.strictEqual(await Allergies.find({}).countAsync(), 1);
assert.strictEqual(await Allergies.find({_id: allergyId}).countAsync(), 1);
const {color} = await findOneOrThrow(Allergies, {_id: allergyId});
assert.equal(color, undefined);
assert.strictEqual(color, undefined);

const expected = '#fff';

await invoke(changeAllergyColor, {userId}, [allergyId, expected]);

assert.equal(await Allergies.find({}).countAsync(), 1);
assert.strictEqual(await Allergies.find({}).countAsync(), 1);

assert.deepInclude(await Allergies.findOneAsync({_id: allergyId}), {
color: expected,
Expand All @@ -42,11 +42,11 @@ server(__filename, () => {

const {upsertedId: allergyId} = await newAllergy({userId});

assert.equal(await Allergies.find({}).countAsync(), 1);
assert.equal(await Allergies.find({_id: allergyId}).countAsync(), 1);
assert.strictEqual(await Allergies.find({}).countAsync(), 1);
assert.strictEqual(await Allergies.find({_id: allergyId}).countAsync(), 1);

const {color} = await findOneOrThrow(Allergies, {_id: allergyId});
assert.equal(color, undefined);
assert.strictEqual(color, undefined);

const expected = '#fff';

Expand All @@ -59,7 +59,7 @@ server(__filename, () => {
/not-authorized/,
);

assert.equal(await Allergies.find({}).countAsync(), 1);
assert.strictEqual(await Allergies.find({}).countAsync(), 1);

assert.notDeepInclude(await Allergies.findOneAsync({_id: allergyId}), {
color: expected,
Expand All @@ -71,10 +71,10 @@ server(__filename, () => {

const {upsertedId: allergyId} = await newAllergy({userId});

assert.equal(await Allergies.find({}).countAsync(), 1);
assert.equal(await Allergies.find({_id: allergyId}).countAsync(), 1);
assert.strictEqual(await Allergies.find({}).countAsync(), 1);
assert.strictEqual(await Allergies.find({_id: allergyId}).countAsync(), 1);
const {color} = await findOneOrThrow(Allergies, {_id: allergyId});
assert.equal(color, undefined);
assert.strictEqual(color, undefined);

const expected = '#fff';

Expand All @@ -87,7 +87,7 @@ server(__filename, () => {
/not-found/,
);

assert.equal(await Allergies.find({}).countAsync(), 1);
assert.strictEqual(await Allergies.find({}).countAsync(), 1);

assert.notDeepInclude(await Allergies.findOneAsync({_id: allergyId}), {
color: expected,
Expand Down
9 changes: 6 additions & 3 deletions imports/api/endpoint/appointments/beginConsultation.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ server(__filename, () => {

const appointmentId = await newAppointment({userId});

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.equal(await Appointments.find({_id: appointmentId}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(
await Appointments.find({_id: appointmentId}).countAsync(),
1,
);

await invoke(appointmentsBeginConsultation, {userId}, [appointmentId]);

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);

assert.deepInclude(await Appointments.findOneAsync({_id: appointmentId}), {
isDone: true,
Expand Down
9 changes: 6 additions & 3 deletions imports/api/endpoint/appointments/cancel.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ server(__filename, () => {

const appointmentId = await newAppointment({userId});

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.equal(await Appointments.find({_id: appointmentId}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(
await Appointments.find({_id: appointmentId}).countAsync(),
1,
);

await invoke(appointmentsCancel, {userId}, [appointmentId, '', '']);

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);

assert.deepInclude(await Appointments.findOneAsync({_id: appointmentId}), {
isCancelled: true,
Expand Down
9 changes: 6 additions & 3 deletions imports/api/endpoint/appointments/remove.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ server(__filename, () => {

const appointmentId = await newAppointment({userId});

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.equal(await Appointments.find({_id: appointmentId}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(
await Appointments.find({_id: appointmentId}).countAsync(),
1,
);

await invoke(appointmentsRemove, {userId}, [appointmentId]);

assert.equal(await Appointments.find({}).countAsync(), 0);
assert.strictEqual(await Appointments.find({}).countAsync(), 0);
});

it("cannot remove other user's consultation", async () => {
Expand Down
4 changes: 2 additions & 2 deletions imports/api/endpoint/appointments/reschedule.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ server(__filename, () => {

const before = await findOneOrThrow(Appointments);

assert.equal(before._id, appointmentId);
assert.strictEqual(before._id, appointmentId);
assert.sameDeepMembers(
dropIds(await Availability.find().fetchAsync()),
expected(before),
Expand All @@ -101,7 +101,7 @@ server(__filename, () => {

const after = await findOneOrThrow(Appointments);

assert.equal(after._id, appointmentId);
assert.strictEqual(after._id, appointmentId);
assert.sameDeepMembers(
dropIds(await Availability.find().fetchAsync()),
expected(after),
Expand Down
2 changes: 1 addition & 1 deletion imports/api/endpoint/appointments/schedule.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ server(__filename, () => {
it('creates associated patient', async () => {
const userId = randomUserId();

assert.equal(await Patients.findOneAsync(), undefined);
assert.strictEqual(await Patients.findOneAsync(), undefined);

const patientFields = {
firstname: 'Jane',
Expand Down
11 changes: 7 additions & 4 deletions imports/api/endpoint/appointments/uncancel.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ server(__filename, () => {

const appointmentId = await newAppointment({userId});

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.equal(await Appointments.find({_id: appointmentId}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(
await Appointments.find({_id: appointmentId}).countAsync(),
1,
);

await invoke(appointmentsCancel, {userId}, [appointmentId, '', '']);

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);

assert.deepInclude(await Appointments.findOneAsync({_id: appointmentId}), {
isCancelled: true,
});

await invoke(appointmentsUncancel, {userId}, [appointmentId]);

assert.equal(await Appointments.find({}).countAsync(), 1);
assert.strictEqual(await Appointments.find({}).countAsync(), 1);

assert.deepInclude(await Appointments.findOneAsync({_id: appointmentId}), {
isCancelled: false,
Expand Down
2 changes: 1 addition & 1 deletion imports/api/endpoint/books/csv.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ server(__filename, () => {
maxRows,
]);

assert.equal(result, expected);
assert.strictEqual(result, expected);
});

it('cannot download csv file if not logged in', async () => {
Expand Down
10 changes: 5 additions & 5 deletions imports/api/endpoint/books/rename.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ server(__filename, () => {
consultationAId,
);

assert.equal(updatedBookNumber, newBookNumber);
assert.strictEqual(updatedBookNumber, newBookNumber);
});

it('renaming a book updates its consultations', async () => {
Expand Down Expand Up @@ -95,7 +95,7 @@ server(__filename, () => {
]) {
// eslint-disable-next-line no-await-in-loop
const {book} = await findOneOrThrow(Consultations, consultationId);
assert.equal(book, newBookNumber);
assert.strictEqual(book, newBookNumber);
}
});

Expand Down Expand Up @@ -177,19 +177,19 @@ server(__filename, () => {
]) {
// eslint-disable-next-line no-await-in-loop
const {book} = await findOneOrThrow(Consultations, consultationId);
assert.equal(book, newBookNumber);
assert.strictEqual(book, newBookNumber);
}

for (const consultationId of [consultationDId]) {
// eslint-disable-next-line no-await-in-loop
const {book} = await findOneOrThrow(Consultations, consultationId);
assert.equal(book, oldBookNumber);
assert.strictEqual(book, oldBookNumber);
}

for (const consultationId of [consultationEId, consultationFId]) {
// eslint-disable-next-line no-await-in-loop
const {book} = await findOneOrThrow(Consultations, consultationId);
assert.equal(book, `${oldBookNumber}x`);
assert.strictEqual(book, `${oldBookNumber}x`);
}
});
});
28 changes: 14 additions & 14 deletions imports/api/endpoint/consultations/attach.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ server(__filename, () => {
const {_id: uploadAId} = await newUpload({userId});
const {_id: uploadBId} = await newUpload({userId});

assert.equal(await Patients.find().countAsync(), 2);
assert.equal(
assert.strictEqual(await Patients.find().countAsync(), 2);
assert.strictEqual(
await Consultations.find({patientId: patientAId}).countAsync(),
1,
);
assert.equal(
assert.strictEqual(
await Consultations.find({patientId: patientBId}).countAsync(),
1,
);
assert.equal(await Attachments.find().countAsync(), 2);
assert.strictEqual(await Attachments.find().countAsync(), 2);

await invoke(consultationsAttach, {userId}, [consultationAId, uploadAId]);

assert.equal(await Patients.find().countAsync(), 2);
assert.equal(
assert.strictEqual(await Patients.find().countAsync(), 2);
assert.strictEqual(
await Consultations.find({patientId: patientAId}).countAsync(),
1,
);
assert.equal(
assert.strictEqual(
await Consultations.find({patientId: patientBId}).countAsync(),
1,
);
assert.equal(await Attachments.find().countAsync(), 2);
assert.strictEqual(await Attachments.find().countAsync(), 2);

assert.deepInclude(
await Attachments.findOneAsync({
Expand All @@ -67,7 +67,7 @@ server(__filename, () => {
},
);

assert.equal(
assert.strictEqual(
await Attachments.findOneAsync({
'meta.attachedToConsultations': consultationBId,
}),
Expand All @@ -76,16 +76,16 @@ server(__filename, () => {

await invoke(consultationsAttach, {userId}, [consultationBId, uploadBId]);

assert.equal(await Patients.find().countAsync(), 2);
assert.equal(
assert.strictEqual(await Patients.find().countAsync(), 2);
assert.strictEqual(
await Consultations.find({patientId: patientAId}).countAsync(),
1,
);
assert.equal(
assert.strictEqual(
await Consultations.find({patientId: patientBId}).countAsync(),
1,
);
assert.equal(await Attachments.find().countAsync(), 2);
assert.strictEqual(await Attachments.find().countAsync(), 2);

assert.deepInclude(
await Attachments.findOneAsync({
Expand Down Expand Up @@ -118,7 +118,7 @@ server(__filename, () => {

const {_id: uploadId} = await newUpload({userId});

assert.equal(
assert.strictEqual(
await Attachments.findOneAsync({
'meta.attachedToConsultations': consultationId,
}),
Expand Down
Loading

0 comments on commit d4cbde9

Please sign in to comment.