forked from DAVFoundation/dav-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.test.js
62 lines (61 loc) · 3.19 KB
/
Message.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Config_1 = require("./Config");
const MessageParams_1 = require("./drone-charging/MessageParams");
describe('Message class', () => {
const configuration = new Config_1.default({});
const messageContent = new MessageParams_1.default({ senderId: 'peerId' });
const selfId = 'selfId';
describe('respond method', () => {
const kafkaError = { msg: 'KAFKA_ERROR' };
beforeEach(() => {
jest.resetAllMocks();
jest.resetModules();
});
it('should succeed, validate kafka mock send message', async () => {
const kafkaMock = {
sendParams: () => Promise.resolve(true),
};
jest.doMock('./Kafka', () => ({ default: kafkaMock }));
// tslint:disable-next-line:variable-name
const Message = (await Promise.resolve().then(() => require('./Message'))).default;
const message = new Message(selfId, messageContent, configuration);
await expect(message.respond(new MessageParams_1.default({ senderId: selfId }))).resolves.toBeDefined();
});
it('should fail due to kafka exception', async () => {
const kafkaMock = {
sendParams: () => Promise.reject(kafkaError),
};
jest.doMock('./Kafka', () => ({ default: kafkaMock }));
// tslint:disable-next-line:variable-name
const Message = (await Promise.resolve().then(() => require('./Message'))).default;
const message = new Message(selfId, messageContent, configuration);
await expect(message.respond(new MessageParams_1.default({ senderId: selfId }))).rejects.toBe(kafkaError);
});
it('should call to Kafka sendParams', async () => {
const kafkaMock = {
sendParams: jest.fn(() => Promise.resolve(true)),
};
jest.doMock('./Kafka', () => ({ default: kafkaMock }));
// tslint:disable-next-line:variable-name
const Message = (await Promise.resolve().then(() => require('./Message'))).default;
const message = new Message(selfId, messageContent, configuration);
const messageParams = new MessageParams_1.default({});
await message.respond(messageParams);
expect(kafkaMock.sendParams).toHaveBeenCalledWith('peerId', messageParams, configuration);
});
it('should call to Kafka sendParams with message params that contain selfId', async () => {
const kafkaMock = {
sendParams: jest.fn(params => Promise.resolve(true)),
};
jest.doMock('./Kafka', () => ({ default: kafkaMock }));
// tslint:disable-next-line:variable-name
const Message = (await Promise.resolve().then(() => require('./Message'))).default;
const message = new Message(selfId, messageContent, configuration);
const messageParams = new MessageParams_1.default({});
await message.respond(messageParams);
expect(kafkaMock.sendParams.mock.calls[0][1].senderId).toBe(selfId);
});
});
});
//# sourceMappingURL=Message.test.js.map