runsDatastoreTest.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var should = require('chai').should();
  2. var runsDatastore = require('../../lib/server/datastores/runsDatastore');
  3. describe('runsDatastore', function() {
  4. var datastore = new runsDatastore();
  5. var firstRunId = 333;
  6. var secondRunId = 999;
  7. it('should accept new runs', function() {
  8. datastore.should.have.a.property('add').that.is.a('function');
  9. datastore.add({
  10. runId: firstRunId,
  11. otherData: 123456789
  12. }, 0);
  13. datastore.add({
  14. runId: secondRunId,
  15. otherData: 'whatever'
  16. }, 1);
  17. });
  18. it('should have stored the runs with a status "runnung"', function() {
  19. datastore.should.have.a.property('get').that.is.a('function');
  20. var firstRun = datastore.get(firstRunId);
  21. firstRun.should.have.a.property('runId').that.equals(firstRunId);
  22. firstRun.should.have.a.property('status').that.deep.equals({
  23. statusCode: 'running'
  24. });
  25. var secondRun = datastore.get(secondRunId);
  26. secondRun.should.have.a.property('runId').that.equals(secondRunId);
  27. secondRun.should.have.a.property('status').that.deep.equals({
  28. statusCode: 'awaiting',
  29. position: 1
  30. });
  31. });
  32. it('should have exactly 2 runs in the store', function() {
  33. var runs = datastore.list();
  34. runs.should.be.a('array');
  35. runs.should.have.length(2);
  36. runs[0].should.have.a.property('runId').that.equals(firstRunId);
  37. });
  38. it('shoud update statuses correctly', function() {
  39. datastore.markAsComplete(firstRunId);
  40. var firstRun = datastore.get(firstRunId);
  41. firstRun.should.have.a.property('status').that.deep.equals({
  42. statusCode: 'complete'
  43. });
  44. datastore.updatePosition(secondRunId, 0);
  45. var secondRun = datastore.get(secondRunId);
  46. secondRun.should.have.a.property('status').that.deep.equals({
  47. statusCode: 'running'
  48. });
  49. datastore.markAsFailed(secondRunId, 'Error message');
  50. secondRun = datastore.get(secondRunId);
  51. secondRun.should.have.a.property('status').that.deep.equals({
  52. statusCode: 'failed',
  53. error: 'Error message'
  54. });
  55. });
  56. it('should delete a run', function() {
  57. datastore.delete(firstRunId);
  58. var runs = datastore.list();
  59. runs.should.be.a('array');
  60. runs.should.have.length(1);
  61. runs[0].should.have.a.property('runId').that.equals(secondRunId);
  62. });
  63. });