cs-mpx-dataservice
Version:
MPX Dataservices
51 lines (42 loc) • 1.79 kB
JavaScript
/**
* Created by paul.rangel on 4/27/15.
*/
var expect = require("chai").expect;
var generateParams = require("../lib/generateParams");
describe("generateParams():", function() {
var endpoint = {schema : 2};
var params = {
'fields': "one,two,three",
'byStationId': "SomeStationID",
'byCustomValue': '{isNext}{true}',
'sort': 'updated|desc'
};
it("Expect token and account id to be set", function() {
var params = generateParams("token","account-id")(endpoint);
expect(params.token).to.eql("token");
expect(params.account).to.eql("account-id");
});
it("Should throw and error if the endpoint is not set", function() {
expect(function() {
generateParams("token","account-id")();
}).to.throw("generateParams: Endpoint not set or wrong number of args");
});
it("Should throw an error if the endpoint does not have a schema", function() {
expect(function() {
generateParams("token","account-id")({});
}).to.throw("generateParams: First object is not an endpoint" );
});
it("schema from endpoint should be set if passed in", function() {
var result = generateParams("token","account-id")(endpoint);
expect(result.schema).to.eql(2);
});
it("Should have the correct method parameter", function() {
var result = generateParams("token","account-id")(endpoint, {'method' : 'post'});
expect(result.method).to.eql("post");
});
it("Should merge additional params correctly", function() {
var result = generateParams("token","account-id")(endpoint, {'method':'get'}, params);
expect(result.sort).to.eql('updated|desc');
expect(result.method).to.eql('get');
});
});