Skip to content

Commit

Permalink
test: send to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
DIY0R committed Jul 1, 2024
1 parent ed05d58 commit 029298a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
15 changes: 11 additions & 4 deletions test/mocks/rmq-nestjs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import { RmqServieController } from './rmq.controller';
exchange: {
exchange: 'for-test',
type: 'topic',
options: { durable: true },
options: {
durable: true,
autoDelete: true,
},
},
queue: {
queue: 'test-for',
options: { durable: true, autoDelete: true },
consumOptions: { noAck: true },
},
queue: { queue: 'test-for', options: { durable: true } },
replyTo: {
queue: '',
options: { durable: true },
consumOptions: { noAck: false },
options: { exclusive: true },
consumOptions: { noAck: true },
},
}),
],
Expand Down
13 changes: 9 additions & 4 deletions test/mocks/rmq.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ export class RmqServieController {
private readonly rmqGlobalService: RmqGlobalService,
) {}

async sendMessage(obj: any, topic: string = 'text.text') {
async sendMessage(obj: Record<string, any>, topic: string = 'text.text') {
const sendhi = await this.rmqServie.send<object, { message: object }>(
topic,
obj,
);
return sendhi;
}

async sendNonRoute(obj: any) {
async sendNonRoute(obj: Record<string, any>) {
const message = await this.rmqServie.send<object, { message: object }>(
'text.text.text',
obj,
);
return message;
}
async sendGlobalRoute(obj: any) {
async sendGlobalRoute(obj: Record<string, any>) {
console.log('----sendGlobalRoutesendGlobalRoutesendGlobalRoute-->');
const message = await this.rmqGlobalService.send<
object,
Expand All @@ -33,12 +33,17 @@ export class RmqServieController {
return message;
}

sendNotify(obj: any) {
sendNotify(obj: Record<string, any>) {
const message = this.rmqGlobalService.notify<object>(
'for-test',
'rpc.notify',
obj,
);
return message;
}

sendToQueue(queue: string, obj: Record<string, any>) {
const status = this.rmqGlobalService.sendToQueue<object>(queue, obj);
return status;
}
}
22 changes: 12 additions & 10 deletions test/rmq-nestjs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe('RMQe2e', () => {
password: 'for-test',
hostname: 'localhost',
port: 5672,
vhost: '/',
vhost: 'local',
protocol: 'amqp',
},
{
globalBroker: {
replyTo: {
queue: 'RmqNestj1111sModuleGlobalQueue',
queue: '',
options: { exclusive: true },
consumOptions: { noAck: false },
consumOptions: { noAck: true },
},
messageTimeout: 50000,
serviceName: 'global srvice',
Expand All @@ -52,7 +52,7 @@ describe('RMQe2e', () => {
const isConnected = rmqService.healthCheck();
expect(isConnected).toBe(true);
});
describe('rpc', () => {
describe('rpc exchange', () => {
it('successful global send()', async () => {
const obj = { time: '001', fulled: 12 };
const { message } = await rmqServieController.sendGlobalRoute(obj);
Expand All @@ -69,11 +69,7 @@ describe('RMQe2e', () => {
const { message } = await rmqServieController.sendMessage(obj, topic);
expect(message).toEqual(obj);
});
it('cant find route', async () => {
const obj = { time: 1 };
const message = await rmqServieController.sendNonRoute(obj);
expect(message).toEqual({ error: ERROR_NO_ROUTE });
});

it('send topic patern #1 "*"', async () => {
const obj = { time: 1 };
const topic = 'message.text.rpc';
Expand All @@ -87,7 +83,13 @@ describe('RMQe2e', () => {
expect(message).toEqual(obj);
});
});

describe('send message to queue', () => {
it('send to Queue', () => {
const obj = { aq: 1121 };
const status = rmqServieController.sendToQueue('test-for', obj);
expect(status).toBeTruthy();
});
});
afterAll(async () => {
await delay(500);
await api.close();
Expand Down

0 comments on commit 029298a

Please sign in to comment.