common-tests.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. function equals(a, b) {
  2. return EJSON.stringify(a) === EJSON.stringify(b);
  3. }
  4. Tinytest.add('cfs-base-package - test environment', function(test) {
  5. test.isTrue(typeof FS !== 'undefined',
  6. 'FS scope not declared');
  7. test.isTrue(typeof FS.Store !== 'undefined',
  8. 'FS scope "FS.Store" not declared');
  9. test.isTrue(typeof FS.AccessPoint !== 'undefined',
  10. 'FS scope "FS.AccessPoint" not declared');
  11. test.isTrue(typeof FS.Utility !== 'undefined',
  12. 'FS scope "FS.Utility" not declared');
  13. test.isTrue(typeof FS._collections !== 'undefined',
  14. 'FS scope "FS._collections" not declared');
  15. test.isTrue(typeof _Utility !== 'undefined',
  16. '_Utility test scope not declared');
  17. });
  18. Tinytest.add('cfs-base-package - _Utility.defaultZero', function(test) {
  19. test.equal(_Utility.defaultZero(), 0, 'Failes to return 0 when (undefined)');
  20. test.equal(_Utility.defaultZero(undefined), 0, 'Failes to return 0 when undefined');
  21. test.equal(_Utility.defaultZero(null), 0, 'Failes to return 0 when null');
  22. test.equal(_Utility.defaultZero(false), 0, 'Failes to return 0 when false');
  23. test.equal(_Utility.defaultZero(0), 0, 'Failes to return 0 when 0');
  24. test.equal(_Utility.defaultZero(-1), -1, 'Failes to return -1');
  25. test.equal(_Utility.defaultZero(1), 1, 'Failes to return 1');
  26. test.equal(_Utility.defaultZero(-0.1), -0.1, 'Failes to return -0.1');
  27. test.equal(_Utility.defaultZero(0.1), 0.1, 'Failes to return 0.1');
  28. test.equal(_Utility.defaultZero(''), 0, 'Failes to return ""');
  29. test.equal(_Utility.defaultZero({}), NaN, 'Failes to return NaN when object');
  30. test.equal(_Utility.defaultZero("dfdsfs"), NaN, 'Failes to return NaN when string');
  31. test.equal(_Utility.defaultZero("1"), 1, 'Failes to return 1 when string "1"');
  32. });
  33. Tinytest.add('cfs-base-package - FS.Utility.cloneFileRecord', function(test) {
  34. // Given an object with any props, should filter out 'collectionName',
  35. // 'collection', 'data', and 'createdByTransform'
  36. var result = FS.Utility.cloneFileRecord({a: 1, b: {c: 1}, d: [1, 2], collectionName: 'test', collection: {}, data: {}, createdByTransform: false});
  37. test.equal(result, {a: 1, b: {c: 1}, d: [1, 2]});
  38. // Given an FS.File instance, should filter out 'collectionName',
  39. // 'collection', 'data', and 'createdByTransform' and return a plain Object
  40. var fileObj = new FS.File({a: 1, b: {c: 1}, d: [1, 2], name: 'name.png', type: 'image/png', size: 100, collectionName: 'test', collection: {}, data: {}, createdByTransform: false});
  41. test.isTrue(fileObj instanceof FS.File);
  42. var result = FS.Utility.cloneFileRecord(fileObj);
  43. test.isFalse(result instanceof FS.File);
  44. test.isTrue(equals(result, {a: 1, b: {c: 1}, d: [1, 2], name: 'name.png', type: 'image/png', size: 100}));
  45. });
  46. Tinytest.add('cfs-base-package - FS.Utility.defaultCallback', function(test) {
  47. // should throw an error passed in, but not a Meteor.Error
  48. test.throws(function () {
  49. var cb = FS.Utility.defaultCallback;
  50. cb(new Error('test'));
  51. });
  52. var cb2 = FS.Utility.defaultCallback;
  53. test.isUndefined(cb2(new Meteor.Error('test')));
  54. });
  55. Tinytest.add('cfs-base-package - FS.Utility.handleError', function(test) {
  56. test.isTrue(true);
  57. // TODO
  58. });
  59. Tinytest.add('cfs-base-package - FS.Utility.binaryToBuffer', function(test) {
  60. test.isTrue(true);
  61. // TODO
  62. });
  63. Tinytest.add('cfs-base-package - FS.Utility.bufferToBinary', function(test) {
  64. test.isTrue(true);
  65. // TODO
  66. });
  67. Tinytest.add('cfs-base-package - FS.Utility.connectionLogin', function(test) {
  68. test.isTrue(true);
  69. // TODO
  70. });
  71. Tinytest.add('cfs-base-package - FS.Utility.getFileName', function(test) {
  72. function t(input, expected) {
  73. var ext = FS.Utility.getFileName(input);
  74. test.equal(ext, expected, 'Got incorrect filename');
  75. }
  76. t('bar.png', 'bar.png');
  77. t('foo/bar.png', 'bar.png');
  78. t('/foo/foo/bar.png', 'bar.png');
  79. t('http://foobar.com/file.png', 'file.png');
  80. t('http://foobar.com/file', 'file');
  81. t('http://foobar.com/file.png?a=b', 'file.png');
  82. t('http://foobar.com/.file?a=b', '.file');
  83. t('file', 'file');
  84. t('.file', '.file');
  85. t('foo/.file', '.file');
  86. t('/foo/foo/.file', '.file');
  87. });
  88. Tinytest.add('cfs-base-package - FS.Utility.getFileExtension', function(test) {
  89. function t(input, expected) {
  90. var ext = FS.Utility.getFileExtension(input);
  91. test.equal(ext, expected, 'Got incorrect extension');
  92. }
  93. t('bar.png', 'png');
  94. t('foo/bar.png', 'png');
  95. t('/foo/foo/bar.png', 'png');
  96. t('http://foobar.com/file.png', 'png');
  97. t('http://foobar.com/file', '');
  98. t('http://foobar.com/file.png?a=b', 'png');
  99. t('http://foobar.com/file?a=b', '');
  100. t('file', '');
  101. t('.file', '');
  102. t('foo/.file', '');
  103. t('/foo/foo/.file', '');
  104. });
  105. Tinytest.add('cfs-base-package - FS.Utility.setFileExtension', function(test) {
  106. function t(name, ext, expected) {
  107. var newName = FS.Utility.setFileExtension(name, ext);
  108. test.equal(newName, expected, 'Extension was not set correctly');
  109. }
  110. t('bar.png', 'jpeg', 'bar.jpeg');
  111. t('bar', 'jpeg', 'bar.jpeg');
  112. t('.bar', 'jpeg', '.bar.jpeg');
  113. t('', 'jpeg', '');
  114. t(null, 'jpeg', null);
  115. });
  116. //Test API:
  117. //Tinytest.add('', function(test) {});
  118. //Tinytest.addAsync('', function(test, onComplete) {});
  119. //test.isFalse(v, msg)
  120. //test.isTrue(v, msg)
  121. //test.equalactual, expected, message, not
  122. //test.length(obj, len)
  123. //test.include(s, v)
  124. //test.isNaN(v, msg)
  125. //test.isUndefined(v, msg)
  126. //test.isNotNull
  127. //test.isNull
  128. //test.throws(func)
  129. //test.instanceOf(obj, klass)
  130. //test.notEqual(actual, expected, message)
  131. //test.runId()
  132. //test.exception(exception)
  133. //test.expect_fail()
  134. //test.ok(doc)
  135. //test.fail(doc)
  136. //test.equal(a, b, msg)