123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- function equals(a, b) {
- return EJSON.stringify(a) === EJSON.stringify(b);
- }
- Tinytest.add('cfs-base-package - test environment', function(test) {
- test.isTrue(typeof FS !== 'undefined',
- 'FS scope not declared');
- test.isTrue(typeof FS.Store !== 'undefined',
- 'FS scope "FS.Store" not declared');
- test.isTrue(typeof FS.AccessPoint !== 'undefined',
- 'FS scope "FS.AccessPoint" not declared');
- test.isTrue(typeof FS.Utility !== 'undefined',
- 'FS scope "FS.Utility" not declared');
- test.isTrue(typeof FS._collections !== 'undefined',
- 'FS scope "FS._collections" not declared');
- test.isTrue(typeof _Utility !== 'undefined',
- '_Utility test scope not declared');
- });
- Tinytest.add('cfs-base-package - _Utility.defaultZero', function(test) {
- test.equal(_Utility.defaultZero(), 0, 'Failes to return 0 when (undefined)');
- test.equal(_Utility.defaultZero(undefined), 0, 'Failes to return 0 when undefined');
- test.equal(_Utility.defaultZero(null), 0, 'Failes to return 0 when null');
- test.equal(_Utility.defaultZero(false), 0, 'Failes to return 0 when false');
- test.equal(_Utility.defaultZero(0), 0, 'Failes to return 0 when 0');
- test.equal(_Utility.defaultZero(-1), -1, 'Failes to return -1');
- test.equal(_Utility.defaultZero(1), 1, 'Failes to return 1');
- test.equal(_Utility.defaultZero(-0.1), -0.1, 'Failes to return -0.1');
- test.equal(_Utility.defaultZero(0.1), 0.1, 'Failes to return 0.1');
- test.equal(_Utility.defaultZero(''), 0, 'Failes to return ""');
- test.equal(_Utility.defaultZero({}), NaN, 'Failes to return NaN when object');
- test.equal(_Utility.defaultZero("dfdsfs"), NaN, 'Failes to return NaN when string');
- test.equal(_Utility.defaultZero("1"), 1, 'Failes to return 1 when string "1"');
- });
- Tinytest.add('cfs-base-package - FS.Utility.cloneFileRecord', function(test) {
- // Given an object with any props, should filter out 'collectionName',
- // 'collection', 'data', and 'createdByTransform'
- var result = FS.Utility.cloneFileRecord({a: 1, b: {c: 1}, d: [1, 2], collectionName: 'test', collection: {}, data: {}, createdByTransform: false});
- test.equal(result, {a: 1, b: {c: 1}, d: [1, 2]});
- // Given an FS.File instance, should filter out 'collectionName',
- // 'collection', 'data', and 'createdByTransform' and return a plain Object
- 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});
- test.isTrue(fileObj instanceof FS.File);
- var result = FS.Utility.cloneFileRecord(fileObj);
- test.isFalse(result instanceof FS.File);
- test.isTrue(equals(result, {a: 1, b: {c: 1}, d: [1, 2], name: 'name.png', type: 'image/png', size: 100}));
- });
- Tinytest.add('cfs-base-package - FS.Utility.defaultCallback', function(test) {
- // should throw an error passed in, but not a Meteor.Error
- test.throws(function () {
- var cb = FS.Utility.defaultCallback;
- cb(new Error('test'));
- });
- var cb2 = FS.Utility.defaultCallback;
- test.isUndefined(cb2(new Meteor.Error('test')));
- });
- Tinytest.add('cfs-base-package - FS.Utility.handleError', function(test) {
- test.isTrue(true);
- // TODO
- });
- Tinytest.add('cfs-base-package - FS.Utility.binaryToBuffer', function(test) {
- test.isTrue(true);
- // TODO
- });
- Tinytest.add('cfs-base-package - FS.Utility.bufferToBinary', function(test) {
- test.isTrue(true);
- // TODO
- });
- Tinytest.add('cfs-base-package - FS.Utility.connectionLogin', function(test) {
- test.isTrue(true);
- // TODO
- });
- Tinytest.add('cfs-base-package - FS.Utility.getFileName', function(test) {
- function t(input, expected) {
- var ext = FS.Utility.getFileName(input);
- test.equal(ext, expected, 'Got incorrect filename');
- }
- t('bar.png', 'bar.png');
- t('foo/bar.png', 'bar.png');
- t('/foo/foo/bar.png', 'bar.png');
- t('http://foobar.com/file.png', 'file.png');
- t('http://foobar.com/file', 'file');
- t('http://foobar.com/file.png?a=b', 'file.png');
- t('http://foobar.com/.file?a=b', '.file');
- t('file', 'file');
- t('.file', '.file');
- t('foo/.file', '.file');
- t('/foo/foo/.file', '.file');
- });
- Tinytest.add('cfs-base-package - FS.Utility.getFileExtension', function(test) {
- function t(input, expected) {
- var ext = FS.Utility.getFileExtension(input);
- test.equal(ext, expected, 'Got incorrect extension');
- }
- t('bar.png', 'png');
- t('foo/bar.png', 'png');
- t('/foo/foo/bar.png', 'png');
- t('http://foobar.com/file.png', 'png');
- t('http://foobar.com/file', '');
- t('http://foobar.com/file.png?a=b', 'png');
- t('http://foobar.com/file?a=b', '');
- t('file', '');
- t('.file', '');
- t('foo/.file', '');
- t('/foo/foo/.file', '');
- });
- Tinytest.add('cfs-base-package - FS.Utility.setFileExtension', function(test) {
- function t(name, ext, expected) {
- var newName = FS.Utility.setFileExtension(name, ext);
- test.equal(newName, expected, 'Extension was not set correctly');
- }
- t('bar.png', 'jpeg', 'bar.jpeg');
- t('bar', 'jpeg', 'bar.jpeg');
- t('.bar', 'jpeg', '.bar.jpeg');
- t('', 'jpeg', '');
- t(null, 'jpeg', null);
- });
- //Test API:
- //Tinytest.add('', function(test) {});
- //Tinytest.addAsync('', function(test, onComplete) {});
- //test.isFalse(v, msg)
- //test.isTrue(v, msg)
- //test.equalactual, expected, message, not
- //test.length(obj, len)
- //test.include(s, v)
- //test.isNaN(v, msg)
- //test.isUndefined(v, msg)
- //test.isNotNull
- //test.isNull
- //test.throws(func)
- //test.instanceOf(obj, klass)
- //test.notEqual(actual, expected, message)
- //test.runId()
- //test.exception(exception)
- //test.expect_fail()
- //test.ok(doc)
- //test.fail(doc)
- //test.equal(a, b, msg)
|