UNPKG

mojio-js-sdk

Version:

Mojio javascript REST client.

88 lines (77 loc) 2.71 kB
// Generated by CoffeeScript 1.10.0 (function() { var HttpBrowserWrapper, XMLHttpRequest, async, nock, should, sinon, xhr; should = require('should'); async = require('async'); HttpBrowserWrapper = require('../../src/browser/wrappers/HttpWrapper'); nock = require('nock'); sinon = require('sinon'); XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; xhr = new XMLHttpRequest(); describe('Http Browser Wrapper', function() { var contentType, testErrorResult, token, unittest; unittest = true; if ((process.env.FUNCTIONAL_TESTS != null)) { unittest = false; } token = "token"; contentType = "application/json"; testErrorResult = function(error, result) { (error === null).should.be["true"]; return (result !== null).should.be["true"]; }; xhr = null; it('tests @request get resource with id', function(done) { var httpBrowserWrapper; nock('https://api.moj.io').get('/v1/Vehicles/1').reply(function(uri, requestBody, cb) { if (!unittest) { this.req.headers.mojioapitoken.should.be.equal(token); } this.req.headers['content-type'].should.be.equal(contentType); return cb(null, [ 200, { id: 1 } ]); }); httpBrowserWrapper = new HttpBrowserWrapper("token", 'https://api.moj.io/v1', false, new XMLHttpRequest()); return httpBrowserWrapper.request({ method: 'Get', resource: "Vehicles", pid: "1" }, (function(_this) { return function(error, result) { testErrorResult(error, result); return done(); }; })(this)); }); return it('tests @request get resource with id and form url encoding', function(done) { var httpBrowserWrapper; nock('https://api.moj.io').get('/v1/Vehicles/2').reply(function(uri, requestBody, cb) { if (!unittest) { this.req.headers.mojioapitoken.should.be.equal(token); } this.req.headers['content-type'].should.be.equal(contentType); this.req.headers['host'].should.be.equal("api.moj.io"); return cb(null, [ 200, { id: 1 } ]); }); httpBrowserWrapper = new HttpBrowserWrapper("token", 'https://api.moj.io/v1', true, new XMLHttpRequest()); return httpBrowserWrapper.request({ method: 'Get', resource: "Vehicles", pid: "2" }, (function(_this) { return function(error, result) { testErrorResult(error, result); return done(); }; })(this)); }); }); }).call(this); //# sourceMappingURL=HttpBrowserWrapper_test.js.map