|
| 1 | +var should = require('should') |
| 2 | + , assert = require('assert') |
| 3 | + , request = require('supertest') |
| 4 | + , mongoose = require('mongoose-q')() |
| 5 | + , winston = require('winston') |
| 6 | + , db = mongoose.connection |
| 7 | + , superagent = require('superagent') |
| 8 | + , agent = superagent.agent() |
| 9 | + |
| 10 | +var Fleet = require('../lib/models/fleet') |
| 11 | + |
| 12 | +describe('Fleet API: Create', function() { |
| 13 | + var url = 'http://0.0.0.0:5000/api'; |
| 14 | + var igb_headers = require('./fixtures/tarei-ju-.json'); |
| 15 | + |
| 16 | + describe('Invalid', function() { |
| 17 | + |
| 18 | + afterEach(function(done) { |
| 19 | + Fleet.find(function(err, fleets) { |
| 20 | + fleets.should.be.empty; |
| 21 | + done(); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should catch invalid sessions', function(done) { |
| 26 | + request(url) |
| 27 | + .post('/fleet/create') |
| 28 | + .expect(200) |
| 29 | + .end(function(err, res) { |
| 30 | + if (err) return done(err); |
| 31 | + res.body.success.should.not.be.ok; |
| 32 | + res.body.error.message.should.match(/You do not seem to be running the IGB, or your request was corrupted/); |
| 33 | + done(); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should not create a fleet a short password', function(done) { |
| 38 | + request(url) |
| 39 | + .post('/fleet/create') |
| 40 | + .set(igb_headers) |
| 41 | + .send({fleetPassword: 'oi'}) |
| 42 | + .expect(200) |
| 43 | + .end(function(err,res) { |
| 44 | + if (err) return done(err); |
| 45 | + res.body.success.should.not.be.ok; |
| 46 | + res.body.error.message.should.match(/Invalid password/); |
| 47 | + |
| 48 | + done(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should not create a fleet a long password', function(done) { |
| 53 | + request(url) |
| 54 | + .post('/fleet/create') |
| 55 | + .set(igb_headers) |
| 56 | + .send({fleetPassword: '7d6fec0cdf6d154618c40c9013f1732393548d9b'}) |
| 57 | + .expect(200) |
| 58 | + .end(function(err,res) { |
| 59 | + if (err) return done(err); |
| 60 | + res.body.success.should.not.be.ok; |
| 61 | + res.body.error.message.should.match(/Invalid password/); |
| 62 | + |
| 63 | + done(); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + }); |
| 68 | + |
| 69 | + describe('Valid', function() { |
| 70 | + |
| 71 | + afterEach(function(done) { |
| 72 | + Fleet.find(function(err, fleets) { |
| 73 | + fleets.length.should.eql(1, 'should only create one fleet'); |
| 74 | + done(); |
| 75 | + }) |
| 76 | + }); |
| 77 | + |
| 78 | + it('should create a fleet without a password', function(done) { |
| 79 | + request(url) |
| 80 | + .post('/fleet/create') |
| 81 | + .set(igb_headers) |
| 82 | + .expect(200) |
| 83 | + .end(function(err,res) { |
| 84 | + if (err) return done(err); |
| 85 | + res.body.success.should.be.ok; |
| 86 | + res.body.events.should.have.property('type', 'fleetCreated'); |
| 87 | + res.body.events.data.should.have.property('key'); |
| 88 | + res.body.events.data.should.have.property('password', false); |
| 89 | + |
| 90 | + done(); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should create a fleet with a password', function(done) { |
| 95 | + request(url) |
| 96 | + .post('/fleet/create') |
| 97 | + .set(igb_headers) |
| 98 | + .send({fleetPassword: 'dongues'}) |
| 99 | + .expect(200) |
| 100 | + .end(function(err,res) { |
| 101 | + if (err) return done(err); |
| 102 | + res.body.success.should.be.ok; |
| 103 | + res.body.events.should.have.property('type', 'fleetCreated'); |
| 104 | + res.body.events.data.should.have.property('key'); |
| 105 | + res.body.events.data.should.have.property('password', 'dongues'); |
| 106 | + |
| 107 | + done(); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + // it('should not create a fleet if one is already joined', function(done) { |
| 112 | + // request(url) |
| 113 | + // .post('/fleet/create') |
| 114 | + // .set(igb_headers) |
| 115 | + // .expect(200) |
| 116 | + // .end(function(err, res) { |
| 117 | + // if (err) return done(err); |
| 118 | + // res.body.success.should.be.ok; |
| 119 | + // agent.saveCookies(res); |
| 120 | + // |
| 121 | + // var req = request(url) |
| 122 | + // .post('/fleet/create') |
| 123 | + // .set(igb_headers); |
| 124 | + // |
| 125 | + // agent.attachCookies(req); |
| 126 | + // |
| 127 | + // req.expect(200) |
| 128 | + // .end(function(err, res) { |
| 129 | + // if (err) return done(err); |
| 130 | + // debugger; |
| 131 | + // res.body.success.should.not.be.ok; |
| 132 | + // res.body.error.message.should.match(/Please leave your current fleet before creating a new one/); |
| 133 | + // done(); |
| 134 | + // }); |
| 135 | + // }); |
| 136 | + // }); |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + }); |
| 141 | + |
| 142 | +}); |
0 commit comments