2016-04-30 13:00:44 -07:00
|
|
|
/* jslint node:true */
|
|
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2017-11-27 11:48:36 -08:00
|
|
|
var async = require('async'),
|
2019-10-22 13:59:01 -07:00
|
|
|
BoxError = require('../boxerror.js'),
|
2017-11-27 11:48:36 -08:00
|
|
|
database = require('../database.js'),
|
2016-04-30 13:00:44 -07:00
|
|
|
eventlog = require('../eventlog.js'),
|
2017-11-27 11:48:36 -08:00
|
|
|
expect = require('expect.js');
|
2016-04-30 13:00:44 -07:00
|
|
|
|
|
|
|
|
function setup(done) {
|
|
|
|
|
// ensure data/config/mount paths
|
|
|
|
|
database.initialize(function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
2017-11-27 11:48:36 -08:00
|
|
|
async.series([
|
|
|
|
|
database._clear,
|
|
|
|
|
database.uninitialize
|
|
|
|
|
], done);
|
2016-04-30 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('Eventlog', function () {
|
|
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
|
|
|
|
|
|
|
|
|
var eventId;
|
|
|
|
|
|
|
|
|
|
it('add succeeds', function (done) {
|
|
|
|
|
eventlog.add('some.event', { ip: '1.2.3.4' }, { appId: 'thatapp' }, function (error, result) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(result.id).to.be.ok();
|
|
|
|
|
|
|
|
|
|
eventId = result.id;
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('get succeeds', function (done) {
|
|
|
|
|
eventlog.get(eventId, function (error, result) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(result.id).to.be(eventId);
|
|
|
|
|
expect(result.action).to.be('some.event');
|
|
|
|
|
expect(result.creationTime).to.be.a(Date);
|
|
|
|
|
|
2016-05-01 20:01:34 -07:00
|
|
|
expect(result.source).to.be.eql({ ip: '1.2.3.4' });
|
2016-04-30 13:00:44 -07:00
|
|
|
expect(result.data).to.be.eql({ appId: 'thatapp' });
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('get of unknown id fails', function (done) {
|
|
|
|
|
eventlog.get('notfoundid', function (error, result) {
|
2019-10-22 13:59:01 -07:00
|
|
|
expect(error).to.be.a(BoxError);
|
|
|
|
|
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
2016-04-30 13:00:44 -07:00
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('getAllPaged succeeds', function (done) {
|
2018-03-05 11:14:36 +01:00
|
|
|
eventlog.getAllPaged([], null, 1, 1, function (error, results) {
|
2016-04-30 13:00:44 -07:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(results).to.be.an(Array);
|
|
|
|
|
expect(results.length).to.be(1);
|
|
|
|
|
|
|
|
|
|
expect(results[0].id).to.be(eventId);
|
|
|
|
|
expect(results[0].action).to.be('some.event');
|
2016-05-01 20:01:34 -07:00
|
|
|
expect(results[0].source).to.be.eql({ ip: '1.2.3.4' });
|
2016-04-30 13:00:44 -07:00
|
|
|
expect(results[0].data).to.be.eql({ appId: 'thatapp' });
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-07-25 12:36:43 -07:00
|
|
|
|
|
|
|
|
it('cleans up token', function (done) {
|
|
|
|
|
eventlog.cleanup(function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
|
|
|
|
eventlog.get(eventId, function (error, result) { // should not have deleted it
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(result.id).to.be(eventId);
|
|
|
|
|
expect(result.action).to.be('some.event');
|
|
|
|
|
expect(result.creationTime).to.be.a(Date);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-04-30 13:00:44 -07:00
|
|
|
});
|