Skip to content

Commit 5b804f5

Browse files
tests(microservices) fix broken options unit tests
1 parent b348920 commit 5b804f5

5 files changed

Lines changed: 62 additions & 48 deletions

File tree

packages/microservices/test/client/client-grpc.spec.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@ describe('ClientGrpcProxy', () => {
1717

1818
beforeEach(() => {
1919
client = new ClientGrpcProxy({
20-
options: {
21-
protoPath: join(__dirname, './test.proto'),
22-
package: 'test',
23-
},
20+
protoPath: join(__dirname, './test.proto'),
21+
package: 'test',
2422
});
2523
});
2624

2725
describe('getService', () => {
2826
describe('when "grpcClient[name]" is nil', () => {
2927
it('should throw "InvalidGrpcServiceException"', () => {
3028
(client as any).grpcClient = {};
31-
expect(() => client.getService('test')).to.throw(InvalidGrpcServiceException);
29+
expect(() => client.getService('test')).to.throw(
30+
InvalidGrpcServiceException,
31+
);
3232
});
3333
});
3434
describe('when "grpcClient[name]" is not nil', () => {
3535
it('should create grpcService', () => {
3636
(client as any).grpcClient = {
3737
test: GrpcService,
3838
};
39-
expect(() => client.getService('test')).to.not.throw(InvalidGrpcServiceException);
39+
expect(() => client.getService('test')).to.not.throw(
40+
InvalidGrpcServiceException,
41+
);
4042
});
4143
});
4244
});
@@ -90,11 +92,11 @@ describe('ClientGrpcProxy', () => {
9092
const methodName = 'm';
9193
type EvtCallback = (...args: any[]) => void;
9294
let callMock: {
93-
on: (type: string, fn: EvtCallback) => void,
94-
cancel: sinon.SinonSpy,
95-
finished: boolean,
96-
destroy: sinon.SinonSpy,
97-
removeAllListeners: sinon.SinonSpy,
95+
on: (type: string, fn: EvtCallback) => void;
96+
cancel: sinon.SinonSpy;
97+
finished: boolean;
98+
destroy: sinon.SinonSpy;
99+
removeAllListeners: sinon.SinonSpy;
98100
};
99101
let eventCallbacks: { [type: string]: EvtCallback };
100102
let obj;
@@ -110,7 +112,7 @@ describe('ClientGrpcProxy', () => {
110112
completeSpy.reset();
111113
eventCallbacks = {};
112114
callMock = {
113-
on: (type, fn) => eventCallbacks[type] = fn,
115+
on: (type, fn) => (eventCallbacks[type] = fn),
114116
cancel: sinon.spy(),
115117
finished: false,
116118
destroy: sinon.spy(),
@@ -149,9 +151,11 @@ describe('ClientGrpcProxy', () => {
149151
eventCallbacks.data('c');
150152

151153
expect(callMock.cancel.called, 'should call call.cancel()').to.be.true;
152-
expect(callMock.destroy.called, 'should call call.destroy()').to.be.true;
154+
expect(callMock.destroy.called, 'should call call.destroy()').to.be
155+
.true;
153156
expect(dataSpy.args).to.eql([['a'], ['b']]);
154-
expect(errorSpy.called, 'should not error if client canceled').to.be.false;
157+
expect(errorSpy.called, 'should not error if client canceled').to.be
158+
.false;
155159
});
156160
});
157161
});
@@ -163,7 +167,7 @@ describe('ClientGrpcProxy', () => {
163167
});
164168
describe('on subscribe', () => {
165169
const methodName = 'm';
166-
const obj = { [methodName]: (callback) => callback(null, {}) };
170+
const obj = { [methodName]: callback => callback(null, {}) };
167171

168172
let stream$: Observable<any>;
169173

@@ -184,7 +188,9 @@ describe('ClientGrpcProxy', () => {
184188
describe('when package does not exist', () => {
185189
it('should throw "InvalidGrpcPackageException"', () => {
186190
sinon.stub(client, 'lookupPackage').callsFake(() => null);
187-
expect(() => client.createClient()).to.throw(InvalidGrpcPackageException);
191+
expect(() => client.createClient()).to.throw(
192+
InvalidGrpcPackageException,
193+
);
188194
});
189195
});
190196
});
@@ -195,7 +201,9 @@ describe('ClientGrpcProxy', () => {
195201
sinon.stub(client, 'getOptionsProp').callsFake(() => {
196202
throw new Error();
197203
});
198-
expect(() => client.loadProto()).to.throws(InvalidProtoDefinitionException);
204+
expect(() => client.loadProto()).to.throws(
205+
InvalidProtoDefinitionException,
206+
);
199207
});
200208
});
201209
});

packages/microservices/test/client/client-redis.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ describe('ClientRedis', () => {
301301
});
302302
describe('otherwise', () => {
303303
it('should return delay (ms)', () => {
304-
(client as any).options.options = {};
304+
(client as any).options = {};
305305
(client as any).isExplicitlyTerminated = false;
306-
(client as any).options.options.retryAttempts = 3;
307-
(client as any).options.options.retryDelay = 3;
306+
(client as any).options.retryAttempts = 3;
307+
(client as any).options.retryDelay = 3;
308308
const result = client.createRetryStrategy(
309309
{ attempt: 2 } as any,
310310
subject,
311311
);
312-
expect(result).to.be.eql((client as any).options.options.retryDelay);
312+
expect(result).to.be.eql((client as any).options.retryDelay);
313313
});
314314
});
315315
});

