From 0209a9146931298ab0f24aa6cdf27fd7ae9a4b6b Mon Sep 17 00:00:00 2001 From: jochongs Date: Fri, 29 Mar 2024 17:24:41 +0900 Subject: [PATCH 1/2] refactor(microservices): Fix isNotKafkaMessage validation condition --- .../microservices/serializers/kafka-request.serializer.ts | 4 +--- .../test/serializers/kafka-request.serializer.spec.ts | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/microservices/serializers/kafka-request.serializer.ts b/packages/microservices/serializers/kafka-request.serializer.ts index 7c519c4583a..5e2f66c423e 100644 --- a/packages/microservices/serializers/kafka-request.serializer.ts +++ b/packages/microservices/serializers/kafka-request.serializer.ts @@ -21,9 +21,7 @@ export class KafkaRequestSerializer { serialize(value: any) { const isNotKafkaMessage = - isNil(value) || - !isObject(value) || - (!('key' in value) && !('value' in value)); + isNil(value) || !isObject(value) || !('key' in value && 'value' in value); if (isNotKafkaMessage) { value = { value }; diff --git a/packages/microservices/test/serializers/kafka-request.serializer.spec.ts b/packages/microservices/test/serializers/kafka-request.serializer.spec.ts index 566e86d95a8..f39f4169069 100644 --- a/packages/microservices/test/serializers/kafka-request.serializer.spec.ts +++ b/packages/microservices/test/serializers/kafka-request.serializer.spec.ts @@ -97,7 +97,9 @@ describe('KafkaRequestSerializer', () => { }), ).to.deep.eq({ headers: {}, - value: 'string', + value: JSON.stringify({ + value: 'string', + }), }); }); From 65df094388e135419f4bf312b0071524f284e94f Mon Sep 17 00:00:00 2001 From: jochongs Date: Fri, 29 Mar 2024 22:31:04 +0900 Subject: [PATCH 2/2] test(microservices): Add kafka serialize test case --- .../serializers/kafka-request.serializer.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/microservices/test/serializers/kafka-request.serializer.spec.ts b/packages/microservices/test/serializers/kafka-request.serializer.spec.ts index f39f4169069..cc358915c08 100644 --- a/packages/microservices/test/serializers/kafka-request.serializer.spec.ts +++ b/packages/microservices/test/serializers/kafka-request.serializer.spec.ts @@ -103,6 +103,19 @@ describe('KafkaRequestSerializer', () => { }); }); + it('kafka message without value', async () => { + expect( + await instance.serialize({ + key: 'string', + }), + ).to.deep.eq({ + headers: {}, + value: JSON.stringify({ + key: 'string', + }), + }); + }); + it('kafka message with key', async () => { expect( await instance.serialize({