cs-mpx-dataservice
Version:
MPX Dataservices
63 lines (45 loc) • 1.65 kB
JavaScript
/**
* Created by paul.rangel on 6/9/15.
*/
var expect = require("chai").expect;
var accountToken = require("./data/accountToken");
var DataService = require("../lib/dataService");
var uid = require('muid');
var should = require("should");
describe("post(Endpoint, {})", function() {
DataService.init(accountToken.account, accountToken.token);
var Endpoint = DataService.Endpoint;
Endpoint.registerDataService("Category", 'Media Data Service', '1.7.0', 'Category');
before(function(done) {
Endpoint.init(accountToken.account, accountToken.token).then(function(epts) {
done();
});
});
var params = {
_title : "TestTitle_"+uid(20),
_scheme : "nav",
fields : "title"
};
it("Should POST a new category and return object with title = "+params._title, function(done) {
this.timeout(3000);
DataService.post(Endpoint.getEndpoint('Category'), params)
.then(function(data) {
data.title.should.eql(params._title);
console.log(data);
done();
}).catch(function(err) {
console.error(err);
});
});
it("Should POST should throw a 422 error if trying to submit the same title", function(done) {
this.timeout(3000);
DataService.post(Endpoint.getEndpoint('Category'), params)
.then(function(data) {
data.title.should.not.eql(params._title);
done();
}).catch(function(err) {
err.code.should.eql(422);
done();
});
});
});