API is starting to run
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
var should = require('chai').should();
|
||||
var resultsDatastore = require('../../lib/server/datastores/resultsDatastore');
|
||||
|
||||
describe('resultsDatastore', function() {
|
||||
|
||||
var datastore = new resultsDatastore();
|
||||
|
||||
var testId1 = '123456789';
|
||||
var testData1 = {
|
||||
runId: testId1,
|
||||
other: {
|
||||
foo: 'foo',
|
||||
bar: 1
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
it('should store a result', function(done) {
|
||||
datastore.should.have.a.property('saveResult').that.is.a('function');
|
||||
|
||||
datastore.saveResult(testData1).then(function() {
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should store another result', function(done) {
|
||||
var testData2 = {
|
||||
runId: '987654321',
|
||||
other: {
|
||||
foo: 'foo',
|
||||
bar: 2
|
||||
}
|
||||
};
|
||||
|
||||
datastore.saveResult(testData2).then(function() {
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should retrieve a result', function(done) {
|
||||
datastore.getResult(testId1)
|
||||
.then(function(results) {
|
||||
|
||||
// Compare results with testData
|
||||
results.should.deep.equal(testData1);
|
||||
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete a result', function(done) {
|
||||
datastore.deleteResult(testId1)
|
||||
.then(function() {
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not find the result anymore', function(done) {
|
||||
datastore.getResult(testId1)
|
||||
.then(function(results) {
|
||||
done('Error, the result is still in the datastore');
|
||||
}).fail(function(err) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
var should = require('chai').should();
|
||||
var runsDatastore = require('../../lib/server/datastores/runsDatastore');
|
||||
|
||||
describe('runsDatastore', function() {
|
||||
|
||||
var datastore = new runsDatastore();
|
||||
|
||||
var firstRunId = 333;
|
||||
var secondRunId = 999;
|
||||
|
||||
it('should accept new runs', function() {
|
||||
datastore.should.have.a.property('add').that.is.a('function');
|
||||
|
||||
datastore.add({
|
||||
runId: firstRunId,
|
||||
otherData: 123456789
|
||||
}, 0);
|
||||
|
||||
datastore.add({
|
||||
runId: secondRunId,
|
||||
otherData: 'whatever'
|
||||
}, 1);
|
||||
});
|
||||
|
||||
it('should have stored the runs with a status "runnung"', function() {
|
||||
datastore.should.have.a.property('get').that.is.a('function');
|
||||
|
||||
var firstRun = datastore.get(firstRunId);
|
||||
firstRun.should.have.a.property('runId').that.equals(firstRunId);
|
||||
firstRun.should.have.a.property('status').that.deep.equals({
|
||||
statusCode: 'running'
|
||||
});
|
||||
|
||||
var secondRun = datastore.get(secondRunId);
|
||||
secondRun.should.have.a.property('runId').that.equals(secondRunId);
|
||||
secondRun.should.have.a.property('status').that.deep.equals({
|
||||
statusCode: 'awaiting',
|
||||
position: 1
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should have exactly 2 runs in the store', function() {
|
||||
var runs = datastore.list();
|
||||
runs.should.be.a('array');
|
||||
runs.should.have.length(2);
|
||||
runs[0].should.have.a.property('runId').that.equals(firstRunId);
|
||||
});
|
||||
|
||||
it('shoud update statuses correctly', function() {
|
||||
|
||||
datastore.markAsComplete(firstRunId);
|
||||
var firstRun = datastore.get(firstRunId);
|
||||
firstRun.should.have.a.property('status').that.deep.equals({
|
||||
statusCode: 'complete'
|
||||
});
|
||||
|
||||
datastore.updatePosition(secondRunId, 0);
|
||||
var secondRun = datastore.get(secondRunId);
|
||||
secondRun.should.have.a.property('status').that.deep.equals({
|
||||
statusCode: 'running'
|
||||
});
|
||||
|
||||
datastore.markAsFailed(secondRunId);
|
||||
secondRun = datastore.get(secondRunId);
|
||||
secondRun.should.have.a.property('status').that.deep.equals({
|
||||
statusCode: 'failed'
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should delete a run', function() {
|
||||
datastore.delete(firstRunId);
|
||||
|
||||
var runs = datastore.list();
|
||||
runs.should.be.a('array');
|
||||
runs.should.have.length(1);
|
||||
|
||||
runs[0].should.have.a.property('runId').that.equals(secondRunId);
|
||||
});
|
||||
});
|
||||
@@ -4,13 +4,15 @@ var runsQueue = require('../../lib/server/datastores/runsQueue.js');
|
||||
describe('runsQueue', function() {
|
||||
|
||||
var queue = new runsQueue();
|
||||
var aaaRun = null;
|
||||
var bbbRun = null;
|
||||
var cccRun = null;
|
||||
|
||||
it('should accept a new runId', function(done) {
|
||||
queue.should.have.a.property('push').that.is.a('function');
|
||||
|
||||
var aaaRun = queue.push('aaa');
|
||||
queue.push('bbb');
|
||||
aaaRun = queue.push('aaa');
|
||||
bbbRun = queue.push('bbb');
|
||||
|
||||
aaaRun.then(function() {
|
||||
done();
|
||||
@@ -20,9 +22,11 @@ describe('runsQueue', function() {
|
||||
it('should return the right positions', function() {
|
||||
var aaaPosition = queue.getPosition('aaa');
|
||||
aaaPosition.should.equal(0);
|
||||
aaaRun.startingPosition.should.equal(0);
|
||||
|
||||
var bbbPosition = queue.getPosition('bbb');
|
||||
bbbPosition.should.equal(1);
|
||||
bbbRun.startingPosition.should.equal(1);
|
||||
|
||||
var cccPosition = queue.getPosition('ccc');
|
||||
cccPosition.should.equal(-1);
|
||||
@@ -1,41 +0,0 @@
|
||||
var should = require('chai').should();
|
||||
var runsDatastore = require('../../lib/server/datastores/runsDatastore');
|
||||
|
||||
describe('runsDatastore', function() {
|
||||
|
||||
var datastore = new runsDatastore();
|
||||
|
||||
var randomId = Math.round(Math.random() * 100000);
|
||||
|
||||
it('should accept a new run', function() {
|
||||
datastore.should.have.a.property('add').that.is.a('function');
|
||||
|
||||
datastore.add({
|
||||
_id: randomId,
|
||||
otherData: 123456789
|
||||
});
|
||||
});
|
||||
|
||||
it('should have stored the run', function() {
|
||||
datastore.should.have.a.property('get').that.is.a('function');
|
||||
|
||||
var run = datastore.get(randomId);
|
||||
|
||||
run.should.have.a.property('_id').that.equals(randomId);
|
||||
});
|
||||
|
||||
it('should have exactly 1 run in the store', function() {
|
||||
var runs = datastore.list();
|
||||
runs.should.be.a('array');
|
||||
runs.should.have.length(1);
|
||||
runs[0].should.have.a.property('_id').that.equals(randomId);
|
||||
});
|
||||
|
||||
it('should delete the run', function() {
|
||||
datastore.delete(randomId);
|
||||
|
||||
var runs = datastore.list();
|
||||
runs.should.be.a('array');
|
||||
runs.should.have.length(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user