-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_spec.js
40 lines (32 loc) · 969 Bytes
/
test_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
var fs = require('fs');
var frisby = require('frisby');
var Parser = require('blueprint-parser');
function test(filename) {
var str = fs.readFileSync(filename,'UTF8');
var doc = Parser.parse(str);
doc.sections.forEach(function(s) {
testSection(doc,s);
});
}
function testSection(doc,s) {
s.resources.forEach(function(r) {
testResource(doc,r);
});
}
function testResource(doc,r) {
var t = frisby.create(r.description);
t[r.method.toLowerCase()](doc.location+r.url);
var header, headers = r.request.headers;
for (header in headers) {
t.addHeader(header, headers[header]);
}
var response = r.responses[0];
if (response) {
for (header in response.headers) {
t.expectHeaderContains(header.toLowerCase(), response.headers[header]);
}
t.expectJSON(JSON.parse(response.body));
}
t.toss();
}
test('sample.blp');