Skip to content

Commit ba089f3

Browse files
author
Vikas Agarwal
committed
Fixing unit tests which were failing because pubsub object was stubbed in server initialisation
1 parent 0f4be54 commit ba089f3

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/routes/projectUpgrade/create.spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import server from '../../app';
77
import { PROJECT_STATUS } from '../../constants';
88
import models from '../../models';
99
import testUtil from '../../tests/util';
10-
import RabbitMQService from '../../services/rabbitmq';
1110

1211
describe('Project upgrade', () => {
1312
describe('POST /projects/:id/upgrade', () => {
@@ -132,13 +131,17 @@ describe('Project upgrade', () => {
132131
defaultProductTemplateId: defaultProductTemplate.id,
133132
},
134133
};
135-
sinon.stub(RabbitMQService.prototype, 'init', () => {});
136-
sinon.stub(RabbitMQService.prototype, 'publish', () => {});
134+
// restoring the stubs in beforeEach instead of afterEach because these methods are already stubbed
135+
server.services.pubsub.init.restore();
136+
server.services.pubsub.publish.restore();
137+
sinon.stub(server.services.pubsub, 'init', () => {});
138+
sinon.stub(server.services.pubsub, 'publish', () => {});
137139
});
138140

139141
afterEach(async () => {
140-
RabbitMQService.prototype.init.restore();
141-
RabbitMQService.prototype.publish.restore();
142+
// restoring the stubs in beforeEach instead of afterEach because these methods are already stubbed
143+
// server.services.pubsub.init.restore();
144+
// server.services.pubsub.publish.restore();
142145
await testUtil.clearDb();
143146
});
144147

src/tests/serviceMocks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import elasticsearch from 'elasticsearch';
1010
module.exports = (app) => {
1111
_.assign(app.services, {
1212
pubsub: {
13+
init: () => {},
1314
publish: () => {},
1415
},
1516
es: new elasticsearch.Client(_.cloneDeep(config.elasticsearchConfig)),
1617
});
18+
sinon.stub(app.services.pubsub, 'init', () => Promise.resolve(true));
1719
sinon.stub(app.services.pubsub, 'publish', () => Promise.resolve(true));
1820
};

0 commit comments

Comments
 (0)