Skip to content

Commit

Permalink
Merge branch 'master' into tests-db-tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo committed Aug 14, 2017
2 parents 8d71b58 + a1fec51 commit d659ce1
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 128 deletions.
2 changes: 1 addition & 1 deletion tests/enforceToken/collector/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe(`api: POST ${path}`, () => {
const deRegisterPath = `/v1/collectors/${res.body.id}/deregister`;
return Collector.destroy({
where: {},
truncate: true
truncate: true,
})
.then(() => {
api.post(deRegisterPath)
Expand Down
18 changes: 3 additions & 15 deletions tests/enforceToken/createToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('api: createToken', () => {
.send(u.fakeUserCredentials)
.end((err, res) => {
if (err) {
done(err);
return done(err);
}

defaultToken = res.body.token;
Expand All @@ -40,13 +40,7 @@ describe('api: createToken', () => {
.send({ name: 'newToken' })
.expect(constants.httpStatus.FORBIDDEN)
.expect(/No authorization token was found/)
.end((err) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});

it('error if wrong token found provided', (done) => {
Expand All @@ -55,13 +49,7 @@ describe('api: createToken', () => {
.send({ name: 'newToken' })
.expect(constants.httpStatus.FORBIDDEN)
.expect(/Invalid Token/)
.end((err) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});

it('sucessful authentication, create token for user', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/enforceToken/revoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('enforceToken: revoke:', () => {
.send(u.fakeUserCredentials)
.end((err, res) => {
if (err) {
done(err);
return done(err);
}

defaultToken = res.body.token;
Expand Down
17 changes: 2 additions & 15 deletions tests/enforceToken/sampleUpsertBulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* tests/tokenReq/sampleUpsertBulk.js
*/
'use strict';

const expect = require('chai').expect;
const supertest = require('supertest');
const api = supertest(require('../../index').app);
Expand Down Expand Up @@ -81,13 +80,7 @@ describe('api: POST ' + path, () => {
])
.expect(constants.httpStatus.FORBIDDEN)
.expect(/ForbiddenError/)
.end((err /* , res */) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});

it('all succeed', (done) => {
Expand All @@ -103,12 +96,6 @@ describe('api: POST ' + path, () => {
},
])
.expect(constants.httpStatus.OK)
.end((err /* , res */) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});
});
21 changes: 4 additions & 17 deletions tests/enforceToken/subjectGetHierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* tests/tokenReq/subjectGetHierarchy.js
*/
'use strict';

const supertest = require('supertest');
const api = supertest(require('../../index').app);
const constants = require('../../api/v1/constants');
Expand Down Expand Up @@ -46,7 +45,7 @@ describe(`api: GET ${path}`, () => {
token = returnedToken;
done();
})
.catch((err) => done(err));
.catch(done);
});

before((done) => {
Expand Down Expand Up @@ -82,7 +81,7 @@ describe(`api: GET ${path}`, () => {
password: 'abcd',
}))
.then(() => done())
.catch((err) => done(err));
.catch(done);
});

after(u.forceDelete);
Expand All @@ -93,13 +92,7 @@ describe(`api: GET ${path}`, () => {
api.get(path.replace('{key}', ipar))
.expect(constants.httpStatus.FORBIDDEN)
.expect(/ForbiddenError/)
.end((err /* , res */) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});
it('should be an empty object at the parent level (with token)', (done) => {
api.get(path.replace('{key}', ipar))
Expand All @@ -109,13 +102,7 @@ describe(`api: GET ${path}`, () => {
expect(res.body.samples).to.be.an('array');
expect(res.body.samples).to.be.empty;
})
.end((err /* , res */) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});
});
});
28 changes: 5 additions & 23 deletions tests/enforceToken/verbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ describe('API verb token enforced tests', () => {
it('GET docs without token should succeed', (done) => {
api.get('/v1/docs/')
.expect(constants.httpStatus.OK)
.end((err /* , res */) => {
if (err) {
done(err);
}

done();
});
.end(done);
});

describe('CRUD should require tokens', () => {
Expand All @@ -45,7 +39,7 @@ describe('API verb token enforced tests', () => {
.expect(constants.httpStatus.CREATED)
.end((err, res) => {
if (err) {
done(err);
return done(err);
}

expect(res.body.token).to.be.defined;
Expand All @@ -64,7 +58,7 @@ describe('API verb token enforced tests', () => {
.expect(constants.httpStatus.CREATED)
.end((err, res) => {
if (err) {
done(err);
return done(err);
}

expect(res.body.name).to.equal(NEW_SUBJECT);
Expand Down Expand Up @@ -114,13 +108,7 @@ describe('API verb token enforced tests', () => {
.set('Authorization', `${defaultToken}xyz`)
.expect(FORBIDDEN)
.expect(/Invalid Token/)
.end((err) => {
if (err) {
done(err);
}

done();
});
.end(done);
});

it(`${VERB} ${path} appropriate token returns OK`, (done) => {
Expand All @@ -133,13 +121,7 @@ describe('API verb token enforced tests', () => {
call
.set('Authorization', defaultToken)
.expect(expectedStatus)
.end((err) => {
if (err) {
done(err);
}

done();
});
.end(done);
});
}

Expand Down
3 changes: 1 addition & 2 deletions tests/realtime/realtimeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* tests/realtime/realtimeUtils.js
*/
'use strict';

const expect = require('chai').expect;
const realtimeUtils = require('../../realtime/utils');
const tu = require('../testUtils');
Expand Down Expand Up @@ -91,7 +90,7 @@ describe('realtime utils Tests:', () => {
subjectTagFilter: ['ea', 'na'],
subjectTagFilterType: 'INCLUDE',
statusFilter: ['OK'],
statusFilterType: 'INCLUDE'
statusFilterType: 'INCLUDE',
});
})
.then((pers2) => {
Expand Down
26 changes: 14 additions & 12 deletions tests/realtime/redisPublisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* tests/realtime/redisPublisher.js
*/
'use strict';

const expect = require('chai').expect;
const tu = require('../testUtils');
const u = require('./utils');
Expand Down Expand Up @@ -66,8 +65,8 @@ describe('publishSample with redis cache on', () => {
afterEach(rtu.flushRedis);
after(() => tu.toggleOverride('enableRedisSampleStore', false));

it('certain fields in aspect should be array, and others' +
' should be undefined', (done) => {
it('certain fields in aspect should be array, and others ' +
'should be undefined', (done) => {
Sample.findOne({ where: { name: sampleName } })
.then((sam) => publisher.publishSample(sam, null, sampleEvent.upd))
.then((pubObj) => {
Expand All @@ -81,8 +80,8 @@ describe('publishSample with redis cache on', () => {
.catch(done);
});

it('certain fields in subject should be array, and others' +
' should be undefined', (done) => {
it('certain fields in subject should be array, and others ' +
'should be undefined', (done) => {
Sample.findOne({ where: { name: sampleName } })
.then((sam) => publisher.publishSample(sam, null, sampleEvent.upd))
.then((pubObj) => {
Expand All @@ -95,8 +94,8 @@ describe('publishSample with redis cache on', () => {
.catch(done);
});

it('when tried to publish sample without aspect,'+
' aspect should be attached, along with subject', (done) => {
it('when tried to publish sample without aspect, ' +
'aspect should be attached, along with subject', (done) => {
Sample.findOne({ where: { name: sampleName } })
.then((sam) => {
const sampInst = sam.get();
Expand Down Expand Up @@ -154,8 +153,8 @@ describe('redis Publisher', () => {
after(u.forceDelete);

describe('publishSample function tests: ', () => {
it('with EventType argument: sample should be published with subject ' +
' object and asbolutePath field', (done) => {
it('with EventType argument: sample should be published with subject ' +
'object and asbolutePath field', (done) => {
Sample.findById(sampId)
.then((sam) => publisher.publishSample(sam, Subject, sampleEvent.upd))
.then((pubObj) => {
Expand Down Expand Up @@ -188,8 +187,8 @@ describe('redis Publisher', () => {
.catch(done);
});

it('when tried to publish sample without aspect,'+
' aspect should be attached', (done) => {
it('when tried to publish sample without aspect, ' +
'aspect should be attached', (done) => {
Sample.findById(sampId)
.then((sam) => {
const sampInst = sam.get();
Expand Down Expand Up @@ -217,18 +216,20 @@ describe('redis Publisher', () => {
describe('getSampleEventType function tests: ', () => {
it('update Event', (done) => {
Sample.findById(sampId)
.then((sam) => sam.update({ value: 10}))
.then((sam) => sam.update({ value: 10 }))
.then((updSample) => {
// pass sequelize object
let eventType = publisher.getSampleEventType(updSample);
expect(eventType).to.equal(sampleEvent.upd);

// pass plain object
eventType = publisher.getSampleEventType(updSample.get());
expect(eventType).to.equal(sampleEvent.upd);
done();
})
.catch(done);
});

it('add Event', (done) => {
Sample.upsertByName({
name: subjectSA.name + '|' + humidity.name,
Expand All @@ -238,6 +239,7 @@ describe('redis Publisher', () => {
// pass sequelize object
let eventType = publisher.getSampleEventType(sam);
expect(eventType).to.equal(sampleEvent.add);

// pass plain object
eventType = publisher.getSampleEventType(sam.get());
expect(eventType).to.equal(sampleEvent.add);
Expand Down
5 changes: 2 additions & 3 deletions tests/realtime/setupSocketIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* tests/realtime/setupSocketIO.js
*/
'use strict';

const expect = require('chai').expect;
const tu = require('../testUtils');
const socketIOSetup = require('../../realtime/setupSocketIO');
Expand Down Expand Up @@ -46,7 +45,7 @@ describe('socket.io setup', () => {
subjectTagFilter: ['ea', 'na'],
subjectTagFilterType: 'INCLUDE',
statusFilter: ['OK'],
statusFilterType: 'INCLUDE'
statusFilterType: 'INCLUDE',
}))
.then(() => done())
.catch(done);
Expand Down Expand Up @@ -118,7 +117,7 @@ describe('socket.io setup', () => {
subjectTagFilter: ['ea', 'na'],
subjectTagFilterType: 'INCLUDE',
statusFilter: ['OK'],
statusFilterType: 'INCLUDE'
statusFilterType: 'INCLUDE',
}))
.then(() => done())
.catch(done);
Expand Down
4 changes: 1 addition & 3 deletions tests/realtime/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
* tests/realtime/utils.js
*/
'use strict'; // eslint-disable-line strict

const tu = require('../testUtils');
const path = require('path');
const fs = require('fs');

const testStartTime = new Date();

module.exports = {
Expand Down Expand Up @@ -45,6 +43,6 @@ module.exports = {
.then(() => tu.forceDelete(tu.db.Subject, testStartTime))
.then(() => tu.forceDelete(tu.db.Aspect, testStartTime))
.then(() => done())
.catch((err) => done(err));
.catch(done);
},
};
10 changes: 1 addition & 9 deletions tests/roomFlag/roomFlagDisabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* tests/api/v1/roomFlag/roomFlagDisabled.js
*/
'use strict';

const supertest = require('supertest');
const api = supertest(require('../../index').app);
const constants = require('../../api/v1/constants');
Expand All @@ -21,13 +20,6 @@ describe('Rooms path is found', () => {
it('GET is found', (done) => {
api.get(path)
.expect(constants.httpStatus.NOT_FOUND)
.end((err /* , res */) => {
if (err) {
return done(err);
}

done();
});
.end(done);
});
});

Loading

0 comments on commit d659ce1

Please sign in to comment.