7digital-api
Advanced tools
Comparing version 0.6.1 to 0.6.3
@@ -33,2 +33,3 @@ var http = require('http'), | ||
this.host = options.host; | ||
this.port = options.port || 80; | ||
this.version = options.version; | ||
@@ -45,4 +46,2 @@ this.logger = options.logger; | ||
this.consumersecret); | ||
} else { | ||
this.client = http.createClient(80, this.host); | ||
} | ||
@@ -85,3 +84,3 @@ }; | ||
Request.prototype.formatPath = function (resource, action) { | ||
var requestPath = '/' + this.version + '/' + resource; | ||
var requestPath = '/' + (this.version ? this.version + '/' : '') + resource; | ||
@@ -145,2 +144,6 @@ if (action !== '') { | ||
function cacheAndCallback(err, data, response) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
var ttl = self.parseMaxAge(response); | ||
@@ -228,2 +231,3 @@ | ||
self.logger.error(err); | ||
callback(err); | ||
return; | ||
@@ -261,5 +265,9 @@ } | ||
this.logger.info(httpMethod + ': ' + url); | ||
apiRequest = this.client.request(httpMethod, url, this.createHeaders()); | ||
apiRequest.on('response', function handleResponse(response) { | ||
apiRequest = http.request({ | ||
method: httpMethod, | ||
hostname: this.host, | ||
path: url, | ||
port: this.port, | ||
headers: this.createHeaders() | ||
}, function handleResponse(response) { | ||
var responseBuffer = ''; | ||
@@ -274,3 +282,4 @@ | ||
if (+response.statusCode > 400) { | ||
return callback(new ApiError(response.statusCode, responseBuffer)); | ||
return callback(new ApiError( | ||
response.statusCode, responseBuffer)); | ||
} | ||
@@ -277,0 +286,0 @@ callback(null, responseBuffer, response); |
@@ -25,2 +25,3 @@ var underscore = require('underscore'), | ||
this.host = options.schema.host; | ||
this.port = options.schema.port; | ||
this.version = options.schema.version; | ||
@@ -83,2 +84,3 @@ this.consumerkey = options.consumerkey; | ||
host: this.host, | ||
port: this.port, | ||
version: this.version, | ||
@@ -85,0 +87,0 @@ consumerkey: this.consumerkey, |
@@ -50,4 +50,5 @@ var xml2js = require('xml2js'), | ||
if (response.basket && response.basket.basketItems | ||
&& response.basket.basketItems.basketItem) { | ||
if (response.basket && response.basket.basketItems && | ||
response.basket.basketItems.basketItem) { | ||
items = response.basket.basketItems.basketItem; | ||
@@ -90,17 +91,25 @@ items = items.length ? items : [items]; | ||
this.logger.silly(response); | ||
parser.on('end', function (result) { | ||
parser.parseString(response + '', function (err, result) { | ||
// Manually remove the xml namespace bits | ||
delete result['xmlns:xsi']; | ||
delete result['xsi:noNamespaceSchemaLocation']; | ||
if (result.response.status === 'error') { | ||
callback(result.response.error); | ||
if (err) { | ||
callback(new Error(err)); | ||
} else if (!result.response) { | ||
callback(new Error('unexpected response returned by api')); | ||
} else { | ||
delete result['xmlns:xsi']; | ||
delete result['xsi:noNamespaceSchemaLocation']; | ||
if (result.response.status === 'error') { | ||
callback(result.response.error); | ||
} else if (result.response.status !== 'ok') { | ||
callback(new Error('unrecognised response status "' + | ||
result.response.status + '" from api')); | ||
} | ||
else { | ||
var normalisedResult = self.normaliseResourceArrays(result.response); | ||
callback(null, normalisedResult); | ||
} | ||
} | ||
else { | ||
var normalisedResult = self.normaliseResourceArrays(result.response); | ||
callback(null, normalisedResult); | ||
} | ||
}); | ||
parser.parseString(response + ''); | ||
}; | ||
module.exports = ResponseParser; |
{ | ||
"name": "7digital-api", | ||
"version": "0.6.1", | ||
"version": "0.6.3", | ||
"description": "7digital API client for nodeJS", | ||
@@ -25,7 +25,7 @@ "homepage": [ | ||
"scripts": { | ||
"test": "jasmine-node --verbose spec/" | ||
"test": "./node_modules/.bin/mocha spec/" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"xml2js": "~0.2.8", | ||
"xml2js": "~0.4.1", | ||
"oauth": "0.9.5", | ||
@@ -39,4 +39,6 @@ "step": "~0.0.5", | ||
"docco": "0.3.0", | ||
"jasmine-node": "~1.9.0", | ||
"jshint": "0.3.0" | ||
"jshint": "0.3.0", | ||
"mocha": "~1.15.1", | ||
"chai": "~1.8.1", | ||
"sinon": "~1.7.3" | ||
}, | ||
@@ -43,0 +45,0 @@ "contributors": [ |
@@ -70,4 +70,39 @@ ![7digital](http://i.imgur.com/StUnvCy.png?1) | ||
To run the tests: | ||
TESTS | ||
===== | ||
To run the unit tests: | ||
npm test | ||
There are also integration tests. Tests for various error handling scenarios | ||
are run against a stub 7d api. It can be installed | ||
with: | ||
npm install git://github.com/7digital/api-stub.git | ||
Some of the integration tests (around the client's handling of OAuth) run | ||
against the real 7d api. In order for these tests to work, several environment | ||
variables need to be set: | ||
- `NODE_API_CLIENT_TESTS_CONSUMER_KEY` | ||
- `NODE_API_CLIENT_TESTS_CONSUMER_SECRET` | ||
Your 7d api key and secret, which can be obtained from | ||
http://access.7digital.com/partnerprogram | ||
- `NODE_API_CLIENT_TESTS_VOUCHER_CODE` | ||
The code for a voucher which can be applied to a basket containing an item of | ||
1p, used for a two-legged OAuth test. | ||
- `NODE_API_CLIENT_TESTS_USER_TOKEN` | ||
- `NODE_API_CLIENT_TESTS_USER_SECRET` | ||
A token and secret for access to any user's resources for a given consumer key | ||
and secret. These are used for 3-legged OAuth tests, and can be obtained by | ||
running `node ./examples/oauth.js` and following the prompts. | ||
If these vars are set, the tests can then be run with: | ||
mocha spec-integration/ |
@@ -0,6 +1,6 @@ | ||
var expect = require('chai').expect; | ||
var ApiError = require('../lib/apierror'), | ||
winston = require('winston'); | ||
require('./custom-matchers.js'); | ||
describe('API Error', function() { | ||
@@ -12,3 +12,3 @@ | ||
expect(err.message).toEqual(msg); | ||
expect(err.message).to.equal(msg); | ||
}); | ||
@@ -19,3 +19,3 @@ | ||
expect(err.message).toEqual('Unexpected 401 status code'); | ||
expect(err.message).to.equal('Unexpected 401 status code'); | ||
}); | ||
@@ -26,4 +26,4 @@ | ||
expect(err.message).toEqual('Unexpected 401 status code'); | ||
expect(err.message).to.equal('Unexpected 401 status code'); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
var expect = require('chai').expect; | ||
var winston = require('winston'), | ||
@@ -6,4 +8,2 @@ api = require('../index').configure({ | ||
require('./custom-matchers.js'); | ||
describe("Artists actions", function() { | ||
@@ -18,40 +18,40 @@ | ||
it("should generate a browse method for the browse action", function() { | ||
expect(artists.browse).toBeDefined(); | ||
expect(artists.browse).toBeDefined(); | ||
expect(artists.browse).to.exist; | ||
expect(artists.browse).to.exist; | ||
}); | ||
it("should generate a getChart method for the chart action", function() { | ||
expect(artists.getChart).toBeDefined(); | ||
expect(artists.getChart).toBeAFunction(); | ||
expect(artists.getChart).to.exist; | ||
expect(artists.getChart).to.be.a('function'); | ||
}); | ||
it("should generate a getDetails method for the details action", function() { | ||
expect(artists.getDetails).toBeDefined(); | ||
expect(artists.getDetails).toBeAFunction(); | ||
expect(artists.getDetails).to.exist; | ||
expect(artists.getDetails).to.be.a('function'); | ||
}); | ||
it("should generate a getReleases method for the releases action", function() { | ||
expect(artists.getReleases).toBeDefined(); | ||
expect(artists.getReleases).toBeAFunction(); | ||
expect(artists.getReleases).to.exist; | ||
expect(artists.getReleases).to.be.a('function'); | ||
}); | ||
it("should generate a search method for the search action", function() { | ||
expect(artists.search).toBeDefined(); | ||
expect(artists.search).toBeAFunction(); | ||
expect(artists.search).to.exist; | ||
expect(artists.search).to.be.a('function'); | ||
}); | ||
it("should generate a getTopTracks method for the toptracks action", function() { | ||
expect(artists.getTopTracks).toBeDefined(); | ||
expect(artists.getTopTracks).toBeAFunction(); | ||
expect(artists.getTopTracks).to.exist; | ||
expect(artists.getTopTracks).to.be.a('function'); | ||
}); | ||
it("should generate a getTags method for the tags action", function() { | ||
expect(artists.getTags).toBeDefined(); | ||
expect(artists.getTags).toBeAFunction(); | ||
expect(artists.getTags).to.exist; | ||
expect(artists.getTags).to.be.a('function'); | ||
}); | ||
it("should generate a getTopByTags method for the bytag/top action", function() { | ||
expect(artists.getTopByTags).toBeDefined(); | ||
expect(artists.getTopByTags).toBeAFunction(); | ||
expect(artists.getTopByTags).to.exist; | ||
expect(artists.getTopByTags).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
var expect = require('chai').expect; | ||
var winston = require('winston'), | ||
@@ -6,4 +8,2 @@ api = require('../index').configure({ | ||
require('./custom-matchers.js'); | ||
describe("Basket actions", function() { | ||
@@ -18,20 +18,20 @@ | ||
it("should generate a create method for the create action", function() { | ||
expect(basket.create).toBeDefined(); | ||
expect(basket.create).toBeAFunction(); | ||
expect(basket.create).to.exist; | ||
expect(basket.create).to.be.a('function'); | ||
}); | ||
it("should generate a get method for the default action", function() { | ||
expect(basket.get).toBeDefined(); | ||
expect(basket.get).toBeAFunction(); | ||
expect(basket.get).to.exist; | ||
expect(basket.get).to.be.a('function'); | ||
}); | ||
it("should generate an addItem method for the addItem action", function() { | ||
expect(basket.addItem).toBeDefined(); | ||
expect(basket.addItem).toBeAFunction(); | ||
expect(basket.addItem).to.exist; | ||
expect(basket.addItem).to.be.a('function'); | ||
}); | ||
it("should generate a removeItem method for the removeItem action", function() { | ||
expect(basket.removeItem).toBeDefined(); | ||
expect(basket.removeItem).toBeAFunction(); | ||
expect(basket.removeItem).to.exist; | ||
expect(basket.removeItem).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,6 +1,6 @@ | ||
var expect = require('chai').expect; | ||
var Api = require('../lib/api').Api, | ||
winston = require('winston'); | ||
require('./custom-matchers.js'); | ||
describe('API.build', function() { | ||
@@ -34,7 +34,7 @@ var schema = { | ||
it('should return a wrapper', function() { | ||
expect(api).not.toBeNull(); | ||
expect(api).not.to.be.null; | ||
}); | ||
it('should create an API constructor for each resource', function() { | ||
expect(api.Test).toBeDefined(); | ||
expect(api.Test).to.exist; | ||
}); | ||
@@ -53,4 +53,4 @@ | ||
expect(testApi.consumerkey).toEqual('testkey'); | ||
expect(testApi.consumersecret).toEqual('testsecret'); | ||
expect(testApi.consumerkey).to.equal('testkey'); | ||
expect(testApi.consumersecret).to.equal('testsecret'); | ||
}); | ||
@@ -60,12 +60,12 @@ | ||
function() { | ||
expect(testApi.host).toEqual('api.example.com'); | ||
expect(testApi.version).toEqual('1.0'); | ||
expect(testApi.resourceName).toEqual('testresource'); | ||
expect(testApi.host).to.equal('api.example.com'); | ||
expect(testApi.version).to.equal('1.0'); | ||
expect(testApi.resourceName).to.equal('testresource'); | ||
}); | ||
it('should create a method for each action', function() { | ||
expect(testApi.getByDate).toBeDefined(); | ||
expect(testApi.getByDate).toBeAFunction(); | ||
expect(testApi.getByDate).to.exist; | ||
expect(testApi.getByDate).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
var expect = require('chai').expect; | ||
var helpers = require('../lib/helpers'); | ||
@@ -6,6 +8,6 @@ | ||
var result = helpers.capitalize('seven'); | ||
expect(result[0]).toEqual('S'); | ||
expect(result).toEqual('Seven'); | ||
expect(result[0]).to.equal('S'); | ||
expect(result).to.equal('Seven'); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
var expect = require('chai').expect; | ||
describe('config', function() { | ||
@@ -5,20 +7,20 @@ var config = require('../config'); | ||
it('should have the default consumer key', function() { | ||
expect(config.consumerkey).toEqual('YOUR_KEY_HERE'); | ||
expect(config.consumerkey).to.equal('YOUR_KEY_HERE'); | ||
}); | ||
it('should have an empty oauthsecret', function() { | ||
expect(config.consumersecret).toEqual('YOUR_SECRET_HERE'); | ||
expect(config.consumersecret).to.equal('YOUR_SECRET_HERE'); | ||
}); | ||
it('should have the path to the schema json', function() { | ||
expect(config.schemapath).toMatch(/assets\/7digital-api-schema.json$/); | ||
expect(config.schemapath).to.match(/assets\/7digital-api-schema.json$/); | ||
}); | ||
it('should have debug', function() { | ||
expect(config.debug).toEqual(true); | ||
expect(config.debug).to.equal(true); | ||
}); | ||
it('should have the response format set to JSON by default', function() { | ||
expect(config.format).toEqual('json'); | ||
expect(config.format).to.equal('json'); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
var expect = require('chai').expect; | ||
describe('Examples', function() { | ||
@@ -8,16 +10,9 @@ | ||
it('should return return some releases', function() { | ||
var processReturned = false; | ||
it('should return return some releases', function(done) { | ||
exec('node ' + path.join(__dirname, '../examples/customconfig.js'), | ||
function assertOutput(err, stdout, stderr) { | ||
var result; | ||
expect(err).toBeFalsy(); | ||
expect(stdout).toMatch('releases'); | ||
processReturned = true; | ||
expect(err).to.equal(null); | ||
expect(stdout).to.match(/releases/); | ||
done(); | ||
}); | ||
waitsFor(function () { | ||
return processReturned; | ||
}, "Timed out waiting for process to return", 5000); | ||
}); | ||
@@ -32,16 +27,9 @@ | ||
it('should return return some releases', function() { | ||
var processReturned = false; | ||
it('should return return some releases', function(done) { | ||
exec('node ' + path.join(__dirname, '../examples/simpleclient.js'), | ||
function assertOutput(err, stdout, stderr) { | ||
var result; | ||
expect(err).toBeFalsy(); | ||
expect(stdout).toMatch('releases'); | ||
processReturned = true; | ||
expect(err).to.be.null; | ||
expect(stdout).to.match(/releases/); | ||
done() | ||
}); | ||
waitsFor(function () { | ||
return processReturned; | ||
}, "Timed out waiting for process to return", 5000); | ||
}); | ||
@@ -56,16 +44,9 @@ | ||
it('should return return some tags', function() { | ||
var processReturned = false; | ||
it('should return return some tags', function(done) { | ||
exec('node ' + path.join(__dirname, '../examples/default-action.js'), | ||
function assertOutput(err, stdout, stderr) { | ||
var result; | ||
expect(err).toBeFalsy(); | ||
expect(stdout).toMatch('tags'); | ||
processReturned = true; | ||
expect(err).to.be.null; | ||
expect(stdout).to.match(/tags/); | ||
done(); | ||
}); | ||
waitsFor(function () { | ||
return processReturned; | ||
}, "Timed out waiting for process to return", 5000); | ||
}); | ||
@@ -72,0 +53,0 @@ |
@@ -0,16 +1,15 @@ | ||
var expect = require('chai').expect; | ||
var sevendigital = require("../index"); | ||
require('./custom-matchers.js'); | ||
describe('Module entry point', function() { | ||
it('should be the built 7digital API wrapper', function() { | ||
expect(sevendigital.Artists).toBeDefined(); | ||
expect(sevendigital.Artists).toBeAFunction(); | ||
expect(sevendigital.Artists).to.exist; | ||
expect(sevendigital.Artists).to.be.a('function'); | ||
}); | ||
it('should expose the schema', function() { | ||
expect(sevendigital.schema.host).toBeDefined(); | ||
expect(sevendigital.schema.host).to.exist; | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var expect = require('chai').expect; | ||
var helpers = require('../lib/helpers'); | ||
@@ -7,3 +8,3 @@ | ||
var result = helpers.padComponent(9); | ||
expect(result).toEqual('09'); | ||
expect(result).to.equal('09'); | ||
}); | ||
@@ -13,5 +14,5 @@ | ||
var result = helpers.padComponent(10); | ||
expect(result).toEqual('10'); | ||
expect(result).to.equal('10'); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var expect = require('chai').expect; | ||
var winston = require('winston'), | ||
@@ -6,4 +7,2 @@ api = require('../index').configure({ | ||
require('./custom-matchers.js'); | ||
describe("Releases actions", function() { | ||
@@ -18,45 +17,45 @@ | ||
it("should generate a getByDate method for the byDate action", function() { | ||
expect(releases.getByDate).toBeDefined(); | ||
expect(releases.getByDate).toBeAFunction(); | ||
expect(releases.getByDate).to.exist; | ||
expect(releases.getByDate).to.be.a('function'); | ||
}); | ||
it("should generate a getDetails method for the details action", function() { | ||
expect(releases.getDetails).toBeDefined(); | ||
expect(releases.getDetails).toBeAFunction(); | ||
expect(releases.getDetails).to.exist; | ||
expect(releases.getDetails).to.be.a('function'); | ||
}); | ||
it("should generate a getChart method for the chart action", function() { | ||
expect(releases.getChart).toBeDefined(); | ||
expect(releases.getChart).toBeAFunction(); | ||
expect(releases.getChart).to.exist; | ||
expect(releases.getChart).to.be.a('function'); | ||
}); | ||
it("should generate a getRecommendations method for the recommend action", function() { | ||
expect(releases.getRecommendations).toBeDefined(); | ||
expect(releases.getRecommendations).toBeAFunction(); | ||
expect(releases.getRecommendations).to.exist; | ||
expect(releases.getRecommendations).to.be.a('function'); | ||
}); | ||
it("should generate a search method for the search action", function() { | ||
expect(releases.search).toBeDefined(); | ||
expect(releases.search).toBeAFunction(); | ||
expect(releases.search).to.exist; | ||
expect(releases.search).to.be.a('function'); | ||
}); | ||
it("should generate a getTracks method for the tracks action", function() { | ||
expect(releases.getTracks).toBeDefined(); | ||
expect(releases.getTracks).toBeAFunction(); | ||
expect(releases.getTracks).to.exist; | ||
expect(releases.getTracks).to.be.a('function'); | ||
}); | ||
it("should generate a getTags method for the tags action", function() { | ||
expect(releases.getTags).toBeDefined(); | ||
expect(releases.getTags).toBeAFunction(); | ||
expect(releases.getTags).to.exist; | ||
expect(releases.getTags).to.be.a('function'); | ||
}); | ||
it("should generate a getNewByTags method for the bytag/new action", function() { | ||
expect(releases.getNewByTags).toBeDefined(); | ||
expect(releases.getNewByTags).toBeAFunction(); | ||
expect(releases.getNewByTags).to.exist; | ||
expect(releases.getNewByTags).to.be.a('function'); | ||
}); | ||
it("should generate a getTopByTags method for the bytag/top action", function() { | ||
expect(releases.getNewByTags).toBeDefined(); | ||
expect(releases.getNewByTags).toBeAFunction(); | ||
expect(releases.getNewByTags).to.exist; | ||
expect(releases.getNewByTags).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,5 +1,7 @@ | ||
var expect = require('chai').expect; | ||
var ResponseParser = require('../lib/responseparser'), | ||
winston = require('winston'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
path = require('path'), | ||
sinon = require('sinon'); | ||
@@ -12,12 +14,4 @@ describe('responseparser', function() { | ||
beforeEach(function() { | ||
this.addMatchers({ | ||
toBeAnArray: function() { | ||
return this.actual.constructor.toString().indexOf('Array') !== -1; | ||
} | ||
}) | ||
}); | ||
it('should return xml when format is xml', function() { | ||
var callbackSpy = jasmine.createSpy(), | ||
var callbackSpy = sinon.spy(), | ||
xml = fs.readFileSync( | ||
@@ -28,8 +22,8 @@ path.join(__dirname + | ||
parser.parse(callbackSpy, null, xml); | ||
expect(callbackSpy).toHaveBeenCalled(); | ||
expect(callbackSpy).toHaveBeenCalledWith(null, xml); | ||
expect(callbackSpy.calledOnce); | ||
expect(callbackSpy.calledWith(null, xml)); | ||
}); | ||
it('should return xml when format is XML', function() { | ||
var callbackSpy = jasmine.createSpy(), | ||
var callbackSpy = sinon.spy(), | ||
xml = fs.readFileSync( | ||
@@ -42,8 +36,8 @@ path.join(__dirname + | ||
parser.parse(callbackSpy, null, xml); | ||
expect(callbackSpy).toHaveBeenCalled(); | ||
expect(callbackSpy).toHaveBeenCalledWith(null, xml); | ||
expect(callbackSpy.calledOnce); | ||
expect(callbackSpy.calledWith(null, xml)); | ||
}); | ||
it('should return javascript object when format is not xml', function() { | ||
var callbackSpy = jasmine.createSpy(), | ||
var callbackSpy = sinon.spy(), | ||
xml = fs.readFileSync( | ||
@@ -56,8 +50,8 @@ path.join(__dirname + | ||
parser.parse(callbackSpy, null, xml); | ||
expect(callbackSpy).toHaveBeenCalled(); | ||
expect(typeof callbackSpy.mostRecentCall.args[1]).toEqual('object'); | ||
expect(callbackSpy.calledOnce); | ||
expect(typeof callbackSpy.lastCall.args[1]).to.equal('object'); | ||
}); | ||
it('should callback with the error when the status is error', function () { | ||
var callbackSpy = jasmine.createSpy(), | ||
var callbackSpy = sinon.spy(), | ||
xml = fs.readFileSync( | ||
@@ -69,13 +63,13 @@ path.join(__dirname, 'responses', 'release-not-found.xml'), | ||
parser.parse(callbackSpy, null, xml) | ||
expect(callbackSpy).toHaveBeenCalled(); | ||
var error = callbackSpy.mostRecentCall.args[0]; | ||
var response = callbackSpy.mostRecentCall.args[1]; | ||
expect(error).toBeDefined(); | ||
expect(response).not.toBeDefined(); | ||
expect(error.code).toEqual('2001'); | ||
expect(error.errorMessage).toEqual("Release not found"); | ||
expect(callbackSpy.calledOnce) | ||
var error = callbackSpy.lastCall.args[0]; | ||
var response = callbackSpy.lastCall.args[1]; | ||
expect(error).to.not.equal(undefined); | ||
expect(response).to.equal(undefined); | ||
expect(error.code).to.equal('2001'); | ||
expect(error.errorMessage).to.equal("Release not found"); | ||
}); | ||
it('should normalise single resource responses into an array', function() { | ||
var callbackSpy = jasmine.createSpy(), | ||
var callbackSpy = sinon.spy(), | ||
xml = fs.readFileSync( | ||
@@ -88,5 +82,5 @@ path.join(__dirname + | ||
parser.parse(callbackSpy, null, xml); | ||
expect(callbackSpy).toHaveBeenCalled(); | ||
var response = callbackSpy.mostRecentCall.args[1]; | ||
expect(response.tracks.track).toBeAnArray(); | ||
expect(callbackSpy.calledOnce) | ||
var response = callbackSpy.lastCall.args[1]; | ||
expect(response.tracks.track).to.be.instanceOf(Array); | ||
}); | ||
@@ -97,3 +91,3 @@ | ||
it("should normalise basket items into an array", function () { | ||
var callbackSpy = jasmine.createSpy() | ||
var callbackSpy = sinon.spy() | ||
xml = fs.readFileSync(path.join(__dirname + | ||
@@ -103,6 +97,6 @@ "/responses/basket-additem.xml"), "utf8"); | ||
parser.parse(callbackSpy, null, xml); | ||
expect(callbackSpy).toHaveBeenCalled(); | ||
response = callbackSpy.mostRecentCall.args[1]; | ||
expect(response.basket.basketItems).toBeAnArray(); | ||
expect(callbackSpy.calledOnce) | ||
response = callbackSpy.lastCall.args[1]; | ||
expect(response.basket.basketItems).to.be.instanceOf(Array); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var expect = require('chai').expect; | ||
var winston = require('winston'), | ||
@@ -6,4 +7,2 @@ api = require('../index').configure({ | ||
require('./custom-matchers.js'); | ||
describe("Tags actions", function() { | ||
@@ -18,6 +17,6 @@ | ||
it("should generate an all method for the default action", function() { | ||
expect(tags.all).toBeDefined(); | ||
expect(tags.all).toBeAFunction(); | ||
expect(tags.all).to.exist; | ||
expect(tags.all).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var expect = require('chai').expect; | ||
var winston = require('winston'), | ||
@@ -6,4 +7,2 @@ api = require('../index').configure({ | ||
require('./custom-matchers.js'); | ||
describe("Territories actions", function() { | ||
@@ -18,5 +17,5 @@ | ||
it("should generate a getCountries method for the default action", function() { | ||
expect(territories.getCountries).toBeDefined(); | ||
expect(territories.getCountries).toBeAFunction(); | ||
expect(territories.getCountries).to.exist; | ||
expect(territories.getCountries).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var expect = require('chai').expect; | ||
var helpers = require('../lib/helpers'); | ||
@@ -8,5 +9,5 @@ | ||
var result = helpers.toYYYYMMDD(theDate); | ||
expect(result).toEqual('19751013'); | ||
expect(result).to.equal('19751013'); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var expect = require('chai').expect; | ||
var winston = require('winston'), | ||
@@ -6,4 +7,2 @@ api = require('../index').configure({ | ||
require('./custom-matchers.js'); | ||
describe("Tracks actions", function() { | ||
@@ -18,20 +17,20 @@ | ||
it("should generate a getChart method for the chart action", function() { | ||
expect(tracks.getChart).toBeDefined(); | ||
expect(tracks.getChart).toBeAFunction(); | ||
expect(tracks.getChart).to.exist; | ||
expect(tracks.getChart).to.be.a('function'); | ||
}); | ||
it("should generate a getDetails method for the details action", function() { | ||
expect(tracks.getDetails).toBeDefined(); | ||
expect(tracks.getDetails).toBeAFunction(); | ||
expect(tracks.getDetails).to.exist; | ||
expect(tracks.getDetails).to.be.a('function'); | ||
}); | ||
it("should generate a getPreview method for the preview action", function() { | ||
expect(tracks.getPreview).toBeDefined(); | ||
expect(tracks.getPreview).toBeAFunction(); | ||
expect(tracks.getPreview).to.exist; | ||
expect(tracks.getPreview).to.be.a('function'); | ||
}); | ||
it("should generate a search method for the search action", function() { | ||
expect(tracks.search).toBeDefined(); | ||
expect(tracks.search).toBeAFunction(); | ||
expect(tracks.search).to.exist; | ||
expect(tracks.search).to.be.a('function'); | ||
}); | ||
}); |
@@ -0,5 +1,4 @@ | ||
var expect = require('chai').expect; | ||
var Api = require('../lib/api').Api; | ||
require('./custom-matchers.js'); | ||
describe('url translation', function() { | ||
@@ -35,3 +34,3 @@ var schema = { | ||
'nonexistentactionslug'); | ||
expect(methodName).toEqual(''); | ||
expect(methodName).to.equal(''); | ||
}); | ||
@@ -42,3 +41,3 @@ | ||
var methodName = api.getActionMethodName('Test', 'byDate'); | ||
expect(methodName).toEqual('getByDate'); | ||
expect(methodName).to.equal('getByDate'); | ||
}); | ||
@@ -49,3 +48,3 @@ | ||
var methodName = api.getActionMethodName('Test', 'BYDATE'); | ||
expect(methodName).toEqual('getByDate'); | ||
expect(methodName).to.equal('getByDate'); | ||
}); | ||
@@ -55,3 +54,3 @@ | ||
var methodName = api.getActionMethodName('Test', 'test'); | ||
expect(methodName).toEqual('expectedName'); | ||
expect(methodName).to.equal('expectedName'); | ||
}); | ||
@@ -62,3 +61,3 @@ | ||
var methodName = api.getActionMethodName('Test', 'TEST'); | ||
expect(methodName).toEqual('expectedName'); | ||
expect(methodName).to.equal('expectedName'); | ||
}); | ||
@@ -70,4 +69,4 @@ | ||
''); | ||
expect(methodName).toEqual('get'); | ||
expect(methodName).to.equal('get'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
87196
49
1775
108
5
8
5
+ Addedsax@1.4.1(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
- Removedsax@0.5.8(transitive)
- Removedxml2js@0.2.8(transitive)
Updatedxml2js@~0.4.1