UNPKG

mqrpc

Version:

💫 Easy RPC over RabbitMQ

29 lines (28 loc) • 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ava_1 = require("ava"); const sinon = require("sinon"); const _config_1 = require("../../_config"); const AmqpClient_1 = require("../../../lib/AmqpClient"); const comms_1 = require("../../../lib/RpcServer/comms"); const sampleMessage = { fields: { deliveryTag: 1234567890987654321 }, properties: { replyTo: 'amqp.rabbitmq.reply-to', correlationId: '123456', deliveryMode: 2 } }; const amqpClient = new AmqpClient_1.default({ amqpUrl: _config_1.AMQP_URL }); ava_1.default.before(() => amqpClient.init()); ava_1.default.after.always(() => amqpClient.term()); ava_1.default.beforeEach(t => t.context.sandbox = sinon.sandbox.create()); ava_1.default.afterEach.always(t => t.context.sandbox.restore()); ava_1.default.serial('[unit] #ack sends an ack message to the client', async (t) => { const spy = t.context.sandbox.spy(amqpClient.channel, 'publish'); await comms_1.ack(amqpClient.channel, sampleMessage); sinon.assert.calledWith(spy, '', 'amqp.rabbitmq.reply-to', new Buffer('{"type":"ack"}'), { correlationId: '123456', deliveryMode: 2 }); t.pass(); }); ava_1.default.serial('[unit] #wait sends a wait message to the client', async (t) => { const spy = t.context.sandbox.spy(amqpClient.channel, 'publish'); await comms_1.wait(amqpClient.channel, sampleMessage); sinon.assert.calledWith(spy, '', 'amqp.rabbitmq.reply-to', new Buffer('{"type":"wait"}'), { correlationId: '123456', deliveryMode: 2 }); t.pass(); });