-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
111 lines (73 loc) · 1.75 KB
/
Copy pathtest.js
File metadata and controls
111 lines (73 loc) · 1.75 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
110
var req = require('supertest');
var app = require('./app');
var redis = require('redis');
var client = redis.createClient();
client.select('test'.length);
client.flushdb();
describe('Requests to root path', function(){
it('Returns a 200 status code', function(done){
req(app)
.get('/')
.expect(200, done);
});
it('Returns HTML format', function(done){
req(app)
.get('/')
.expect('Content-Type', /html/, done);
});
it('Returns an index file with Cities', function(done){
req(app)
.get('/')
.expect(/cities/i, done);
});
});
describe('Listing cities on /cities', function(){
it('Returns a 200 status code', function(done){
req(app)
.get('/cities')
.expect(200, done);
});
it('Returns JSON format', function(done){
req(app)
.get('/cities')
.expect('Content-Type', /json/, done);
});
it('Returns initial cities', function(done){
req(app)
.get('/cities')
.expect(JSON.stringify([]), done);
});
});
describe('Creating new cities', function(){
it('Returns a 201 status code', function(done){
req(app)
.post('/cities')
.send('name=Springfield&description=where+the+simpsons+live')
.expect(201, done);
});
it('Returns city name', function(done){
req(app)
.post('/cities')
.send('name=Springfield&description=where+the+simpsons+live')
.expect(/Springfield/i, done);
});
it('Validates city name and description', function(done){
req(app)
.post('/cities')
.send('name=&description=')
.expect(400, done);
});
});
describe('Deleting a city', function(){
before(function(){
client.hset('cities', 'Banana', 'a tasty fruit');
});
after(function(){
client.flushdb();
});
it('Returns a 204 status code', function(done){
req(app)
.delete('/cities/Banana')
.expect(204, done);
});
});