resultsDatastoreTest.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. var should = require('chai').should();
  2. var resultsDatastore = require('../../lib/server/datastores/resultsDatastore');
  3. var fs = require('fs');
  4. var path = require('path');
  5. describe('resultsDatastore', function() {
  6. var datastore = new resultsDatastore();
  7. var testId1 = '123456789';
  8. var testData1 = {
  9. runId: testId1,
  10. other: {
  11. foo: 'foo',
  12. bar: 1
  13. }
  14. };
  15. it('should store a result', function(done) {
  16. datastore.should.have.a.property('saveResult').that.is.a('function');
  17. datastore.saveResult(testData1).then(function() {
  18. done();
  19. }).fail(function(err) {
  20. done(err);
  21. });
  22. });
  23. it('should store another result', function(done) {
  24. var testData2 = {
  25. runId: '987654321',
  26. other: {
  27. foo: 'foo',
  28. bar: 2
  29. }
  30. };
  31. datastore.saveResult(testData2).then(function() {
  32. done();
  33. }).fail(function(err) {
  34. done(err);
  35. });
  36. });
  37. it('should retrieve a result', function(done) {
  38. datastore.getResult(testId1)
  39. .then(function(results) {
  40. // Compare results with testData
  41. results.should.deep.equal(testData1);
  42. done();
  43. }).fail(function(err) {
  44. done(err);
  45. });
  46. });
  47. it('should delete a result', function(done) {
  48. datastore.deleteResult(testId1)
  49. .then(function() {
  50. done();
  51. }).fail(function(err) {
  52. done(err);
  53. });
  54. });
  55. it('should not find the result anymore', function(done) {
  56. datastore.getResult(testId1)
  57. .then(function(results) {
  58. done('Error, the result is still in the datastore');
  59. }).fail(function(err) {
  60. done();
  61. });
  62. });
  63. var testId3 = '555555';
  64. var testData3 = {
  65. runId: testId3,
  66. other: {
  67. foo: 'foo',
  68. bar: 2
  69. },
  70. screenshotBuffer: fs.readFileSync(path.join(__dirname, '../fixtures/logo-large.png'))
  71. };
  72. it('should store a test with a screenshot', function(done) {
  73. datastore.saveResult(testData3).then(function() {
  74. done();
  75. }).fail(function(err) {
  76. done(err);
  77. });
  78. });
  79. it('should have a normal result', function(done) {
  80. datastore.getResult(testId3)
  81. .then(function(results) {
  82. results.should.not.have.a.property('screenshot');
  83. done();
  84. })
  85. .fail(function(err) {
  86. done(err);
  87. });
  88. });
  89. it('should retrieve the saved image', function() {
  90. datastore.getScreenshot(testId3)
  91. .then(function(imageBuffer) {
  92. imageBuffer.should.be.an.instanceof(Buffer);
  93. done();
  94. })
  95. .fail(function(err) {
  96. done(err);
  97. });
  98. });
  99. });