Writing the API (workin in progress)

This commit is contained in:
Gaël Métais
2014-12-02 00:08:07 +01:00
parent 35aed5fb55
commit e18cd87a07
14 changed files with 344 additions and 100 deletions
+41
View File
@@ -0,0 +1,41 @@
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);
});
});
+64
View File
@@ -0,0 +1,64 @@
var should = require('chai').should();
var runsQueue = require('../../lib/server/datastores/runsQueue.js');
describe('runsQueue', function() {
var queue = new runsQueue();
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.then(function() {
done();
});
});
it('should return the right positions', function() {
var aaaPosition = queue.getPosition('aaa');
aaaPosition.should.equal(0);
var bbbPosition = queue.getPosition('bbb');
bbbPosition.should.equal(1);
var cccPosition = queue.getPosition('ccc');
cccPosition.should.equal(-1);
});
it('should refresh runs\' positions', function(done) {
cccRun = queue.push('ccc');
cccRun.progress(function(position) {
position.should.equal(1);
var positionDoubleCheck = queue.getPosition('ccc');
positionDoubleCheck.should.equal(1);
done();
});
queue.remove('aaa');
});
it('should fulfill the promise when first in the line', function(done) {
cccRun.then(function() {
done();
});
queue.remove('bbb');
});
it('should not keep removed runs', function() {
var aaaPosition = queue.getPosition('aaa');
aaaPosition.should.equal(-1);
var bbbPosition = queue.getPosition('bbb');
bbbPosition.should.equal(-1);
var cccPosition = queue.getPosition('ccc');
cccPosition.should.equal(0);
});
});
-23
View File
@@ -1,23 +0,0 @@
var should = require('chai').should();
var testQueue = require('../../app/lib/testQueue.js');
describe('testQueue', function() {
var url = 'http://www.not.existing';
it('should accept a new test with method push', function() {
testQueue.should.have.property('push').that.is.a('function');
var task = {
testId: 'aaaaa',
url: url,
options: {}
};
testQueue.push(task, function(err, json, results) {
done();
});
});
});