packages/microservices/test/server/server-grpc.spec.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ describe('ServerGrpc', () => {
99
let server: ServerGrpc;
1010
beforeEach(() => {
1111
server = new ServerGrpc({
12-
options: {
13-
protoPath: join(__dirname, './test.proto'),
14-
package: 'test',
15-
},
12+
protoPath: join(__dirname, './test.proto'),
13+
package: 'test',
1614
} as any);
1715
});
1816

@@ -167,14 +165,19 @@ describe('ServerGrpc', () => {
167165
it(`should close the result observable when receiving an 'cancelled' event from the client`, async () => {
168166
let cancelCb: () => void;
169167
const call = {
170-
write: sinon.stub().onSecondCall().callsFake(() => cancelCb()),
168+
write: sinon
169+
.stub()
170+
.onSecondCall()
171+
.callsFake(() => cancelCb()),
171172
end: sinon.spy(),
172-
addListener: (name, cb) => cancelCb = cb,
173+
addListener: (name, cb) => (cancelCb = cb),
173174
removeListener: sinon.spy(),
174175
};
175176
const result$ = of(1, 2, 3);
176177
const callback = sinon.spy();
177-
const native = sinon.stub().returns(new Promise((resolve, reject) => resolve(result$)));
178+
const native = sinon
179+
.stub()
180+
.returns(new Promise((resolve, reject) => resolve(result$)));
178181

179182
await server.createStreamServiceMethod(native)(call, callback);
180183
expect(call.write.calledTwice).to.be.true;

packages/microservices/test/server/server-redis.spec.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import * as sinon from 'sinon';
21
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
33
import { NO_PATTERN_MESSAGE } from '../../constants';
44
import { ServerRedis } from '../../server/server-redis';
5-
import { Observable } from 'rxjs';
65

76
describe('ServerRedis', () => {
87
let server: ServerRedis;
@@ -23,7 +22,7 @@ describe('ServerRedis', () => {
2322
.stub(server, 'createRedisClient')
2423
.callsFake(() => client);
2524

26-
server.listen(null);
25+
server.listen(null);
2726
});
2827
it('should bind "error" event to handler', () => {
2928
expect(onSpy.getCall(0).args[0]).to.be.equal('error');
@@ -116,7 +115,7 @@ describe('ServerRedis', () => {
116115
describe('getPublisher', () => {
117116
let publisherSpy: sinon.SinonSpy;
118117
let pub, publisher;
119-
118+
120119
const id = '1';
121120
const pattern = 'test';
122121

@@ -133,8 +132,12 @@ describe('ServerRedis', () => {
133132
it(`should call "publish" with expected arguments`, () => {
134133
const respond = 'test';
135134
publisher({ respond, id });
136-
expect(publisherSpy.calledWith(`${pattern}_res`, JSON.stringify({ respond, id })))
137-
.to.be.true;
135+
expect(
136+
publisherSpy.calledWith(
137+
`${pattern}_res`,
138+
JSON.stringify({ respond, id }),
139+
),
140+
).to.be.true;
138141
});
139142
});
140143
describe('deserialize', () => {
@@ -198,21 +201,21 @@ describe('ServerRedis', () => {
198201
describe('when ECONNREFUSED', () => {
199202
it('should call logger', () => {
200203
const loggerErrorSpy = sinon.spy((server as any).logger, 'error');
201-
const result = server.createRetryStrategy(
202-
{ error: { code: 'ECONNREFUSED' } } as any,
203-
);
204+
const result = server.createRetryStrategy({
205+
error: { code: 'ECONNREFUSED' },
206+
} as any);
204207
expect(loggerErrorSpy.called).to.be.true;
205208
});
206209
});
207210
describe('otherwise', () => {
208211
it('should return delay (ms)', () => {
209-
(server as any).options.options = {};
212+
(server as any).options = {};
210213
(server as any).isExplicitlyTerminated = false;
211-
(server as any).options.options.retryAttempts = 3;
212-
(server as any).options.options.retryDelay = 3;
214+
(server as any).options.retryAttempts = 3;
215+
(server as any).options.retryDelay = 3;
213216
const result = server.createRetryStrategy({ attempt: 2 } as any);
214-
expect(result).to.be.eql((server as any).options.options.retryDelay);
217+
expect(result).to.be.eql((server as any).options.retryDelay);
215218
});
216-
})
219+
});
217220
});
218221
});

packages/microservices/test/server/server-tcp.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as sinon from 'sinon';
21
import { expect } from 'chai';
3-
import { ServerTCP } from '../../server/server-tcp';
2+
import * as sinon from 'sinon';
43
import { NO_PATTERN_MESSAGE } from '../../constants';
4+
import { ServerTCP } from '../../server/server-tcp';
55

66
describe('ServerTCP', () => {
77
let server: ServerTCP;
@@ -100,14 +100,14 @@ describe('ServerTCP', () => {
100100
});
101101
describe('otherwise', () => {
102102
it('should return delay (ms)', () => {
103-
(server as any).options.options = {};
103+
(server as any).options = {};
104104
(server as any).isExplicitlyTerminated = false;
105-
(server as any).options.options.retryAttempts = 3;
105+
(server as any).options.retryAttempts = 3;
106106
(server as any).retryAttemptsCount = 2;
107-
(server as any).options.options.retryDelay = 3;
107+
(server as any).options.retryDelay = 3;
108108
const result = server.handleClose();
109109
expect(result).to.be.not.undefined;
110110
});
111-
})
111+
});
112112
});
113113
});

0 commit comments

Comments
 (0)