-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp_test.js
95 lines (83 loc) · 2.98 KB
/
app_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
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
// @format
var request = require('supertest');
var prepareApp = require('../src/app.js');
var expect = require('expect.js');
var CachedCss = require('../src/models/CachedCss.js');
var redis = require('redis-mock');
var simple = require('simple-mock');
describe('app.js', function() {
describe('POST /api/v1/css', function() {
before(function() {
this.client = redis.createClient();
this.app = prepareApp({redis: this.client, queue: {add: simple.stub()}});
});
describe('with valid params', function() {
var params = {page: {key: 1, url: '/path', css: '/css'}};
describe('asking for item that is ready', function() {
before(function(done) {
this.cached = new CachedCss(this.client, params.page);
this.cached.finish('css {};', done);
});
it('should return a 200 and the content', function() {
return request(this.app)
.post('/api/v1/css')
.send(params)
.set('Content-Type', 'application/json')
.expect(200, 'css {};');
});
});
describe('asking for item that is new', function() {
var params = {page: {key: 2, url: '/path', css: '/css'}};
it('should return a 202', function() {
return request(this.app)
.post('/api/v1/css')
.send(params)
.set('Content-Type', 'application/json')
.expect(202);
});
});
describe('asking for item that is working', function() {
var params = {page: {key: 'working', url: '/path', css: '/css'}};
before(function(done) {
this.cached = new CachedCss(this.client, params.page);
this.cached.createStub(done);
});
it('should return a 202', function() {
return request(this.app)
.post('/api/v1/css')
.send(params)
.set('Content-Type', 'application/json')
.expect(202);
});
});
describe('asking for item that is waiting', function() {
var params = {page: {key: 'waiting', url: '/path', css: '/css'}};
before(function(done) {
this.cached = new CachedCss(this.client, params.page);
this.cached.begin(done);
});
it('should return a 202', function() {
return request(this.app)
.post('/api/v1/css')
.send(params)
.set('Content-Type', 'application/json')
.expect(202);
});
});
describe('asking for item that is failed', function() {
var params = {page: {key: 'failed', url: '/path', css: '/css'}};
before(function(done) {
this.cached = new CachedCss(this.client, params.page);
this.cached.failed(done);
});
it('should return a 202', function() {
return request(this.app)
.post('/api/v1/css')
.send(params)
.set('Content-Type', 'application/json')
.expect(202);
});
});
});
});
});