server-tests.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. function equals(a, b) {
  2. return !!(EJSON.stringify(a) === EJSON.stringify(b));
  3. }
  4. var fileCollection = new FS.Collection('files', {
  5. stores: [
  6. new FS.Store.GridFS('files')
  7. ]
  8. });
  9. Tinytest.add('cfs-collection - test environment', function(test) {
  10. test.isTrue(typeof FS.Collection !== 'undefined', 'test environment not initialized FS.Collection');
  11. });
  12. Tinytest.add('cfs-collection - insert URL - sync - one', function (test) {
  13. // XXX should switch to a local URL we host
  14. // One
  15. try {
  16. fileCollection.insert("http://cdn.morguefile.com/imageData/public/files/b/bboomerindenial/preview/fldr_2009_04_01/file3301238617907.jpg");
  17. test.isTrue(true);
  18. } catch (err) {
  19. test.isFalse(!!err, "URL insert failed");
  20. }
  21. });
  22. Tinytest.add('cfs-collection - insert URL - sync - loop', function (test) {
  23. // XXX should switch to a local URL we host
  24. try {
  25. for (var i = 0, len = 10; i < len; i++) {
  26. fileCollection.insert("http://cdn.morguefile.com/imageData/public/files/b/bboomerindenial/preview/fldr_2009_04_01/file3301238617907.jpg");
  27. }
  28. test.isTrue(true);
  29. } catch (err) {
  30. test.isFalse(!!err, "URL insert failed");
  31. }
  32. });
  33. Tinytest.addAsync('cfs-collection - insert URL - async - one', function (test, next) {
  34. // XXX should switch to a local URL we host
  35. // One
  36. try {
  37. fileCollection.insert("http://cdn.morguefile.com/imageData/public/files/b/bboomerindenial/preview/fldr_2009_04_01/file3301238617907.jpg", function (error, result) {
  38. test.isNull(error);
  39. test.instanceOf(result, FS.File);
  40. next();
  41. });
  42. } catch (err) {
  43. test.isFalse(!!err, "URL insert failed");
  44. next();
  45. }
  46. });
  47. Tinytest.addAsync('cfs-collection - insert URL - async - loop', function (test, next) {
  48. // XXX should switch to a local URL we host
  49. try {
  50. var done = 0;
  51. for (var i = 0, len = 10; i < len; i++) {
  52. fileCollection.insert("http://cdn.morguefile.com/imageData/public/files/b/bboomerindenial/preview/fldr_2009_04_01/file3301238617907.jpg", function (error, result) {
  53. test.isNull(error);
  54. test.instanceOf(result, FS.File);
  55. done++;
  56. if (done === 10) {
  57. next();
  58. }
  59. });
  60. }
  61. } catch (err) {
  62. test.isFalse(!!err, "URL insert failed");
  63. next();
  64. }
  65. });
  66. //Test API:
  67. //test.isFalse(v, msg)
  68. //test.isTrue(v, msg)
  69. //test.equalactual, expected, message, not
  70. //test.length(obj, len)
  71. //test.include(s, v)
  72. //test.isNaN(v, msg)
  73. //test.isUndefined(v, msg)
  74. //test.isNotNull
  75. //test.isNull
  76. //test.throws(func)
  77. //test.instanceOf(obj, klass)
  78. //test.notEqual(actual, expected, message)
  79. //test.runId()
  80. //test.exception(exception)
  81. //test.expect_fail()
  82. //test.ok(doc)
  83. //test.fail(doc)
  84. //test.equal(a, b, msg)