mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
build: use strict null checks part 4
This commit is contained in:
@@ -44,7 +44,7 @@ export async function callModuleBootstrapHook(module: Module): Promise<any> {
|
|||||||
const providers = module.getNonAliasProviders();
|
const providers = module.getNonAliasProviders();
|
||||||
// Module (class) instance is the first element of the providers array
|
// Module (class) instance is the first element of the providers array
|
||||||
// Lifecycle hook has to be called once all classes are properly initialized
|
// Lifecycle hook has to be called once all classes are properly initialized
|
||||||
const [_, moduleClassHost] = providers.shift();
|
const [_, moduleClassHost] = providers.shift()!;
|
||||||
const instances = [
|
const instances = [
|
||||||
...module.controllers,
|
...module.controllers,
|
||||||
...providers,
|
...providers,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export async function callAppShutdownHook(
|
|||||||
const providers = module.getNonAliasProviders();
|
const providers = module.getNonAliasProviders();
|
||||||
// Module (class) instance is the first element of the providers array
|
// Module (class) instance is the first element of the providers array
|
||||||
// Lifecycle hook has to be called once all classes are properly initialized
|
// Lifecycle hook has to be called once all classes are properly initialized
|
||||||
const [_, moduleClassHost] = providers.shift();
|
const [_, moduleClassHost] = providers.shift()!;
|
||||||
const instances = [
|
const instances = [
|
||||||
...module.controllers,
|
...module.controllers,
|
||||||
...providers,
|
...providers,
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export async function callModuleDestroyHook(module: Module): Promise<any> {
|
|||||||
const providers = module.getNonAliasProviders();
|
const providers = module.getNonAliasProviders();
|
||||||
// Module (class) instance is the first element of the providers array
|
// Module (class) instance is the first element of the providers array
|
||||||
// Lifecycle hook has to be called once all classes are properly destroyed
|
// Lifecycle hook has to be called once all classes are properly destroyed
|
||||||
const [_, moduleClassHost] = providers.shift();
|
const [_, moduleClassHost] = providers.shift()!;
|
||||||
const instances = [
|
const instances = [
|
||||||
...module.controllers,
|
...module.controllers,
|
||||||
...providers,
|
...providers,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export async function callModuleInitHook(module: Module): Promise<void> {
|
|||||||
const providers = module.getNonAliasProviders();
|
const providers = module.getNonAliasProviders();
|
||||||
// Module (class) instance is the first element of the providers array
|
// Module (class) instance is the first element of the providers array
|
||||||
// Lifecycle hook has to be called once all classes are properly initialized
|
// Lifecycle hook has to be called once all classes are properly initialized
|
||||||
const [_, moduleClassHost] = providers.shift();
|
const [_, moduleClassHost] = providers.shift()!;
|
||||||
const instances = [
|
const instances = [
|
||||||
...module.controllers,
|
...module.controllers,
|
||||||
...providers,
|
...providers,
|
||||||
|
|||||||
@@ -365,7 +365,7 @@ describe('ClientGrpcProxy', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
handler(null, 'a');
|
handler!(null, 'a');
|
||||||
|
|
||||||
expect(dataSpy.called).to.be.false;
|
expect(dataSpy.called).to.be.false;
|
||||||
expect(errorSpy.called).to.be.false;
|
expect(errorSpy.called).to.be.false;
|
||||||
@@ -416,7 +416,7 @@ describe('ClientGrpcProxy', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
handler(null, 'a');
|
handler!(null, 'a');
|
||||||
|
|
||||||
expect(dataSpy.called).to.be.false;
|
expect(dataSpy.called).to.be.false;
|
||||||
expect(writeSpy.called).to.be.true;
|
expect(writeSpy.called).to.be.true;
|
||||||
@@ -476,7 +476,7 @@ describe('ClientGrpcProxy', () => {
|
|||||||
|
|
||||||
describe('publish', () => {
|
describe('publish', () => {
|
||||||
it('should throw exception', () => {
|
it('should throw exception', () => {
|
||||||
expect(() => client['publish'](null, null)).to.throws(Error);
|
expect(() => client['publish'](null, null!)).to.throws(Error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -504,7 +504,7 @@ describe('ClientGrpcProxy', () => {
|
|||||||
it('should return root package in case package name is not defined', () => {
|
it('should return root package in case package name is not defined', () => {
|
||||||
const root = {};
|
const root = {};
|
||||||
|
|
||||||
expect(client.lookupPackage(root, undefined)).to.be.equal(root);
|
expect(client.lookupPackage(root, undefined!)).to.be.equal(root);
|
||||||
expect(client.lookupPackage(root, '')).to.be.equal(root);
|
expect(client.lookupPackage(root, '')).to.be.equal(root);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -647,7 +647,7 @@ describe('ClientKafka', () => {
|
|||||||
|
|
||||||
it('should throw error when the topic is not being consumed', () => {
|
it('should throw error when the topic is not being consumed', () => {
|
||||||
client['consumerAssignments'] = {
|
client['consumerAssignments'] = {
|
||||||
[topic]: undefined,
|
[topic]: undefined!,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(() => client['getReplyTopicPartition'](replyTopic)).to.throw(
|
expect(() => client['getReplyTopicPartition'](replyTopic)).to.throw(
|
||||||
@@ -687,7 +687,7 @@ describe('ClientKafka', () => {
|
|||||||
assignPacketIdStub = sinon
|
assignPacketIdStub = sinon
|
||||||
.stub(client as any, 'assignPacketId')
|
.stub(client as any, 'assignPacketId')
|
||||||
.callsFake(packet =>
|
.callsFake(packet =>
|
||||||
Object.assign(packet, {
|
Object.assign(packet!, {
|
||||||
id: correlationId,
|
id: correlationId,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe('ClientMqtt', () => {
|
|||||||
connectSpy = sinon.stub(client, 'connect');
|
connectSpy = sinon.stub(client, 'connect');
|
||||||
assignStub = sinon
|
assignStub = sinon
|
||||||
.stub(client, 'assignPacketId' as any)
|
.stub(client, 'assignPacketId' as any)
|
||||||
.callsFake(packet => Object.assign(packet, { id }));
|
.callsFake(packet => Object.assign(packet!, { id }));
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
connectSpy.restore();
|
connectSpy.restore();
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ describe('ClientNats', () => {
|
|||||||
callback = sinon.spy();
|
callback = sinon.spy();
|
||||||
assignStub = sinon
|
assignStub = sinon
|
||||||
.stub(client, 'assignPacketId' as any)
|
.stub(client, 'assignPacketId' as any)
|
||||||
.callsFake(packet => Object.assign(packet, { id }));
|
.callsFake(packet => Object.assign(packet!, { id }));
|
||||||
|
|
||||||
subscription = client['publish'](msg, callback);
|
subscription = client['publish'](msg, callback);
|
||||||
subscription();
|
subscription();
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ describe('ClientRedis', () => {
|
|||||||
callback = sinon.spy();
|
callback = sinon.spy();
|
||||||
assignStub = sinon
|
assignStub = sinon
|
||||||
.stub(client, 'assignPacketId' as any)
|
.stub(client, 'assignPacketId' as any)
|
||||||
.callsFake(packet => Object.assign(packet, { id }));
|
.callsFake(packet => Object.assign(packet!, { id }));
|
||||||
|
|
||||||
getReplyPatternStub = sinon
|
getReplyPatternStub = sinon
|
||||||
.stub(client, 'getReplyPattern')
|
.stub(client, 'getReplyPattern')
|
||||||
@@ -289,9 +289,9 @@ describe('ClientRedis', () => {
|
|||||||
describe('getClientOptions', () => {
|
describe('getClientOptions', () => {
|
||||||
it('should return options object with "retryStrategy" and call "createRetryStrategy"', () => {
|
it('should return options object with "retryStrategy" and call "createRetryStrategy"', () => {
|
||||||
const createSpy = sinon.spy(client, 'createRetryStrategy');
|
const createSpy = sinon.spy(client, 'createRetryStrategy');
|
||||||
const { retryStrategy } = client.getClientOptions();
|
const { retryStrategy } = client.getClientOptions()!;
|
||||||
try {
|
try {
|
||||||
retryStrategy({} as any);
|
retryStrategy!({} as any);
|
||||||
} catch {
|
} catch {
|
||||||
// No empty
|
// No empty
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ describe('ClientRMQ', function () {
|
|||||||
assertQueue: sinon.spy(() => ({})),
|
assertQueue: sinon.spy(() => ({})),
|
||||||
prefetch: sinon.spy(),
|
prefetch: sinon.spy(),
|
||||||
};
|
};
|
||||||
consumeStub = sinon.stub(client, 'consumeChannel').callsFake(() => null);
|
consumeStub = sinon.stub(client, 'consumeChannel').callsFake(() => null!);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
consumeStub.restore();
|
consumeStub.restore();
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ describe('ExceptionFiltersContext', () => {
|
|||||||
const filter = exceptionFilter.create(
|
const filter = exceptionFilter.create(
|
||||||
new EmptyMetadata(),
|
new EmptyMetadata(),
|
||||||
() => ({}) as any,
|
() => ({}) as any,
|
||||||
undefined,
|
undefined!,
|
||||||
);
|
);
|
||||||
expect((filter as any).filters).to.be.empty;
|
expect((filter as any).filters).to.be.empty;
|
||||||
});
|
});
|
||||||
@@ -47,7 +47,7 @@ describe('ExceptionFiltersContext', () => {
|
|||||||
const filter = exceptionFilter.create(
|
const filter = exceptionFilter.create(
|
||||||
new WithMetadata(),
|
new WithMetadata(),
|
||||||
() => ({}) as any,
|
() => ({}) as any,
|
||||||
undefined,
|
undefined!,
|
||||||
);
|
);
|
||||||
expect((filter as any).filters).to.not.be.empty;
|
expect((filter as any).filters).to.not.be.empty;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ describe('RpcContextCreator', () => {
|
|||||||
|
|
||||||
describe('createGuardsFn', () => {
|
describe('createGuardsFn', () => {
|
||||||
it('should throw exception when "tryActivate" returns false', () => {
|
it('should throw exception when "tryActivate" returns false', () => {
|
||||||
const guardsFn = contextCreator.createGuardsFn([null], null, null);
|
const guardsFn = contextCreator.createGuardsFn([null], null!, null!)!;
|
||||||
sinon.stub(guardsConsumer, 'tryActivate').callsFake(async () => false);
|
sinon.stub(guardsConsumer, 'tryActivate').callsFake(async () => false);
|
||||||
guardsFn([]).catch(err => expect(err).to.not.be.undefined);
|
guardsFn([]).catch(err => expect(err).to.not.be.undefined);
|
||||||
});
|
});
|
||||||
@@ -217,12 +217,12 @@ describe('RpcContextCreator', () => {
|
|||||||
{
|
{
|
||||||
index: 1,
|
index: 1,
|
||||||
type: 'test',
|
type: 'test',
|
||||||
data: null,
|
data: null!,
|
||||||
pipes: [],
|
pipes: [],
|
||||||
extractValue: () => null,
|
extractValue: () => null,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
);
|
)!;
|
||||||
await pipesFn([]);
|
await pipesFn([]);
|
||||||
expect(pipesFn).to.be.a('function');
|
expect(pipesFn).to.be.a('function');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import {
|
|||||||
PATTERN_METADATA,
|
PATTERN_METADATA,
|
||||||
TRANSPORT_METADATA,
|
TRANSPORT_METADATA,
|
||||||
} from '../../constants';
|
} from '../../constants';
|
||||||
import { Transport } from '../../enums/transport.enum';
|
|
||||||
import { EventPattern } from '../../decorators/event-pattern.decorator';
|
import { EventPattern } from '../../decorators/event-pattern.decorator';
|
||||||
|
import { Transport } from '../../enums/transport.enum';
|
||||||
|
|
||||||
describe('@EventPattern', () => {
|
describe('@EventPattern', () => {
|
||||||
const pattern = { role: 'test' };
|
const pattern = { role: 'test' };
|
||||||
@@ -79,7 +79,7 @@ describe('@EventPattern', () => {
|
|||||||
Reflect.defineMetadata(
|
Reflect.defineMetadata(
|
||||||
PATTERN_EXTRAS_METADATA,
|
PATTERN_EXTRAS_METADATA,
|
||||||
additionalExtras,
|
additionalExtras,
|
||||||
descriptor.value,
|
descriptor.value!,
|
||||||
)
|
)
|
||||||
)())
|
)())
|
||||||
public static test() {}
|
public static test() {}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import {
|
import {
|
||||||
PATTERN_METADATA,
|
|
||||||
PATTERN_EXTRAS_METADATA,
|
PATTERN_EXTRAS_METADATA,
|
||||||
|
PATTERN_METADATA,
|
||||||
TRANSPORT_METADATA,
|
TRANSPORT_METADATA,
|
||||||
} from '../../constants';
|
} from '../../constants';
|
||||||
import { Transport } from '../../enums/transport.enum';
|
|
||||||
import {
|
import {
|
||||||
GrpcMethod,
|
GrpcMethod,
|
||||||
GrpcMethodStreamingType,
|
GrpcMethodStreamingType,
|
||||||
@@ -12,6 +11,7 @@ import {
|
|||||||
GrpcStreamMethod,
|
GrpcStreamMethod,
|
||||||
MessagePattern,
|
MessagePattern,
|
||||||
} from '../../decorators/message-pattern.decorator';
|
} from '../../decorators/message-pattern.decorator';
|
||||||
|
import { Transport } from '../../enums/transport.enum';
|
||||||
|
|
||||||
describe('@MessagePattern', () => {
|
describe('@MessagePattern', () => {
|
||||||
const pattern = { role: 'test' };
|
const pattern = { role: 'test' };
|
||||||
@@ -61,7 +61,7 @@ describe('@MessagePattern', () => {
|
|||||||
Reflect.defineMetadata(
|
Reflect.defineMetadata(
|
||||||
PATTERN_EXTRAS_METADATA,
|
PATTERN_EXTRAS_METADATA,
|
||||||
additionalExtras,
|
additionalExtras,
|
||||||
descriptor.value,
|
descriptor.value!,
|
||||||
)
|
)
|
||||||
)())
|
)())
|
||||||
public static test() {}
|
public static test() {}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ describe('RpcExceptionsHandler', () => {
|
|||||||
|
|
||||||
describe('handle', () => {
|
describe('handle', () => {
|
||||||
it('should method returns expected stream with message when exception is unknown', done => {
|
it('should method returns expected stream with message when exception is unknown', done => {
|
||||||
const stream$ = handler.handle(new Error(), null);
|
const stream$ = handler.handle(new Error(), null!);
|
||||||
stream$
|
stream$
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError((err: any) => {
|
catchError((err: any) => {
|
||||||
@@ -33,7 +33,7 @@ describe('RpcExceptionsHandler', () => {
|
|||||||
const message = {
|
const message = {
|
||||||
custom: 'Unauthorized',
|
custom: 'Unauthorized',
|
||||||
};
|
};
|
||||||
const stream$ = handler.handle(new RpcException(message), null);
|
const stream$ = handler.handle(new RpcException(message), null!);
|
||||||
stream$
|
stream$
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError((err: any) => {
|
catchError((err: any) => {
|
||||||
@@ -47,7 +47,7 @@ describe('RpcExceptionsHandler', () => {
|
|||||||
it('should method emit expected status and transform message to json', done => {
|
it('should method emit expected status and transform message to json', done => {
|
||||||
const message = 'Unauthorized';
|
const message = 'Unauthorized';
|
||||||
|
|
||||||
const stream$ = handler.handle(new RpcException(message), null);
|
const stream$ = handler.handle(new RpcException(message), null!);
|
||||||
stream$
|
stream$
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError((err: any) => {
|
catchError((err: any) => {
|
||||||
@@ -65,7 +65,7 @@ describe('RpcExceptionsHandler', () => {
|
|||||||
sinon.stub(handler, 'invokeCustomFilters').returns(observable$);
|
sinon.stub(handler, 'invokeCustomFilters').returns(observable$);
|
||||||
});
|
});
|
||||||
it('should return observable', () => {
|
it('should return observable', () => {
|
||||||
const result = handler.handle(new RpcException(''), null);
|
const result = handler.handle(new RpcException(''), null!);
|
||||||
expect(result).to.be.eql(observable$);
|
expect(result).to.be.eql(observable$);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -77,13 +77,13 @@ describe('RpcExceptionsHandler', () => {
|
|||||||
expect((handler as any).filters).to.be.eql(filters);
|
expect((handler as any).filters).to.be.eql(filters);
|
||||||
});
|
});
|
||||||
it('should throw exception when passed argument is not an array', () => {
|
it('should throw exception when passed argument is not an array', () => {
|
||||||
expect(() => handler.setCustomFilters(null)).to.throw();
|
expect(() => handler.setCustomFilters(null!)).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('invokeCustomFilters', () => {
|
describe('invokeCustomFilters', () => {
|
||||||
describe('when filters array is empty', () => {
|
describe('when filters array is empty', () => {
|
||||||
it('should return identity', () => {
|
it('should return identity', () => {
|
||||||
expect(handler.invokeCustomFilters(null, null)).to.be.null;
|
expect(handler.invokeCustomFilters(null, null!)).to.be.null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when filters array is not empty', () => {
|
describe('when filters array is not empty', () => {
|
||||||
@@ -99,26 +99,26 @@ describe('RpcExceptionsHandler', () => {
|
|||||||
(handler as any).filters = filters;
|
(handler as any).filters = filters;
|
||||||
});
|
});
|
||||||
it('should call funcSpy', () => {
|
it('should call funcSpy', () => {
|
||||||
handler.invokeCustomFilters(new TestException(), null);
|
handler.invokeCustomFilters(new TestException(), null!);
|
||||||
expect(funcSpy.notCalled).to.be.false;
|
expect(funcSpy.notCalled).to.be.false;
|
||||||
});
|
});
|
||||||
it('should call funcSpy with exception and response passed as an arguments', () => {
|
it('should call funcSpy with exception and response passed as an arguments', () => {
|
||||||
const exception = new TestException();
|
const exception = new TestException();
|
||||||
handler.invokeCustomFilters(exception, null);
|
handler.invokeCustomFilters(exception, null!);
|
||||||
expect(funcSpy.calledWith(exception)).to.be.true;
|
expect(funcSpy.calledWith(exception)).to.be.true;
|
||||||
});
|
});
|
||||||
it('should return stream', () => {
|
it('should return stream', () => {
|
||||||
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
|
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
|
||||||
.not.null;
|
.not.null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when filter does not exists in filters array', () => {
|
describe('when filter does not exists in filters array', () => {
|
||||||
it('should not call funcSpy', () => {
|
it('should not call funcSpy', () => {
|
||||||
handler.invokeCustomFilters(new TestException(), null);
|
handler.invokeCustomFilters(new TestException(), null!);
|
||||||
expect(funcSpy.notCalled).to.be.true;
|
expect(funcSpy.notCalled).to.be.true;
|
||||||
});
|
});
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
|
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
|
||||||
.null;
|
.null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ describe('RpcParamsFactory', () => {
|
|||||||
describe(`RpcParamtype.PAYLOAD`, () => {
|
describe(`RpcParamtype.PAYLOAD`, () => {
|
||||||
it('should return a message payload object', () => {
|
it('should return a message payload object', () => {
|
||||||
expect(
|
expect(
|
||||||
factory.exchangeKeyForValue(RpcParamtype.PAYLOAD, null, args),
|
factory.exchangeKeyForValue(RpcParamtype.PAYLOAD, null!, args),
|
||||||
).to.be.eql(payload);
|
).to.be.eql(payload);
|
||||||
});
|
});
|
||||||
it('should return a message payload object with parameter extraction', () => {
|
it('should return a message payload object with parameter extraction', () => {
|
||||||
@@ -28,19 +28,21 @@ describe('RpcParamsFactory', () => {
|
|||||||
describe(`RpcParamtype.CONTEXT`, () => {
|
describe(`RpcParamtype.CONTEXT`, () => {
|
||||||
it('should return a ctx object', () => {
|
it('should return a ctx object', () => {
|
||||||
expect(
|
expect(
|
||||||
factory.exchangeKeyForValue(RpcParamtype.CONTEXT, null, args),
|
factory.exchangeKeyForValue(RpcParamtype.CONTEXT, null!, args),
|
||||||
).to.be.eql(ctx);
|
).to.be.eql(ctx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when key is not available', () => {
|
describe('when key is not available', () => {
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
expect(factory.exchangeKeyForValue(-1, null, [])).to.be.eql(null);
|
expect(factory.exchangeKeyForValue(-1, null!, [])).to.be.eql(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when args are not available', () => {
|
describe('when args are not available', () => {
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
expect(factory.exchangeKeyForValue(null, null, null)).to.be.eql(null);
|
expect(factory.exchangeKeyForValue(null!, null!, null!)).to.be.eql(
|
||||||
|
null,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,31 +16,31 @@ describe('JsonSocket connection', () => {
|
|||||||
return done(error);
|
return done(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(clientSocket['isClosed']).to.be.false;
|
expect(clientSocket!['isClosed']).to.be.false;
|
||||||
expect(serverSocket['isClosed']).to.be.false;
|
expect(serverSocket!['isClosed']).to.be.false;
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
new Promise(callback => {
|
new Promise(callback => {
|
||||||
clientSocket.sendMessage({ type: 'ping' }, callback);
|
clientSocket!.sendMessage({ type: 'ping' }, callback);
|
||||||
}),
|
}),
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
clientSocket.on(MESSAGE_EVENT, (message: string) => {
|
clientSocket!.on(MESSAGE_EVENT, (message: string) => {
|
||||||
expect(message).to.deep.equal({ type: 'pong' });
|
expect(message).to.deep.equal({ type: 'pong' });
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
new Promise(callback => {
|
new Promise(callback => {
|
||||||
serverSocket.on(MESSAGE_EVENT, (message: string) => {
|
serverSocket!.on(MESSAGE_EVENT, (message: string) => {
|
||||||
expect(message).to.deep.equal({ type: 'ping' });
|
expect(message).to.deep.equal({ type: 'ping' });
|
||||||
serverSocket.sendMessage({ type: 'pong' }, callback);
|
serverSocket!.sendMessage({ type: 'pong' }, callback);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(clientSocket['isClosed']).to.equal(false);
|
expect(clientSocket!['isClosed']).to.equal(false);
|
||||||
expect(serverSocket['isClosed']).to.equal(false);
|
expect(serverSocket!['isClosed']).to.equal(false);
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
server.close(done);
|
server!.close(done);
|
||||||
})
|
})
|
||||||
.catch(e => done(e));
|
.catch(e => done(e));
|
||||||
},
|
},
|
||||||
@@ -52,30 +52,30 @@ describe('JsonSocket connection', () => {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
expect(clientSocket['isClosed']).to.equal(false);
|
expect(clientSocket!['isClosed']).to.equal(false);
|
||||||
expect(serverSocket['isClosed']).to.equal(false);
|
expect(serverSocket!['isClosed']).to.equal(false);
|
||||||
Promise.all([
|
Promise.all([
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
clientSocket.sendMessage(longPayload, callback);
|
clientSocket!.sendMessage(longPayload, callback);
|
||||||
}),
|
}),
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
clientSocket.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
|
clientSocket!.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
|
||||||
expect(message).to.deep.equal({ type: 'pong' });
|
expect(message).to.deep.equal({ type: 'pong' });
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
serverSocket.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
|
serverSocket!.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
|
||||||
expect(message).to.deep.equal(longPayload);
|
expect(message).to.deep.equal(longPayload);
|
||||||
serverSocket.sendMessage({ type: 'pong' }, callback);
|
serverSocket!.sendMessage({ type: 'pong' }, callback);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(clientSocket['isClosed']).to.equal(false);
|
expect(clientSocket!['isClosed']).to.equal(false);
|
||||||
expect(serverSocket['isClosed']).to.equal(false);
|
expect(serverSocket!['isClosed']).to.equal(false);
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
server.close(done);
|
server!.close(done);
|
||||||
})
|
})
|
||||||
.catch(e => done(e));
|
.catch(e => done(e));
|
||||||
});
|
});
|
||||||
@@ -94,14 +94,14 @@ describe('JsonSocket connection', () => {
|
|||||||
.map(
|
.map(
|
||||||
i =>
|
i =>
|
||||||
new Promise(resolve =>
|
new Promise(resolve =>
|
||||||
clientSocket.sendMessage({ number: i }, resolve),
|
clientSocket!.sendMessage({ number: i }, resolve),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).then(_ => callback()),
|
).then(_ => callback()),
|
||||||
),
|
),
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
let lastNumber = 0;
|
let lastNumber = 0;
|
||||||
serverSocket.on(MESSAGE_EVENT, (message: { number: number }) => {
|
serverSocket!.on(MESSAGE_EVENT, (message: { number: number }) => {
|
||||||
expect(message.number).to.deep.equal(lastNumber + 1);
|
expect(message.number).to.deep.equal(lastNumber + 1);
|
||||||
lastNumber = message.number;
|
lastNumber = message.number;
|
||||||
if (lastNumber === 100) {
|
if (lastNumber === 100) {
|
||||||
@@ -111,8 +111,8 @@ describe('JsonSocket connection', () => {
|
|||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
server.close(done);
|
server!.close(done);
|
||||||
})
|
})
|
||||||
.catch(e => done(e));
|
.catch(e => done(e));
|
||||||
});
|
});
|
||||||
@@ -125,20 +125,20 @@ describe('JsonSocket connection', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new Promise(callback => {
|
new Promise(callback => {
|
||||||
serverSocket.end();
|
serverSocket!.end();
|
||||||
setTimeout(callback, 10);
|
setTimeout(callback, 10);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() =>
|
() =>
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
expect(clientSocket['isClosed']).to.equal(true);
|
expect(clientSocket!['isClosed']).to.equal(true);
|
||||||
expect(serverSocket['isClosed']).to.equal(true);
|
expect(serverSocket!['isClosed']).to.equal(true);
|
||||||
callback();
|
callback();
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
server.close(done);
|
server!.close(done);
|
||||||
})
|
})
|
||||||
.catch(e => done(e));
|
.catch(e => done(e));
|
||||||
});
|
});
|
||||||
@@ -151,18 +151,18 @@ describe('JsonSocket connection', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new Promise(callback => {
|
new Promise(callback => {
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
setTimeout(callback, 10);
|
setTimeout(callback, 10);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() =>
|
() =>
|
||||||
new Promise<void>(callback => {
|
new Promise<void>(callback => {
|
||||||
expect(clientSocket['isClosed']).to.equal(true);
|
expect(clientSocket!['isClosed']).to.equal(true);
|
||||||
expect(serverSocket['isClosed']).to.equal(true);
|
expect(serverSocket!['isClosed']).to.equal(true);
|
||||||
callback();
|
callback();
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.then(() => server.close(done))
|
.then(() => server!.close(done))
|
||||||
.catch(e => done(e));
|
.catch(e => done(e));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -176,16 +176,16 @@ describe('JsonSocket connection', () => {
|
|||||||
server.once('connection', socket => {
|
server.once('connection', socket => {
|
||||||
const serverSocket = new JsonSocket(socket);
|
const serverSocket = new JsonSocket(socket);
|
||||||
|
|
||||||
serverSocket.once('end', () => {
|
serverSocket!.once('end', () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(serverSocket['isClosed']).to.equal(true);
|
expect(serverSocket!['isClosed']).to.equal(true);
|
||||||
expect(clientSocket['isClosed']).to.equal(true);
|
expect(clientSocket!['isClosed']).to.equal(true);
|
||||||
|
|
||||||
clientSocket.on(TcpEventsMap.CONNECT, () => {
|
clientSocket!.on(TcpEventsMap.CONNECT, () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(clientSocket['isClosed']).to.equal(false);
|
expect(clientSocket!['isClosed']).to.equal(false);
|
||||||
|
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
server.close(done);
|
server.close(done);
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
@@ -196,11 +196,11 @@ describe('JsonSocket connection', () => {
|
|||||||
}
|
}
|
||||||
const port2 = (address2 as AddressInfo).port;
|
const port2 = (address2 as AddressInfo).port;
|
||||||
|
|
||||||
clientSocket.connect(port2, ip);
|
clientSocket!.connect(port2, ip);
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
const address1 = server.address();
|
const address1 = server.address();
|
||||||
@@ -209,7 +209,7 @@ describe('JsonSocket connection', () => {
|
|||||||
}
|
}
|
||||||
const port1 = (address1 as AddressInfo).port;
|
const port1 = (address1 as AddressInfo).port;
|
||||||
|
|
||||||
clientSocket.connect(port1, ip);
|
clientSocket!.connect(port1, ip);
|
||||||
});
|
});
|
||||||
server.listen();
|
server.listen();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export function createServerAndClient(
|
|||||||
return callback(serverErr);
|
return callback(serverErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
createClient(server, (clientErr, clientSocket, serverSocket) => {
|
createClient(server!, (clientErr, clientSocket, serverSocket) => {
|
||||||
if (clientErr) {
|
if (clientErr) {
|
||||||
return callback(clientErr);
|
return callback(clientErr);
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ export function createServerAndClient(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function range(start: number, end: number) {
|
export function range(start: number, end: number) {
|
||||||
const r = [];
|
const r = [] as number[];
|
||||||
for (let i = start; i <= end; i++) {
|
for (let i = start; i <= end; i++) {
|
||||||
r.push(i);
|
r.push(i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,18 @@ describe('JsonSocket chaining', () => {
|
|||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(clientSocket.on(MESSAGE_EVENT, () => {})).to.be.instanceof(
|
expect(clientSocket!.on(MESSAGE_EVENT, () => {})).to.be.instanceof(
|
||||||
JsonSocket,
|
JsonSocket,
|
||||||
);
|
);
|
||||||
expect(clientSocket.on(TcpEventsMap.CONNECT, () => {})).to.deep.equal(
|
expect(clientSocket!.on(TcpEventsMap.CONNECT, () => {})).to.deep.equal(
|
||||||
clientSocket,
|
clientSocket,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
clientSocket.on(MESSAGE_EVENT, () => {}).on('end', () => {}),
|
clientSocket!.on(MESSAGE_EVENT, () => {}).on('end', () => {}),
|
||||||
).to.deep.equal(clientSocket);
|
).to.deep.equal(clientSocket);
|
||||||
|
|
||||||
clientSocket.end();
|
clientSocket!.end();
|
||||||
server.close(done);
|
server!.close(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ describe('ListenersController', () => {
|
|||||||
patterns: ['findOne'],
|
patterns: ['findOne'],
|
||||||
methodKey: 'find',
|
methodKey: 'find',
|
||||||
isEventHandler: false,
|
isEventHandler: false,
|
||||||
targetCallback: null,
|
targetCallback: null!,
|
||||||
extras: { qos: 2 },
|
extras: { qos: 2 },
|
||||||
};
|
};
|
||||||
const transportId = Transport.MQTT;
|
const transportId = Transport.MQTT;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ describe('ListenerMetadataExplorer', () => {
|
|||||||
test,
|
test,
|
||||||
Object.getPrototypeOf(test),
|
Object.getPrototypeOf(test),
|
||||||
'testMessage',
|
'testMessage',
|
||||||
);
|
)!;
|
||||||
expect(metadata).to.have.keys([
|
expect(metadata).to.have.keys([
|
||||||
'isEventHandler',
|
'isEventHandler',
|
||||||
'methodKey',
|
'methodKey',
|
||||||
@@ -101,7 +101,7 @@ describe('ListenerMetadataExplorer', () => {
|
|||||||
test,
|
test,
|
||||||
Object.getPrototypeOf(test),
|
Object.getPrototypeOf(test),
|
||||||
'testMultipleMessage',
|
'testMultipleMessage',
|
||||||
);
|
)!;
|
||||||
expect(metadata).to.have.keys([
|
expect(metadata).to.have.keys([
|
||||||
'isEventHandler',
|
'isEventHandler',
|
||||||
'methodKey',
|
'methodKey',
|
||||||
@@ -122,7 +122,7 @@ describe('ListenerMetadataExplorer', () => {
|
|||||||
test,
|
test,
|
||||||
Object.getPrototypeOf(test),
|
Object.getPrototypeOf(test),
|
||||||
'testEvent',
|
'testEvent',
|
||||||
);
|
)!;
|
||||||
expect(metadata).to.have.keys([
|
expect(metadata).to.have.keys([
|
||||||
'isEventHandler',
|
'isEventHandler',
|
||||||
'methodKey',
|
'methodKey',
|
||||||
@@ -139,7 +139,7 @@ describe('ListenerMetadataExplorer', () => {
|
|||||||
test,
|
test,
|
||||||
Object.getPrototypeOf(test),
|
Object.getPrototypeOf(test),
|
||||||
'testMultipleEvent',
|
'testMultipleEvent',
|
||||||
);
|
)!;
|
||||||
expect(metadata).to.have.keys([
|
expect(metadata).to.have.keys([
|
||||||
'isEventHandler',
|
'isEventHandler',
|
||||||
'methodKey',
|
'methodKey',
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe('ClientsModule', () => {
|
|||||||
expect(dynamicModule.module).to.be.eql(ClientsModule);
|
expect(dynamicModule.module).to.be.eql(ClientsModule);
|
||||||
});
|
});
|
||||||
it('should return an expected providers array', () => {
|
it('should return an expected providers array', () => {
|
||||||
const provider = dynamicModule.providers.find(
|
const provider = dynamicModule.providers!.find(
|
||||||
p => 'useValue' in p && p.provide === 'test',
|
p => 'useValue' in p && p.provide === 'test',
|
||||||
) as ValueProvider;
|
) as ValueProvider;
|
||||||
expect(provider).to.not.be.undefined;
|
expect(provider).to.not.be.undefined;
|
||||||
@@ -56,7 +56,7 @@ describe('ClientsModule', () => {
|
|||||||
expect(dynamicModule.exports).to.be.eq(dynamicModule.providers);
|
expect(dynamicModule.exports).to.be.eq(dynamicModule.providers);
|
||||||
expect(dynamicModule.providers).to.be.have.length(1);
|
expect(dynamicModule.providers).to.be.have.length(1);
|
||||||
|
|
||||||
const provider = dynamicModule.providers[0] as FactoryProvider;
|
const provider = dynamicModule.providers![0] as FactoryProvider;
|
||||||
expect(provider.provide).to.be.eql('test');
|
expect(provider.provide).to.be.eql('test');
|
||||||
expect(provider.inject).to.be.deep.eq([]);
|
expect(provider.inject).to.be.deep.eq([]);
|
||||||
expect(provider.useFactory).to.be.an.instanceOf(Function);
|
expect(provider.useFactory).to.be.an.instanceOf(Function);
|
||||||
@@ -82,7 +82,8 @@ describe('ClientsModule', () => {
|
|||||||
expect(dynamicModule.imports).to.be.deep.eq([]);
|
expect(dynamicModule.imports).to.be.deep.eq([]);
|
||||||
expect(dynamicModule.providers).to.be.have.length(2);
|
expect(dynamicModule.providers).to.be.have.length(2);
|
||||||
|
|
||||||
const classTestProvider = dynamicModule.providers[0] as FactoryProvider;
|
const classTestProvider = dynamicModule
|
||||||
|
.providers![0] as FactoryProvider;
|
||||||
expect(classTestProvider.provide).to.be.eql('classTest');
|
expect(classTestProvider.provide).to.be.eql('classTest');
|
||||||
expect(classTestProvider.inject).to.be.deep.eq([ClientOptionService]);
|
expect(classTestProvider.inject).to.be.deep.eq([ClientOptionService]);
|
||||||
expect(classTestProvider.useFactory).to.be.an.instanceOf(Function);
|
expect(classTestProvider.useFactory).to.be.an.instanceOf(Function);
|
||||||
@@ -98,7 +99,7 @@ describe('ClientsModule', () => {
|
|||||||
createClientOptions: sinon.spy(),
|
createClientOptions: sinon.spy(),
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
await (dynamicModule.providers[0] as any).useFactory(optionsFactory);
|
await (dynamicModule.providers![0] as any).useFactory(optionsFactory);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@@ -114,7 +115,8 @@ describe('ClientsModule', () => {
|
|||||||
dynamicModule = ClientsModule.registerAsync([asyncOptions as any]);
|
dynamicModule = ClientsModule.registerAsync([asyncOptions as any]);
|
||||||
expect(dynamicModule.providers).to.have.length(1);
|
expect(dynamicModule.providers).to.have.length(1);
|
||||||
expect(dynamicModule.imports).to.be.deep.eq([]);
|
expect(dynamicModule.imports).to.be.deep.eq([]);
|
||||||
const classTestProvider = dynamicModule.providers[0] as FactoryProvider;
|
const classTestProvider = dynamicModule
|
||||||
|
.providers![0] as FactoryProvider;
|
||||||
expect(classTestProvider.useFactory).to.be.an.instanceOf(Function);
|
expect(classTestProvider.useFactory).to.be.an.instanceOf(Function);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -731,7 +731,7 @@ describe('ServerGrpc', () => {
|
|||||||
write: sinon.spy(() => true),
|
write: sinon.spy(() => true),
|
||||||
};
|
};
|
||||||
|
|
||||||
await fn(call as any, null);
|
await fn(call as any, null!);
|
||||||
|
|
||||||
expect(call.write.called).to.be.true;
|
expect(call.write.called).to.be.true;
|
||||||
expect(call.end.called).to.be.true;
|
expect(call.end.called).to.be.true;
|
||||||
|
|||||||
@@ -265,8 +265,8 @@ describe('ServerKafka', () => {
|
|||||||
it('should call "handleMessage"', async () => {
|
it('should call "handleMessage"', async () => {
|
||||||
const handleMessageStub = sinon
|
const handleMessageStub = sinon
|
||||||
.stub(server, 'handleMessage')
|
.stub(server, 'handleMessage')
|
||||||
.callsFake(() => null);
|
.callsFake(() => null!);
|
||||||
await server.getMessageHandler()(null);
|
await server.getMessageHandler()(null!);
|
||||||
expect(handleMessageStub.called).to.be.true;
|
expect(handleMessageStub.called).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -287,7 +287,7 @@ describe('ServerKafka', () => {
|
|||||||
.callsFake(async () => []);
|
.callsFake(async () => []);
|
||||||
});
|
});
|
||||||
it(`should return function`, () => {
|
it(`should return function`, () => {
|
||||||
expect(typeof server.getPublisher(null, null, correlationId)).to.be.eql(
|
expect(typeof server.getPublisher(null!, null!, correlationId)).to.be.eql(
|
||||||
'function',
|
'function',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -393,7 +393,9 @@ describe('ServerKafka', () => {
|
|||||||
await server.handleMessage(payload);
|
await server.handleMessage(payload);
|
||||||
expect(
|
expect(
|
||||||
getPublisherSpy.calledWith({
|
getPublisherSpy.calledWith({
|
||||||
id: payload.message.headers[KafkaHeaders.CORRELATION_ID].toString(),
|
id: payload.message!.headers![
|
||||||
|
KafkaHeaders.CORRELATION_ID
|
||||||
|
]!.toString(),
|
||||||
err: NO_MESSAGE_HANDLER,
|
err: NO_MESSAGE_HANDLER,
|
||||||
}),
|
}),
|
||||||
).to.be.true;
|
).to.be.true;
|
||||||
@@ -453,7 +455,7 @@ describe('ServerKafka', () => {
|
|||||||
response: messageValue,
|
response: messageValue,
|
||||||
},
|
},
|
||||||
replyTopic,
|
replyTopic,
|
||||||
undefined,
|
undefined!,
|
||||||
correlationId,
|
correlationId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -103,11 +103,11 @@ describe('ServerMqtt', () => {
|
|||||||
it('should call "handleMessage"', async () => {
|
it('should call "handleMessage"', async () => {
|
||||||
const handleMessageStub = sinon
|
const handleMessageStub = sinon
|
||||||
.stub(server, 'handleMessage')
|
.stub(server, 'handleMessage')
|
||||||
.callsFake(() => null);
|
.callsFake(() => null!);
|
||||||
await server.getMessageHandler(untypedServer.mqttClient)(
|
await server.getMessageHandler(untypedServer.mqttClient)(
|
||||||
null,
|
null!,
|
||||||
null,
|
null!,
|
||||||
null,
|
null!,
|
||||||
);
|
);
|
||||||
expect(handleMessageStub.called).to.be.true;
|
expect(handleMessageStub.called).to.be.true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -140,13 +140,13 @@ describe('ServerNats', () => {
|
|||||||
});
|
});
|
||||||
describe('getMessageHandler', () => {
|
describe('getMessageHandler', () => {
|
||||||
it(`should return function`, () => {
|
it(`should return function`, () => {
|
||||||
expect(typeof server.getMessageHandler(null)).to.be.eql('function');
|
expect(typeof server.getMessageHandler(null!)).to.be.eql('function');
|
||||||
});
|
});
|
||||||
describe('handler', () => {
|
describe('handler', () => {
|
||||||
it('should call "handleMessage"', async () => {
|
it('should call "handleMessage"', async () => {
|
||||||
const handleMessageStub = sinon
|
const handleMessageStub = sinon
|
||||||
.stub(server, 'handleMessage')
|
.stub(server, 'handleMessage')
|
||||||
.callsFake(() => null);
|
.callsFake(() => null!);
|
||||||
await server.getMessageHandler('')('' as any, '');
|
await server.getMessageHandler('')('' as any, '');
|
||||||
expect(handleMessageStub.called).to.be.true;
|
expect(handleMessageStub.called).to.be.true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -223,9 +223,9 @@ describe('ServerRedis', () => {
|
|||||||
describe('getClientOptions', () => {
|
describe('getClientOptions', () => {
|
||||||
it('should return options object with "retryStrategy" and call "createRetryStrategy"', () => {
|
it('should return options object with "retryStrategy" and call "createRetryStrategy"', () => {
|
||||||
const createSpy = sinon.spy(server, 'createRetryStrategy');
|
const createSpy = sinon.spy(server, 'createRetryStrategy');
|
||||||
const { retryStrategy } = server.getClientOptions();
|
const { retryStrategy } = server.getClientOptions()!;
|
||||||
try {
|
try {
|
||||||
retryStrategy(0);
|
retryStrategy!(0);
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ describe('ServerTCP', () => {
|
|||||||
sinon.stub(server, 'getSocketInstance' as any).callsFake(() => socket);
|
sinon.stub(server, 'getSocketInstance' as any).callsFake(() => socket);
|
||||||
});
|
});
|
||||||
it('should bind message and error events to handler', () => {
|
it('should bind message and error events to handler', () => {
|
||||||
server.bindHandler(null);
|
server.bindHandler(null!);
|
||||||
expect(socket.on.calledTwice).to.be.true;
|
expect(socket.on.calledTwice).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class TestServer extends Server {
|
|||||||
EventCallback extends Function = Function,
|
EventCallback extends Function = Function,
|
||||||
>(event: EventKey, callback: EventCallback) {}
|
>(event: EventKey, callback: EventCallback) {}
|
||||||
public unwrap<T>(): T {
|
public unwrap<T>(): T {
|
||||||
return null;
|
return null!;
|
||||||
}
|
}
|
||||||
public listen(callback: () => void) {}
|
public listen(callback: () => void) {}
|
||||||
public close() {}
|
public close() {}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ describe('transformPatternToRoute', () => {
|
|||||||
controller: 'app',
|
controller: 'app',
|
||||||
id: 150,
|
id: 150,
|
||||||
},
|
},
|
||||||
];
|
] as MsPattern[];
|
||||||
|
|
||||||
const expectedResults = [
|
const expectedResults = [
|
||||||
JSON.stringify(testPatterns[0]),
|
JSON.stringify(testPatterns[0]),
|
||||||
@@ -71,7 +71,7 @@ describe('transformPatternToRoute', () => {
|
|||||||
use: { p1: 'path1', p2: 'path2', id: 160 },
|
use: { p1: 'path1', p2: 'path2', id: 160 },
|
||||||
controller: 'app',
|
controller: 'app',
|
||||||
},
|
},
|
||||||
];
|
] as MsPattern[];
|
||||||
|
|
||||||
const expectedResults = [
|
const expectedResults = [
|
||||||
JSON.stringify(testPatterns[0]),
|
JSON.stringify(testPatterns[0]),
|
||||||
@@ -98,7 +98,7 @@ describe('transformPatternToRoute', () => {
|
|||||||
use: { p1: 'path1', p2: { pp1: 'ppath1' } },
|
use: { p1: 'path1', p2: { pp1: 'ppath1' } },
|
||||||
controller: { p1: { pp1: 'ppath1', id: 180 } },
|
controller: { p1: { pp1: 'ppath1', id: 180 } },
|
||||||
},
|
},
|
||||||
];
|
] as MsPattern[];
|
||||||
|
|
||||||
const expectedResults = [
|
const expectedResults = [
|
||||||
JSON.stringify(testPatterns[0]),
|
JSON.stringify(testPatterns[0]),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { FactoryProvider } from '@nestjs/common';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as sinon from 'sinon';
|
import * as sinon from 'sinon';
|
||||||
import { MULTER_MODULE_OPTIONS } from '../../../multer/files.constants';
|
import { MULTER_MODULE_OPTIONS } from '../../../multer/files.constants';
|
||||||
import { MulterModule } from '../../../multer/multer.module';
|
import { MulterModule } from '../../../multer/multer.module';
|
||||||
import { FactoryProvider } from '@nestjs/common';
|
|
||||||
|
|
||||||
describe('MulterModule', () => {
|
describe('MulterModule', () => {
|
||||||
describe('register', () => {
|
describe('register', () => {
|
||||||
@@ -16,7 +16,7 @@ describe('MulterModule', () => {
|
|||||||
expect(dynamicModule.imports).to.be.undefined;
|
expect(dynamicModule.imports).to.be.undefined;
|
||||||
expect(dynamicModule.exports).to.include(MULTER_MODULE_OPTIONS);
|
expect(dynamicModule.exports).to.include(MULTER_MODULE_OPTIONS);
|
||||||
|
|
||||||
const moduleOptionsProvider = dynamicModule.providers.find(
|
const moduleOptionsProvider = dynamicModule.providers!.find(
|
||||||
p => 'useFactory' in p && p.provide === MULTER_MODULE_OPTIONS,
|
p => 'useFactory' in p && p.provide === MULTER_MODULE_OPTIONS,
|
||||||
) as FactoryProvider;
|
) as FactoryProvider;
|
||||||
expect(moduleOptionsProvider).to.not.be.undefined;
|
expect(moduleOptionsProvider).to.not.be.undefined;
|
||||||
@@ -76,7 +76,7 @@ describe('MulterModule', () => {
|
|||||||
const optionsFactory = {
|
const optionsFactory = {
|
||||||
createMulterOptions: sinon.spy(),
|
createMulterOptions: sinon.spy(),
|
||||||
};
|
};
|
||||||
await (dynamicModule.providers[0] as any).useFactory(optionsFactory);
|
await (dynamicModule.providers![0] as any).useFactory(optionsFactory);
|
||||||
expect(optionsFactory.createMulterOptions.called).to.be.true;
|
expect(optionsFactory.createMulterOptions.called).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import {
|
import {
|
||||||
multerExceptions,
|
|
||||||
busboyExceptions,
|
busboyExceptions,
|
||||||
|
multerExceptions,
|
||||||
} from '../../../multer/multer/multer.constants';
|
} from '../../../multer/multer/multer.constants';
|
||||||
import { transformException } from '../../../multer/multer/multer.utils';
|
import { transformException } from '../../../multer/multer/multer.utils';
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ describe('transformException', () => {
|
|||||||
message: multerExceptions.LIMIT_UNEXPECTED_FILE,
|
message: multerExceptions.LIMIT_UNEXPECTED_FILE,
|
||||||
field: 'foo',
|
field: 'foo',
|
||||||
};
|
};
|
||||||
expect(transformException(err as any).message).to.equal(
|
expect(transformException(err as any)!.message).to.equal(
|
||||||
`${multerExceptions.LIMIT_UNEXPECTED_FILE} - foo`,
|
`${multerExceptions.LIMIT_UNEXPECTED_FILE} - foo`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { NestContainer } from '../../../core/injector/container';
|
|||||||
import { ExceptionFiltersContext } from '../../context/exception-filters-context';
|
import { ExceptionFiltersContext } from '../../context/exception-filters-context';
|
||||||
|
|
||||||
describe('ExceptionFiltersContext', () => {
|
describe('ExceptionFiltersContext', () => {
|
||||||
let moduleName: string;
|
|
||||||
let exceptionFilter: ExceptionFiltersContext;
|
let exceptionFilter: ExceptionFiltersContext;
|
||||||
|
|
||||||
class CustomException {}
|
class CustomException {}
|
||||||
@@ -16,7 +15,6 @@ describe('ExceptionFiltersContext', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
moduleName = 'Test';
|
|
||||||
exceptionFilter = new ExceptionFiltersContext(new NestContainer() as any);
|
exceptionFilter = new ExceptionFiltersContext(new NestContainer() as any);
|
||||||
});
|
});
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ describe('WsContextCreator', () => {
|
|||||||
|
|
||||||
describe('createGuardsFn', () => {
|
describe('createGuardsFn', () => {
|
||||||
it('should throw exception when "tryActivate" returns false', () => {
|
it('should throw exception when "tryActivate" returns false', () => {
|
||||||
const guardsFn = contextCreator.createGuardsFn([null], null, null);
|
const guardsFn = contextCreator.createGuardsFn([null], null!, null!)!;
|
||||||
sinon.stub(guardsConsumer, 'tryActivate').callsFake(async () => false);
|
sinon.stub(guardsConsumer, 'tryActivate').callsFake(async () => false);
|
||||||
guardsFn([]).catch(err => expect(err).to.not.be.undefined);
|
guardsFn([]).catch(err => expect(err).to.not.be.undefined);
|
||||||
});
|
});
|
||||||
@@ -211,12 +211,12 @@ describe('WsContextCreator', () => {
|
|||||||
{
|
{
|
||||||
index: 1,
|
index: 1,
|
||||||
type: 'test',
|
type: 'test',
|
||||||
data: null,
|
data: null!,
|
||||||
pipes: [],
|
pipes: [],
|
||||||
extractValue: () => null,
|
extractValue: () => null,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
);
|
)!;
|
||||||
await pipesFn([]);
|
await pipesFn([]);
|
||||||
expect(pipesFn).to.be.a('function');
|
expect(pipesFn).to.be.a('function');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -121,13 +121,13 @@ describe('WsExceptionsHandler', () => {
|
|||||||
expect((handler as any).filters).to.be.eql(filters);
|
expect((handler as any).filters).to.be.eql(filters);
|
||||||
});
|
});
|
||||||
it('should throw exception when passed argument is not an array', () => {
|
it('should throw exception when passed argument is not an array', () => {
|
||||||
expect(() => handler.setCustomFilters(null)).to.throw();
|
expect(() => handler.setCustomFilters(null!)).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('invokeCustomFilters', () => {
|
describe('invokeCustomFilters', () => {
|
||||||
describe('when filters array is empty', () => {
|
describe('when filters array is empty', () => {
|
||||||
it('should return false', () => {
|
it('should return false', () => {
|
||||||
expect(handler.invokeCustomFilters(null, null)).to.be.false;
|
expect(handler.invokeCustomFilters(null, null!)).to.be.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when filters array is not empty', () => {
|
describe('when filters array is not empty', () => {
|
||||||
@@ -143,7 +143,7 @@ describe('WsExceptionsHandler', () => {
|
|||||||
(handler as any).filters = filters;
|
(handler as any).filters = filters;
|
||||||
});
|
});
|
||||||
it('should call funcSpy', () => {
|
it('should call funcSpy', () => {
|
||||||
handler.invokeCustomFilters(new TestException(), null);
|
handler.invokeCustomFilters(new TestException(), null!);
|
||||||
expect(funcSpy.notCalled).to.be.false;
|
expect(funcSpy.notCalled).to.be.false;
|
||||||
});
|
});
|
||||||
it('should call funcSpy with exception and response passed as an arguments', () => {
|
it('should call funcSpy with exception and response passed as an arguments', () => {
|
||||||
@@ -154,17 +154,17 @@ describe('WsExceptionsHandler', () => {
|
|||||||
expect(funcSpy.calledWith(exception, res)).to.be.true;
|
expect(funcSpy.calledWith(exception, res)).to.be.true;
|
||||||
});
|
});
|
||||||
it('should return true', () => {
|
it('should return true', () => {
|
||||||
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
|
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
|
||||||
.true;
|
.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when filter does not exists in filters array', () => {
|
describe('when filter does not exists in filters array', () => {
|
||||||
it('should not call funcSpy', () => {
|
it('should not call funcSpy', () => {
|
||||||
handler.invokeCustomFilters(new TestException(), null);
|
handler.invokeCustomFilters(new TestException(), null!);
|
||||||
expect(funcSpy.notCalled).to.be.true;
|
expect(funcSpy.notCalled).to.be.true;
|
||||||
});
|
});
|
||||||
it('should return false', () => {
|
it('should return false', () => {
|
||||||
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
|
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
|
||||||
.false;
|
.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ describe('WsParamsFactory', () => {
|
|||||||
describe(`WsParamtype.PAYLOAD`, () => {
|
describe(`WsParamtype.PAYLOAD`, () => {
|
||||||
it('should return a message payload object', () => {
|
it('should return a message payload object', () => {
|
||||||
expect(
|
expect(
|
||||||
factory.exchangeKeyForValue(WsParamtype.PAYLOAD, null, args),
|
factory.exchangeKeyForValue(WsParamtype.PAYLOAD, null!, args),
|
||||||
).to.be.eql(data);
|
).to.be.eql(data);
|
||||||
});
|
});
|
||||||
it('should return a message payload object with parameter extraction', () => {
|
it('should return a message payload object with parameter extraction', () => {
|
||||||
@@ -28,19 +28,21 @@ describe('WsParamsFactory', () => {
|
|||||||
describe(`WsParamtype.SOCKET`, () => {
|
describe(`WsParamtype.SOCKET`, () => {
|
||||||
it('should return a connected socket object', () => {
|
it('should return a connected socket object', () => {
|
||||||
expect(
|
expect(
|
||||||
factory.exchangeKeyForValue(WsParamtype.SOCKET, null, args),
|
factory.exchangeKeyForValue(WsParamtype.SOCKET, null!, args),
|
||||||
).to.be.eql(client);
|
).to.be.eql(client);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when key is not available', () => {
|
describe('when key is not available', () => {
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
expect(factory.exchangeKeyForValue(-1, null, [])).to.be.eql(null);
|
expect(factory.exchangeKeyForValue(-1, null!, [])).to.be.eql(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when args are not available', () => {
|
describe('when args are not available', () => {
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
expect(factory.exchangeKeyForValue(null, null, null)).to.be.eql(null);
|
expect(factory.exchangeKeyForValue(null!, null!, null!)).to.be.eql(
|
||||||
|
null,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ describe('GatewayMetadataExplorer', () => {
|
|||||||
expect(metadata).to.eq(null);
|
expect(metadata).to.eq(null);
|
||||||
});
|
});
|
||||||
it(`should return message mapping properties when "isMessageMapping" metadata is not undefined`, () => {
|
it(`should return message mapping properties when "isMessageMapping" metadata is not undefined`, () => {
|
||||||
const metadata = instance.exploreMethodMetadata(test, 'test');
|
const metadata = instance.exploreMethodMetadata(test, 'test')!;
|
||||||
expect(metadata).to.have.keys(['callback', 'message', 'methodName']);
|
expect(metadata).to.have.keys(['callback', 'message', 'methodName']);
|
||||||
expect(metadata.message).to.eql(message);
|
expect(metadata.message).to.eql(message);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ describe('SocketServerProvider', () => {
|
|||||||
const server = { test: 'test' };
|
const server = { test: 'test' };
|
||||||
mockContainer.expects('getOneByConfig').returns(server);
|
mockContainer.expects('getOneByConfig').returns(server);
|
||||||
|
|
||||||
const result = instance.scanForSocketServer({ namespace: null }, port);
|
const result = instance.scanForSocketServer({ namespace: null! }, port);
|
||||||
|
|
||||||
expect(createSocketServerSpy.called).to.be.false;
|
expect(createSocketServerSpy.called).to.be.false;
|
||||||
expect(result).to.eq(server);
|
expect(result).to.eq(server);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ describe('WebSocketsController', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config = new ApplicationConfig(new NoopAdapter());
|
config = new ApplicationConfig(new NoopAdapter());
|
||||||
provider = new SocketServerProvider(null, config);
|
provider = new SocketServerProvider(null!, config);
|
||||||
graphInspector = new GraphInspector(new NestContainer());
|
graphInspector = new GraphInspector(new NestContainer());
|
||||||
mockProvider = sinon.mock(provider);
|
mockProvider = sinon.mock(provider);
|
||||||
|
|
||||||
@@ -187,12 +187,12 @@ describe('WebSocketsController', () => {
|
|||||||
{
|
{
|
||||||
methodName: 'findOne',
|
methodName: 'findOne',
|
||||||
message: 'find',
|
message: 'find',
|
||||||
callback: null,
|
callback: null!,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
methodName: 'create',
|
methodName: 'create',
|
||||||
message: 'insert',
|
message: 'insert',
|
||||||
callback: null,
|
callback: null!,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const insertEntrypointDefinitionSpy = sinon.spy(
|
const insertEntrypointDefinitionSpy = sinon.spy(
|
||||||
@@ -337,7 +337,7 @@ describe('WebSocketsController', () => {
|
|||||||
instance,
|
instance,
|
||||||
gateway,
|
gateway,
|
||||||
handlers,
|
handlers,
|
||||||
null,
|
null!,
|
||||||
connection,
|
connection,
|
||||||
);
|
);
|
||||||
fn(client);
|
fn(client);
|
||||||
@@ -345,7 +345,7 @@ describe('WebSocketsController', () => {
|
|||||||
|
|
||||||
it('should return function', () => {
|
it('should return function', () => {
|
||||||
expect(
|
expect(
|
||||||
instance.getConnectionHandler(null, null, null, null, null),
|
instance.getConnectionHandler(null!, null!, null!, null!, null!),
|
||||||
).to.be.a('function');
|
).to.be.a('function');
|
||||||
});
|
});
|
||||||
it('should call "next" method of connection object with expected argument', () => {
|
it('should call "next" method of connection object with expected argument', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user