This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfleet-create.js
More file actions
158 lines (135 loc) · 4.51 KB
/
Copy pathfleet-create.js
File metadata and controls
158 lines (135 loc) · 4.51 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var server = require('../server')
, should = require('should')
, assert = require('assert')
, request = require('supertest')
, mongoose = require('mongoose-q')()
, winston = require('winston')
, db = mongoose.connection
, Q = require('q')
, session = require('supertest-session')({app: server.app})
var Fleet = require('../server/models/fleet')
describe('Fleet API: Create', function() {
var url = 'http://0.0.0.0:5000/api';
var igb_headers = require('./fixtures/tarei-ju-.json');
describe('Invalid', function() {
beforeEach(function(done) {
Q.all([
db.models.Fleet.remove().execQ(),
db.models.Member.remove().execQ(),
db.models.Event.remove().execQ(),
db.models.Session.remove().execQ()
])
.fin(done);
});
it('should catch invalid sessions', function(done) {
request(url)
.post('/fleet/create')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
res.body.success.should.not.be.ok;
res.body.error.message.should.match(/You do not seem to be running the IGB, or your request was corrupted/);
done();
});
});
it('should not create a fleet a short password', function(done) {
request(url)
.post('/fleet/create')
.set(igb_headers)
.send({fleetPassword: 'oi'})
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.not.be.ok;
res.body.error.message.should.match(/Invalid password/);
done();
});
});
it('should not create a fleet a long password', function(done) {
request(url)
.post('/fleet/create')
.set(igb_headers)
.send({fleetPassword: '7d6fec0cdf6d154618c40c9013f1732393548d9b'})
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.not.be.ok;
res.body.error.message.should.match(/Invalid password/);
done();
});
});
});
describe('Valid', function() {
beforeEach(function(done) {
Q.all([
db.models.Fleet.remove().execQ(),
db.models.Member.remove().execQ(),
db.models.Event.remove().execQ(),
db.models.Session.remove().execQ()
])
.fin(done);
});
afterEach(function(done) {
Fleet.find(function(err, fleets) {
fleets.length.should.eql(1, 'should only create one fleet');
done();
})
});
it('should create a fleet without a password', function(done) {
request(url)
.post('/fleet/create')
.set(igb_headers)
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.be.ok;
res.body.events.should.have.property('type', 'fleetCreated');
res.body.events.data.should.have.property('key');
res.body.events.data.should.have.property('password', false);
done();
});
});
it('should create a fleet with a password', function(done) {
request(url)
.post('/fleet/create')
.set(igb_headers)
.send({fleetPassword: 'dongues'})
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.be.ok;
res.body.events.should.have.property('type', 'fleetCreated');
res.body.events.data.should.have.property('key');
res.body.events.data.should.have.property('password', 'dongues');
done();
});
describe('should not create a fleet if one already exists', function() {
before(function() { this.sess = new session(); });
after(function() { this.sess.destroy(); });
it('creating a fleet should succeed', function(done) {
this.sess
.post('/api/fleet/create')
.set(igb_headers)
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.be.ok;
done();
});
});
it('creating another fleet should error', function(done) {
this.sess
.post('/api/fleet/create')
.set(igb_headers)
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.not.be.ok;
res.body.error.message.should.match(/Please leave your current fleet before creating a new one/);
done();
});
});
});
});
});
});