forked from Tzinov15/swagger-bank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompleteTest.test.js
More file actions
109 lines (101 loc) · 4.38 KB
/
Copy pathcompleteTest.test.js
File metadata and controls
109 lines (101 loc) · 4.38 KB
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
108
109
/* global it, describe, before */
'use strict';
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const chaiSubset = require('chai-subset');
const fetch = require('node-fetch');
chai.use(chaiAsPromised);
chai.use(chaiSubset);
const SwaggerBank = require('../src/index');
describe('End to End Testing with multiple APIs', function () {
let slackAPI;
let contrivedSlackAPI;
before(function preValidateAPI () {
slackAPI = new SwaggerBank.API('./test/mockYamls/validSlack.yaml');
contrivedSlackAPI = new SwaggerBank.API('./test/mockYamls/miscSlack.yaml');
return Promise.all([slackAPI.validateAPI(), contrivedSlackAPI.validateAPI()]);
});
describe('Valid Slack API', function () {
before(function setEnvVar () {
process.env.PROP_GEN = 'static';
});
it('Should return a correct mocked response from a swagger spec after Swaggerbank has Run', function () {
return slackAPI.setupMountebankImposter(3002)
.then(function () {
return fetch('http://localhost:3002/api/channels.info')
.then(response => {
return response.text();
})
.then(body => {
return body.should.equal(JSON.stringify({'channel': {'created': 42, 'creator': 'ran string', 'id': 'ran string', 'is_archived': true, 'is_channel': true, 'is_general': true, 'is_member': true, 'last_read': 'ran string', 'latest': {'attachments': [{'fallback': 'ran string', 'from_url': 'ran string', 'id': 42, 'image_bytes': 42, 'image_height': 42, 'image_url': 'ran string', 'image_width': 42, 'service_name': 'ran string', 'text': 'ran string', 'title': 'ran string', 'title_link': 'ran string'}, {'fallback': 'ran string', 'from_url': 'ran string', 'id': 42, 'image_bytes': 42, 'image_height': 42, 'image_url': 'ran string', 'image_width': 42, 'service_name': 'ran string', 'text': 'ran string', 'title': 'ran string', 'title_link': 'ran string'}, {'fallback': 'ran string', 'from_url': 'ran string', 'id': 42, 'image_bytes': 42, 'image_height': 42, 'image_url': 'ran string', 'image_width': 42, 'service_name': 'ran string', 'text': 'ran string', 'title': 'ran string', 'title_link': 'ran string'}], 'text': 'ran string', 'ts': 'ran string', 'type': 'ran string', 'user': 'ran string'}, 'members': ['ran string', 'ran string', 'ran string'], 'name': 'ran string', 'purpose': {'creator': 'ran string', 'last_set': 42, 'value': 'ran string'}, 'topic': {'creator': 'ran string', 'last_set': 42, 'value': 'ran string'}, 'unread_count': 42, 'unread_count_display': 42}, 'ok': true}));
});
});
});
});
describe('Contrived Slack API', function () {
before(function setEnvVar () {
process.env.PROP_GEN = 'static';
return Promise.all([contrivedSlackAPI.setupMountebankImposter(3003)]);
});
it('setTopic route: Testing array of in place defined objects', function () {
return fetch('http://localhost:3003/api/channels.setTopic')
.then(response => {
return response.text();
})
.then(body => {
return body.should.equal(JSON.stringify(
{'topic': [
{
'ok': true,
'topic': 'ran string'
},
{
'ok': true,
'topic': 'ran string'
},
{
'ok': true,
'topic': 'ran string'
}
]}
));
});
});
it('users route: Testing array of referenced objects', function () {
return fetch('http://localhost:3003/api/users')
.then(response => {
return response.text();
})
.then(body => {
return body.should.equal(JSON.stringify(
{'userList': [
{
'ok': true,
'team': 'ran string',
'team_id': 'ran string',
'url': 'ran string',
'user': 'ran string',
'user_id': 'ran string'
},
{
'ok': true,
'team': 'ran string',
'team_id': 'ran string',
'url': 'ran string',
'user': 'ran string',
'user_id': 'ran string'
},
{
'ok': true,
'team': 'ran string',
'team_id': 'ran string',
'url': 'ran string',
'user': 'ran string',
'user_id': 'ran string'
}
]}
));
});
});
});
});