Skip to content

Commit

Permalink
refactor: Favor use of spies vs. done callback
Browse files Browse the repository at this point in the history
Replaced uses of done callback with async tests and sinon spies for verifing results.  Solves with the done callback where assertions would prevent done from being called and the test would report a timeout error vs the proper test failure.
  • Loading branch information
jrassa committed Oct 2, 2023
1 parent a0e2df6 commit 4b09f1b
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 384 deletions.
4 changes: 2 additions & 2 deletions src/app/common/util.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Utils:', () => {
date: { $date: '2015-07-01T00:00:00.000Z' }
};

const output = utilService.toMongoose(input) as any;
const output = utilService.toMongoose(input) as Record<string, unknown>;
(typeof output.hello).should.equal('object');
output.hello.there.should.equal('you are');
Array.isArray(output.hello.when).should.equal(true);
Expand All @@ -44,7 +44,7 @@ describe('Utils:', () => {
obj: { $obj: '000000000000000000000001' }
};

const output = utilService.toMongoose(input) as any;
const output = utilService.toMongoose(input) as Record<string, unknown>;
(typeof output.hello).should.equal('object');
output.hello.there.should.equal('you are');
Array.isArray(output.hello.when).should.equal(true);
Expand Down
9 changes: 3 additions & 6 deletions src/app/core/feedback/feedback.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { assert, createSandbox, spy, stub } from 'sinon';
import { assert, createSandbox } from 'sinon';

import * as feedbackController from './feedback.controller';
import { Feedback } from './feedback.model';
import feedbackService from './feedback.service';
import { auditService, logger } from '../../../dependencies';
import { getResponseSpy } from '../../../spec/helpers';
import { User } from '../user/user.model';

describe('Feedback Controller2', () => {
Expand All @@ -12,11 +13,7 @@ describe('Feedback Controller2', () => {

beforeEach(() => {
sandbox = createSandbox();
res = {
json: spy(),
status: stub()
};
res.status.returns(res);
res = getResponseSpy();
sandbox.stub(logger, 'error').returns();
});

Expand Down
6 changes: 1 addition & 5 deletions src/app/core/feedback/feedback.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { FilterQuery } from 'mongoose';

import { FeedbackDocument } from './feedback.model';
import feedbackService from './feedback.service';
import {
auditService,
config,
utilService as util
} from '../../../dependencies';
import { auditService, config } from '../../../dependencies';
import { Callbacks } from '../export/callbacks';
import * as exportConfigController from '../export/export-config.controller';
import { IExportConfig } from '../export/export-config.model';
Expand Down
10 changes: 3 additions & 7 deletions src/app/core/teams/teams.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Request } from 'express';
import should from 'should';
import { assert, createSandbox, match, spy, stub } from 'sinon';
import { assert, createSandbox, match, stub } from 'sinon';

import { Team, TeamDocument } from './team.model';
import * as teamsController from './teams.controller';
import teamsService from './teams.service';
import { auditService, logger } from '../../../dependencies';
import { getResponseSpy } from '../../../spec/helpers';
import { User, UserDocument } from '../user/user.model';
import userService from '../user/user.service';

Expand All @@ -18,12 +19,7 @@ describe('Teams Controller:', () => {

beforeEach(() => {
sandbox = createSandbox();
res = {
json: spy(),
end: spy(),
status: stub()
};
res.status.returns(res);
res = getResponseSpy();
});

afterEach(() => {
Expand Down
9 changes: 3 additions & 6 deletions src/app/core/user/admin/user-admin.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { assert, createSandbox, spy, stub } from 'sinon';
import { assert, createSandbox } from 'sinon';

import * as userAdminController from './user-admin.controller';
import { auditService, config } from '../../../../dependencies';
import { getResponseSpy } from '../../../../spec/helpers';
import userEmailService from '../user-email.service';
import { User } from '../user.model';
import userService from '../user.service';
Expand Down Expand Up @@ -29,11 +30,7 @@ describe('User Admin Controller:', () => {

beforeEach(() => {
sandbox = createSandbox();
res = {
json: spy(),
status: stub()
};
res.status.returns(res);
res = getResponseSpy();
});

afterEach(() => {
Expand Down
Loading

0 comments on commit 4b09f1b

Please sign in to comment.