From 4f361284a2354404be93a3a31a74e28cb2f2270d Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Tue, 15 Aug 2023 00:41:42 +0200 Subject: [PATCH] add push batch test --- .../test/shared-aws/queue.inflight.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libs/wingsdk/test/shared-aws/queue.inflight.test.ts b/libs/wingsdk/test/shared-aws/queue.inflight.test.ts index dd98725c0e0..c1a3e7e47ef 100644 --- a/libs/wingsdk/test/shared-aws/queue.inflight.test.ts +++ b/libs/wingsdk/test/shared-aws/queue.inflight.test.ts @@ -8,6 +8,7 @@ import { import { mockClient } from "aws-sdk-client-mock"; import { test, expect, beforeEach } from "vitest"; import { QueueClient } from "../../src/shared-aws/queue.inflight"; +import "aws-sdk-client-mock-jest"; const sqsMock = mockClient(SQSClient); @@ -35,6 +36,37 @@ test("push - happy path", async () => { expect(response).toEqual(undefined); }); +test("push batch - happy path", async () => { + // GIVEN + const QUEUE_URL = "QUEUE_URL"; + const MESSAGES = ["MESSAGE1", "MESSAGE2", "MESSAGE3"]; + const RESPONSE = { + MessageId: "MESSAGE_ID", + }; + + sqsMock.on(SendMessageCommand).resolves(RESPONSE); + + // WHEN + const client = new QueueClient(QUEUE_URL); + const response = await client.push(...MESSAGES); + + // THEN + expect(response).toEqual(undefined); + expect(sqsMock).toHaveReceivedCommandTimes(SendMessageCommand, 3); + expect(sqsMock).toHaveReceivedNthCommandWith(1, SendMessageCommand, { + QueueUrl: QUEUE_URL, + MessageBody: MESSAGES[0], + }); + expect(sqsMock).toHaveReceivedNthCommandWith(2, SendMessageCommand, { + QueueUrl: QUEUE_URL, + MessageBody: MESSAGES[1], + }); + expect(sqsMock).toHaveReceivedNthCommandWith(3, SendMessageCommand, { + QueueUrl: QUEUE_URL, + MessageBody: MESSAGES[2], + }); +}); + test("purge - happy path", async () => { // GIVEN const QUEUE_URL = "QUEUE_URL";