UNPKG

box-view-api

Version:

Box View API, node.js client library

148 lines (119 loc) 4.34 kB
// Tests for the Box View document API var API = require('index').SessionAPI; // setup aliases from the framework to save typing var statusCodeChecks = framework.statusCodeChecks; var jsonContentTypeChecks = framework.jsonContentTypeChecks; var pollTimeout = framework.timeouts.poll; var responseTimeout = framework.timeouts.response; var checkProps = framework.checkProps; var responses = framework.boxViewResponses; // make sure we clean temporarily created uuids after(function(done) { this.timeout(responseTimeout * (framework.tempUuid.uuids.length+1)); framework.tempUuid.purge(done); }); describe('Box View API: REST: session', function() { var instance = new API(framework.boxView.validApiKey); var preloadedUuid; it('should preload a file without timing out', function(done) { var url = 'http://web.crocodoc.com/files/test-simple.pdf'; var name = url; this.timeout(pollTimeout); framework.tempUuid.fromUrl(url, name, function(e, r, b) { framework.assert(typeof b === 'object', 'Could not pre-load a document for the tests: e: ' + e + ', typeof body: ' + typeof b + ' body: ' + framework.inspect(b, true, 1)); preloadedUuid = b.id; framework.tempUuid.waitFor(preloadedUuid, function (e, r, b) { done(); }); }); }); describe('.create()', function() { describe('with an id for a preloaded file', function() { var error, response, body; function getError() { return error; } function getResponse() { return response; } function getBody() { return body; } it('should respond without timing out', function(done) { this.timeout(responseTimeout); instance.create(preloadedUuid, function(e, r, b) { error = e; response = r; body = b; done(); }); }); statusCodeChecks(it, 201)(getError, getResponse, getBody); jsonContentTypeChecks(getError, getResponse, getBody); describe('the response body', function() { checkProps(getBody, responses.session.basic, true); }); }); describe('with malformed id', function () { var error, response, body; function getError() { return error; } function getResponse() { return response; } function getBody() { return body; } it('should respond without timing out', function (done) { this.timeout(responseTimeout); instance.create('maformed id', function (e, r, b) { error = e; response = r; body = b; done(); }); }); statusCodeChecks(it, 400)(getError, getResponse, getBody); jsonContentTypeChecks(getError, getResponse, getBody); describe('the response body', function () { checkProps(getBody, responses.session.badDocId, true); }); }); describe('with a non-existent uuid', function() { var error, response, body; function getError() { return error; } function getResponse() { return response; } function getBody() { return body; } it('should respond without timing out', function(done) { this.timeout(responseTimeout); instance.create('non-existent docId xxxxxxxxxxxxx', function(e, r, b) { error = e; response = r; body = b; done(); }); }); statusCodeChecks(it, 404)(getError, getResponse, getBody); jsonContentTypeChecks(getError, getResponse, getBody); describe('the response body', function() { checkProps(getBody, responses.session.docIdNotFound, true); // it('should be an object', function () { // framework.assert(typeof body === 'object', 'Expected body to be an object, not: (' + typeof body + '): ' + body); // }); // it('should have an undefined id field', function() { // framework.assert(body.id === undefined, 'Expected body.id to be undefined, not: ('+typeof body.id+'): '+body.id); // }); // it('should have a truthy detail field', function() { // framework.assert(body.detail, 'Expected body.detail to be truthy, not: ('+typeof body.detail+'): '+body.detail); // }); }); }); }); });