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-status.js
More file actions
93 lines (79 loc) · 2.82 KB
/
Copy pathfleet-status.js
File metadata and controls
93 lines (79 loc) · 2.82 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
var server = require('../server')
, should = require('should')
, assert = require('assert')
, request = require('supertest')
, mongoose = require('mongoose-q')()
, winston = require('winston')
, Q = require('q')
, db = mongoose.connection
, session = require('supertest-session')({app: server.app})
var Fleet = require('../server/models/fleet')
, Member = require('../server/models/member')
, Event = require('../server/models/event')
describe('Fleet API: Status', 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 headers', function(done) {
request(url)
.get('/fleet/status')
.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 catch invalid sessions', function(done) {
request(url)
.get('/fleet/status')
.set(igb_headers)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
res.body.success.should.be.ok;
res.body.should.have.property('events').with.lengthOf(1);
res.body.events[0].should.have.property('type', 'statusSelf');
done();
});
});
});
describe('Should send status update events', function() {
before(function() { this.sess = new session(); });
after(function() { this.sess.destroy(); });
it('creating a fleet', function(done) {
this.sess
.post('/api/fleet/create')
.set(igb_headers)
.expect(200, done)
});
it('when checking fleet status', function(done) {
this.sess
.get('/api/fleet/status')
.set(igb_headers)
.expect(200)
.end(function(err,res) {
if (err) return done(err);
res.body.success.should.be.ok;
res.body.should.have.property('events').with.lengthOf(6);
res.body.events[0].should.have.property('type', 'statusSelf');
res.body.events[1].should.have.property('type', 'statusFleet');
res.body.events[2].should.have.property('type', 'statusEvents');
res.body.events[3].should.have.property('type', 'statusMembers');
res.body.events[4].should.have.property('type', 'statusHostiles');
res.body.events[5].should.have.property('type', 'statusScans');
done();
});
});
});
});