From d3b5662891ff6284ec07902d9120a79028f70b15 Mon Sep 17 00:00:00 2001 From: belovetech Date: Tue, 26 Sep 2023 09:47:23 +0100 Subject: [PATCH] (chore): fix rabbitmq connection error --- .../__tests__/message.queue.spec.ts | 54 ++++++++++--------- packages/shared-libs/package.json | 6 ++- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/packages/shared-libs/__tests__/message.queue.spec.ts b/packages/shared-libs/__tests__/message.queue.spec.ts index f8f255f..1154722 100644 --- a/packages/shared-libs/__tests__/message.queue.spec.ts +++ b/packages/shared-libs/__tests__/message.queue.spec.ts @@ -1,33 +1,37 @@ import { expect, describe, it, beforeAll, afterAll } from 'vitest'; import { MessageQueue } from '../src'; -describe('MessageQueue', () => { - let messageQueue: MessageQueue; +describe( + 'MessageQueue', + () => { + let messageQueue: MessageQueue; - beforeAll(() => { - messageQueue = new MessageQueue('amqp://localhost'); - }); + beforeAll(() => { + messageQueue = new MessageQueue('amqp://localhost'); + }); - afterAll(() => { - messageQueue.closeConnection(); - }); + afterAll(() => { + messageQueue.closeConnection(); + }); - it('should bind exchange with queue', async () => { - await messageQueue.bindExchangeWithQueue('Booking-Ticket', 'Booking'); - expect(messageQueue.queue).toBeDefined(); - expect(messageQueue.exchange).toBeDefined(); - }); + it('should bind exchange with queue', async () => { + await messageQueue.bindExchangeWithQueue('Booking-Ticket', 'Booking'); + expect(messageQueue.queue).toBeDefined(); + expect(messageQueue.exchange).toBeDefined(); + }); - it('should send and receive message', async () => { - const message = { data: 'hello world' }; - await messageQueue.sendMessage(message); - const receivedMessage = await messageQueue.getMessage(); - expect(receivedMessage).toEqual(message); - }); + it('should send and receive message', async () => { + const message = { data: 'hello world' }; + await messageQueue.sendMessage(message); + const receivedMessage = await messageQueue.getMessage(); + expect(receivedMessage).toEqual(message); + }); - it('should send message with retry', async () => { - const message = { data: 'hello world' }; - const result = await messageQueue.sendMessageWithRetry(message, 3); - expect(result).toEqual('DONE'); - }); -}); + it('should send message with retry', async () => { + const message = { data: 'hello world' }; + const result = await messageQueue.sendMessageWithRetry(message, 3); + expect(result).toEqual('DONE'); + }); + }, + { timeout: 20000 } +); diff --git a/packages/shared-libs/package.json b/packages/shared-libs/package.json index 3f61400..d10cdf6 100644 --- a/packages/shared-libs/package.json +++ b/packages/shared-libs/package.json @@ -19,7 +19,7 @@ ], "scripts": { "build": "rm -rf dist && tsc", - "test": "vitest --watch", + "test": "npm run docker-rabbitmq && vitest --watch", "ui:test": "vitest --ui", "lint": "npm run prettier:check && npm run eslint", "lint:fix": "npm run eslint:fix && npm run prettier:fix", @@ -27,7 +27,9 @@ "prettier:check": "npm run prettier:cli -- -l", "prettier:fix": "npm run prettier:cli -- --write", "eslint": "eslint --report-unused-disable-directives .", - "eslint:fix": "npm run eslint -- --fix" + "eslint:fix": "npm run eslint -- --fix", + "remove-rabbitmq-container": "docker rm -f rabbitmq", + "docker-rabbitmq": "npm run remove-rabbitmq-container && docker run -it -d --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.12-management" }, "devDependencies": { "@types/express": "^4.17.17",