-
Notifications
You must be signed in to change notification settings - Fork 30
/
updateApiResponses.spec.js
107 lines (91 loc) · 3.16 KB
/
updateApiResponses.spec.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
const assert = require('assert');
const {BotMock, SlackApiMock} = require('../../lib');
const {SlackAdapter, SlackMessageTypeMiddleware, SlackEventMiddleware} = require('botbuilder-adapter-slack/lib/index');
describe('Slack API responses', function () {
beforeEach(async () => {
const adapter = new SlackAdapter(SlackApiMock.slackAdapterMockParams);
adapter.use(new SlackEventMiddleware());
adapter.use(new SlackMessageTypeMiddleware());
this.controller = new BotMock({
adapter: adapter,
disable_webserver: true
});
SlackApiMock.bindMockApi(this.controller);
this.bot = await this.controller.spawn('some team');
// or
// this.bot = await this.controller.spawn(BotMock.defaultFields.TEAM);
});
describe('default responses', () => {
it('should return data.ok for users.list call', async () => {
const response = await this.bot.api.users.list();
assert.strictEqual(response.ok, true);
});
it('should return data.ok for channels.info call', async () => {
const response = await this.bot.api.channels.info({});
assert.deepStrictEqual(response.ok, true);
});
});
describe('change response data for actions', () => {
describe('success response', () => {
const usersListResponse = {
ok: true,
members: [{id: '2'}],
response_metadata: {}
};
const channelsInfoResponse = {
ok: true,
channel1: {id: '2'},
response_metadata: {}
};
beforeEach(() => {
this.controller.axiosMockAdapter.onPost('users.list').reply(200, usersListResponse);
this.controller.axiosMockAdapter.onPost('channels.info').reply(200, channelsInfoResponse);
});
it('should return newly changed api data in users.list call', async () => {
const response = await this.bot.api.users.list();
assert.deepStrictEqual(response, usersListResponse);
});
it('should return newly changed api data in channels.info call', async () => {
const response = await this.bot.api.channels.info();
assert.deepStrictEqual(response, channelsInfoResponse);
});
});
describe('error response', () => {
const usersListResponse = {
ok: false,
error: 'not_authed',
response_metadata: {}
};
const channelsInfoResponse = {
ok: false,
error: 'channel_not_found',
response_metadata: {}
};
beforeEach(() => {
this.controller.axiosMockAdapter.onPost('users.list').reply(200, usersListResponse);
this.controller.axiosMockAdapter.onPost('channels.info').reply(200, channelsInfoResponse);
});
it('should return newly changed api data in users.list call', async () => {
let error = '';
try {
await this.bot.api.users.list()
} catch (err) {
error = err;
}
assert.strictEqual(error.toString(), 'Error: An API error occurred: not_authed');
assert.deepStrictEqual(error.data, usersListResponse);
});
it('should return newly changed api data in channels.info call', async () => {
let error = '';
try {
await this.bot.api.channels.info()
} catch (err) {
error = err;
}
assert.strictEqual(error.toString(), 'Error: An API error occurred: channel_not_found');
assert.deepStrictEqual(error.data, channelsInfoResponse);
});
});
});
});