From a6d9e1e5ad5d8c5ad28b66d8a843f5baac510e1c Mon Sep 17 00:00:00 2001 From: Andrew Ivanov Date: Thu, 27 Jun 2024 14:25:05 +0300 Subject: [PATCH 1/2] Add ZodError matching for AMQP consumer test --- .../consumers/AmqpPermissionConsumer.spec.ts | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts b/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts index 1ab63979..7c7dd082 100644 --- a/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts +++ b/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts @@ -299,12 +299,33 @@ describe('AmqpPermissionConsumer', () => { }) it('Invalid message in the queue', async () => { + const invalidMessage = { + id: 1, // invalid type + messageType: 'add', + } + + expect(() => + // @ts-ignore + publisher.publish(invalidMessage), + ).toThrowErrorMatchingInlineSnapshot( + ` + [ZodError: [ + { + "code": "invalid_type", + "expected": "string", + "received": "number", + "path": [ + "id" + ], + "message": "Expected string, received number" + } + ]] + `, + ) + channel.sendToQueue( AmqpPermissionConsumer.QUEUE_NAME, - objectToBuffer({ - id: 1, // invalid type - messageType: 'add', - }), + objectToBuffer(invalidMessage), ) await waitAndRetry(() => consumerErrorResolver.errors.length > 0) From 316bc44e71d2ca9350ec816117a44430c213e2cf Mon Sep 17 00:00:00 2001 From: Andrew Ivanov Date: Thu, 27 Jun 2024 15:40:38 +0300 Subject: [PATCH 2/2] Lint fix --- .../amqp/test/consumers/AmqpPermissionConsumer.spec.ts | 7 ++----- packages/sqs/lib/utils/sqsUtils.ts | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts b/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts index 7c7dd082..469d2eb2 100644 --- a/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts +++ b/packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts @@ -308,7 +308,7 @@ describe('AmqpPermissionConsumer', () => { // @ts-ignore publisher.publish(invalidMessage), ).toThrowErrorMatchingInlineSnapshot( - ` + ` [ZodError: [ { "code": "invalid_type", @@ -323,10 +323,7 @@ describe('AmqpPermissionConsumer', () => { `, ) - channel.sendToQueue( - AmqpPermissionConsumer.QUEUE_NAME, - objectToBuffer(invalidMessage), - ) + channel.sendToQueue(AmqpPermissionConsumer.QUEUE_NAME, objectToBuffer(invalidMessage)) await waitAndRetry(() => consumerErrorResolver.errors.length > 0) diff --git a/packages/sqs/lib/utils/sqsUtils.ts b/packages/sqs/lib/utils/sqsUtils.ts index c474087b..d4dd507f 100644 --- a/packages/sqs/lib/utils/sqsUtils.ts +++ b/packages/sqs/lib/utils/sqsUtils.ts @@ -12,7 +12,8 @@ import type { QueueAttributeName, SendMessageCommandInput, } from '@aws-sdk/client-sqs' -import {Either, globalLogger} from '@lokalise/node-core' +import type { Either} from '@lokalise/node-core'; +import { globalLogger } from '@lokalise/node-core' import { isShallowSubset, waitAndRetry } from '@message-queue-toolkit/core' import type { ExtraSQSCreationParams, SQSQueueLocatorType } from '../sqs/AbstractSqsService'