UNPKG

box-view-api

Version:

Box View API, node.js client library

250 lines (208 loc) 12.7 kB
// Tests for the Box View API document client // var API = require('index').DocumentAPI; var fsUtils = framework.fsUtils; describe('Box View API: NodeJS API: document', function() { describe('constructor', function() { it('should throw an error with no API Token', function() { framework.throwsError(function() { new API(); }); }); it('should throw an error if too many params are passed', function() { framework.throwsError(function() { new API(framework.boxView.dummyApiKey, 1); }); }); for (var k in framework.values.invalidParamList) { it('should throw an error with a '+framework.values.invalidParamList[k].name+' param', function () { framework.throwsError(function() { new API(framework.values.invalidParamList[k].value); }); }); } it('should NOT throw an error with a non-empty API Token string', function(){ new API(framework.boxView.dummyApiKey); }); }); describe('instance', function() { var instance; function getInstance() { return instance; } before(function () { instance = new API(framework.boxView.dummyApiKey); }); it('should have an uploadUrl function', function() { framework.assert(typeof instance.uploadUrl === 'function'); }); /* * no longer certain if this will be supported by Box View API * it('should have an uploadFile function', function() { framework.assert(typeof instance.uploadFile === 'function'); }); * */ it('should have a list function', function () { framework.assert(typeof instance.list === 'function'); }); it('should have an info function', function () { framework.assert(typeof instance.info === 'function'); }); it('should have a changeName function', function () { framework.assert(typeof instance.changeName === 'function'); }); it('should have a download function', function () { framework.assert(typeof instance.download === 'function'); }); it('should have a remove function', function() { framework.assert(typeof instance.remove === 'function'); }); it('should have a poll function', function() { framework.assert(typeof instance.poll === 'function'); }); var dummyCb = function(){}; describe('.uploadUrl()', function() { framework.instanceMethodTests(getInstance, 'uploadUrl', [ {name: 'non-blank string url and filename parameters, and function callback', args: ['url', 'filename', dummyCb]} ], [ {name: 'no parameters', args: []}, {name: 'a single string parameter', args: ['url']}, {name: 'a single function parameter', args: [dummyCb]}, {name: 'non-blank string url and filename parameters, and no callback', args: ['url', 'filename']}, {name: 'a string parameter and a function parameter', args: ['url', dummyCb]}, {name: 'a blank string url parameter, a non-blank string filename parameter and a function callback', args: ['', 'filename', dummyCb]}, {name: 'a non-blank string url parameter, a blank string filename parameter and a function callback', args: ['url', '', dummyCb]}, {name: 'non-blank string url and filename parameters, and a non-function callback', args: ['url', 'filename', 'random']}, {name: 'non-blank string url and filename parameters, a function callback, and some other parameter', args: ['url', 'filename', dummyCb, 'random']} ]); //'URL', 'http://web.crocodoc.com/files/test-simple.pdf'); }); /* * Not sure if this is still supported * describe('.uploadFile()', function() { before(function(done){ // create an unreadable file, since you can't commit one in git! framework.exec('echo "something" >unreadable; chmod a-r unreadable', function(error, stdout, stderr) { framework.assert(!error, 'Did not expect to get an error creating an unreadable file: '+error); done(); }); }); after(function(done){ // cleanup the unreadable file framework.exec('rm -f unreadable', function(error, stdout, stderr) { framework.assert(!error, 'Did not expect to get an error removing the unreadable file: '+error); done(); }); }); instanceMethodTests(instance.uploadFile, 'filepath', 'test/support/files/simple-presentation.ppt'); it('should throw an error with a non-existent file', function() { framework.throwsError(function() { instance.uploadFile('file does not exist'); }); }); it('should throw an error with a directory', function() { framework.throwsError(function() { instance.uploadFile('test'); }); }); it('should throw an error with an unreadable file', function() { framework.throwsError(function() { instance.uploadFile('unreadable'); }); }); }); * */ describe('.list()', function () { framework.instanceMethodTests(getInstance, 'list', [ {name: 'a function callback', args: [dummyCb]}, {name: 'an options hash, and a function callback', args: [{}, dummyCb]} ], [ {name: 'no parameters', args: []}, {name: 'a single non-function parameter', args: ['random']}, {name: 'a non-object options parameter, and a function callback', args: ['random', dummyCb]}, {name: 'an options hash, a function callback, and another parameter', args: [{}, dummyCb, 'random']} ]); }); describe('.info()', function () { framework.instanceMethodTests(getInstance, 'info', [ {name: 'a non-blank string document id, and a function callback', args: ['docId', dummyCb]}, {name: 'a non-blank string document id, a non-blank string of fields, and a function callback', args: ['docId', 'fieldList', dummyCb]}, {name: 'a non-blank string document id, an array of field names, and a function callback', args: ['docId', [], dummyCb]} ], [ {name: 'no parameters', args: []}, {name: 'a blank string document id, and a function callback', args: ['', dummyCb]}, {name: 'a non-string document id, and a function callback', args: [{}, dummyCb]}, {name: 'a non-blank string document id, a non-string / non-array field names, and a function callback', args: ['docId', {}, dummyCb]}, {name: 'a non-blank string document id, a non-blank string of field names, a function callback, and some additional parameter', args: ['docId', 'fieldList', dummyCb, 'random']} ]); }); describe('.changeName()', function () { framework.instanceMethodTests(getInstance, 'changeName', [ {name: 'a non-blank string document id, a non-blank string name, and a function callback', args: ['docId', 'name', dummyCb]}, ], [ {name: 'no parameters', args: []}, {name: 'a non-blank string document id, a non-blank string name, and a no function callback', args: ['docId', 'name']}, {name: 'a non-blank string document id, a non-blank string name, and a non- function callback', args: ['docId', 'name','random']}, {name: 'a blank string document id, a non-blank string name, and a function callback', args: ['', 'name', dummyCb]}, {name: 'a non-string document id, a non-blank string name, and a function callback', args: [{}, 'name', dummyCb]}, {name: 'a non-blank string document id, a blank string name, and a function callback', args: ['docId', '', dummyCb]}, {name: 'a non-blank string document id, a non-string name, and a function callback', args: ['docId', {}, dummyCb]}, {name: 'non-blank string document id and name, a function callback, and some additional parameter', args: ['docId', 'name', dummyCb, 'random']} ]); }); var writeStream = fsUtils.writeStream('/dev/null'); describe('.download()', function () { framework.instanceMethodTests(getInstance, 'download', [ {name: 'a non-blank string document id, a pdf download type, a write stream, and a function callback', args: ['docId', 'pdf', writeStream, dummyCb]}, {name: 'a non-blank string document id, a zip download type, a write stream, and a function callback', args: ['docId', 'zip', writeStream, dummyCb]} ], [ {name: 'no parameters', args: []}, {name: 'a non-blank string document id, a non-zip / non-pdf download type, a write stream, and a function callback', args: ['docId', 'random', writeStream, dummyCb]}, {name: 'a non-blank string document id, a pdf download type, no write stream, and a function callback', args: ['docId', 'pdf', dummyCb]}, {name: 'a non-blank string document id, a zip download type, no write stream, and a function callback', args: ['docId', 'zip', dummyCb]}, {name: 'a non-blank string document id, a pdf download type, a non write stream, and a function callback', args: ['docId', 'pdf', {}, dummyCb]}, {name: 'a non-blank string document id, a zip download type, a non write stream, and a function callback', args: ['docId', 'zip', {}, dummyCb]}, {name: 'a non-blank string document id, a pdf download type, no write stream, and a function callback', args: ['docId', 'pdf', dummyCb]}, {name: 'a non-blank string document id, a zip download type, no write stream, and a function callback', args: ['docId', 'zip', dummyCb]}, {name: 'a non-blank string document id, a pdf download type, a write stream, and no function callback', args: ['docId', 'pdf', writeStream]}, {name: 'a non-blank string document id, a zip download type, a write stream, and no function callback', args: ['docId', 'zip', writeStream]}, {name: 'a non-blank string document id, a pdf download type, a write stream, and a non function callback', args: ['docId', 'pdf', writeStream, 'random']}, {name: 'a non-blank string document id, a zip download type, a write stream, and a non function callback', args: ['docId', 'zip', writeStream, 'random']}, {name: 'a blank string document id, a pdf download type, a write stream, and a function callback', args: ['', 'pdf', writeStream, dummyCb]}, {name: 'a blank string document id, a zip download type, a write stream, and a function callback', args: ['', 'zip', writeStream, dummyCb]}, {name: 'a non string document id, a pdf download type, a write stream, and a function callback', args: [{}, 'pdf', writeStream, dummyCb]}, {name: 'a non string document id, a zip download type, a write stream, and a function callback', args: [{}, 'zip', writeStream, dummyCb]}, {name: 'a non-blank string document id, a pdf download type, a write stream, a function callback, and an additional parameter', args: ['docId', 'pdf', writeStream, dummyCb, 'random']}, {name: 'a non-blank string document id, a zip download type, a write stream, a function callback, and an additional parameter', args: ['docId', 'zip', writeStream, dummyCb, 'random']} ]); }); describe('.remove()', function() { framework.instanceMethodTests(getInstance, 'remove', [ {name: 'a non-blank string document id and a function callback', args: ['docId', dummyCb]} ], [ {name: 'no parameters', args: []}, {name: 'a non-blank string document id and no function callback', args: ['docId']}, {name: 'a non-blank string document id and a non-function callback', args: ['docId', 'random']}, {name: 'a blank string document id and a function callback', args: ['', dummyCb]}, {name: 'a non-string document id and a function callback', args: [{}, dummyCb]}, {name: 'a non-blank string document id, a function callback, and an additional parameter', args: ['docId', dummyCb, 'random']} ]); }); describe('.poll()', function() { framework.instanceMethodTests(getInstance, 'poll', [ {name: 'a non-blank string document id and a function callback', args: ['docId', dummyCb]} ], [ {name: 'no parameters', args: []}, {name: 'a non-blank string document id and no function callback', args: ['docId']}, {name: 'a non-blank string document id and a non-function callback', args: ['docId', 'random']}, {name: 'a blank string document id and a function callback', args: ['', dummyCb]}, {name: 'a non-string document id and a function callback', args: [{}, dummyCb]}, {name: 'a non-blank string document id, a function callback, and an additional parameter', args: ['docId', dummyCb, 'random']} ]); }); }); });