-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchakram.js
72 lines (65 loc) · 2.53 KB
/
chakram.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
let chakram = require('chakram');
expect = chakram.expect;
describe("HTTP assertions", function () {
it("should make HTTP assertions easy", function () {
let response = chakram.get("http://httpbin.org/get?test=chakram");
expect(response).to.have.status(200);
expect(response).to.have.header("content-type", "application/json");
expect(response).not.to.be.encoded.with.gzip;
expect(response).to.comprise.of.json({
args: { test: "chakram" }
});
return chakram.wait();
});
});
xdescribe("Promises", function () {
it("should support asserting Biggie's best track", function () {
let artist = "Notorious B.I.G.";
return chakram.get("https://api.spotify.com/v1/search?q="+artist+"&type=artist")
.then(function (searchResponse) {
let bigID = searchResponse.body.artists.items[0].id;
return chakram.get("https://api.spotify.com/v1/artists/"+bigID+"/top-tracks?country=GB");
})
.then(function (topTrackResponse) {
let topTrack = topTrackResponse.body.tracks[0];
expect(topTrack.name).to.contain("Old Thing Back");
});
});
});
describe("BDD + Hooks", function () {
let thingName;
before("post dweet", function () {
thingName = "chakramtest" + Math.floor(Math.random()*2000);
return chakram.post("https://dweet.io/dweet/for/"+thingName, {
testing: "your API"
});
});
it("should support getting latest dweet", function () {
let postedData = chakram.get("https://dweet.io/get/latest/dweet/for/"+thingName);
return expect(postedData).to.have.json('with[0].content', {
testing: "your API"
});
});
after("update dweet with result", function () {
return chakram.post("https://dweet.io/dweet/for/" + thingName, {
testing: "passed"
});
});
});
describe("Extensibility", function () {
before("define teapot", function () {
chakram.addProperty("teapot", function (respObj) {
let statusCode = respObj.response.statusCode;
this.assert(statusCode === 418,
'expected status code ' + statusCode + ' to equal 418',
'expected ' + statusCode + ' to not be equal to 418');
});
});
it("should be able to detect teapots", function () {
let notATeapot = chakram.get("http://httpbin.org/status/200");
let aTeapot = chakram.get("http://httpbin.org/status/418");
expect(notATeapot).to.not.be.teapot;
expect(aTeapot).to.be.teapot;
return chakram.wait();
});
});