fix(microservices): reorder kafka config assigment

This commit is contained in:
Vlad Krokhin
2021-08-09 16:52:08 +03:00
parent 664f531d2a
commit 2084157cf7
2 changed files with 25 additions and 5 deletions

View File

@@ -107,11 +107,11 @@ export class ServerKafka extends Server implements CustomTransportStrategy {
public createClient<T = any>(): T {
return new kafkaPackage.Kafka(
Object.assign(this.options.client || {}, {
clientId: this.clientId,
brokers: this.brokers,
logCreator: KafkaLogger.bind(null, this.logger),
}) as KafkaConfig,
Object.assign(
{ logCreator: KafkaLogger.bind(null, this.logger) },
this.options.client,
{ clientId: this.clientId, brokers: this.brokers }
) as KafkaConfig,
);
}

View File

@@ -425,4 +425,24 @@ describe('ServerKafka', () => {
).to.be.true;
});
});
describe('createClient', () => {
it('should accept a custom logCreator in client options', () => {
const logCreatorSpy = sinon.spy(() => 'test');
const logCreator = () => logCreatorSpy;
server = new ServerKafka({
client: {
brokers: [],
logCreator,
},
});
const logger = server.createClient().logger();
logger.info({ namespace: '', level: 1, log: 'test' });
expect(logCreatorSpy.called).to.be.true;
})
})
});