client-tests.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. function equals(a, b) {
  2. return !!(EJSON.stringify(a) === EJSON.stringify(b));
  3. }
  4. Tinytest.add('cfs-access-point - client - test environment', function(test) {
  5. test.isTrue(typeof FS.Collection !== 'undefined', 'test environment not initialized FS.Collection');
  6. test.isTrue(typeof FS.HTTP !== 'undefined', 'test environment not initialized FS.HTTP');
  7. });
  8. Images = new FS.Collection('images', {
  9. stores: [
  10. new FS.Store.GridFS('gridList')
  11. ]
  12. });
  13. Meteor.subscribe("img");
  14. var id;
  15. Tinytest.addAsync('cfs-access-point - client - addTestImage', function(test, onComplete) {
  16. Meteor.call('addTestImage', function(err, result) {
  17. id = result;
  18. test.equal(typeof id, "string", "Test image was not inserted properly");
  19. //Don't continue until the data has been stored
  20. Deps.autorun(function (c) {
  21. var img = Images.findOne(id);
  22. if (img && img.hasCopy('gridList')) {
  23. onComplete();
  24. c.stop();
  25. }
  26. });
  27. });
  28. });
  29. Tinytest.addAsync('cfs-access-point - client - GET list of files in collection', function(test, onComplete) {
  30. HTTP.get(Meteor.absoluteUrl('cfs/record/images'), function(err, result) {
  31. // Test the length of array result
  32. var len = result.data && result.data.length;
  33. test.isTrue(!!len, 'Result was empty');
  34. // Get the object
  35. var obj = result.data && result.data[0] || {};
  36. test.equal(obj._id, id, 'Didn\'t get the expected result');
  37. onComplete();
  38. });
  39. });
  40. Tinytest.addAsync('cfs-access-point - client - GET filerecord', function(test, onComplete) {
  41. HTTP.get(Meteor.absoluteUrl('cfs/record/images/' + id), function(err, result) {
  42. // Get the object
  43. var obj = result.data;
  44. test.equal(typeof obj, "object", "Expected object data");
  45. test.equal(obj._id, id, 'Didn\'t get the expected result');
  46. onComplete();
  47. });
  48. });
  49. Tinytest.addAsync('cfs-access-point - client - GET file itself', function(test, onComplete) {
  50. HTTP.get(Meteor.absoluteUrl('cfs/files/images/' + id), function(err, result) {
  51. test.isTrue(!!result.content, "Expected content in response");
  52. console.log(result);
  53. test.equal(result.statusCode, 200, "Expected 200 OK response");
  54. onComplete();
  55. });
  56. });
  57. Tinytest.addAsync('cfs-access-point - client - PUT new file data (update)', function(test, onComplete) {
  58. // TODO
  59. // HTTP.put(Meteor.absoluteUrl('cfs/files/images/' + id), function(err, result) {
  60. // test.equal(result.statusCode, 200, "Expected 200 OK response");
  61. onComplete();
  62. // });
  63. });
  64. Tinytest.addAsync('cfs-access-point - client - PUT insert a new file', function(test, onComplete) {
  65. // TODO
  66. // HTTP.put(Meteor.absoluteUrl('cfs/files/images'), function(err, result) {
  67. // test.equal(result.statusCode, 200, "Expected 200 OK response");
  68. onComplete();
  69. // });
  70. });
  71. Tinytest.addAsync('cfs-access-point - client - DELETE filerecord and data', function(test, onComplete) {
  72. HTTP.del(Meteor.absoluteUrl('cfs/files/images/' + id), function(err, result) {
  73. test.equal(result.statusCode, 200, "Expected 200 OK response");
  74. // Make sure it's gone
  75. HTTP.get(Meteor.absoluteUrl('cfs/record/images/' + id), function(err, result) {
  76. test.isTrue(!!err, 'Expected 404 error');
  77. test.equal(result.statusCode, 404, "Expected 404 response");
  78. onComplete();
  79. });
  80. });
  81. });
  82. //TODO test FS.File.prototype.url method with various options
  83. //Test API:
  84. //test.isFalse(v, msg)
  85. //test.isTrue(v, msg)
  86. //test.equalactual, expected, message, not
  87. //test.length(obj, len)
  88. //test.include(s, v)
  89. //test.isNaN(v, msg)
  90. //test.isUndefined(v, msg)
  91. //test.isNotNull
  92. //test.isNull
  93. //test.throws(func)
  94. //test.instanceOf(obj, klass)
  95. //test.notEqual(actual, expected, message)
  96. //test.runId()
  97. //test.exception(exception)
  98. //test.expect_fail()
  99. //test.ok(doc)
  100. //test.fail(doc)
  101. //test.equal(a, b, msg)