cs-mpx-dataservice
Version:
MPX Dataservices
108 lines (83 loc) • 3.1 kB
JavaScript
/**
* Created by paul.rangel on 6/10/15.
*/
var expect = require("chai").expect;
var accountToken = require("./data/accountToken");
var DataService = require("../lib/dataService");
var uid = require('muid');
var should = require("should");
var flashPostBridge = require('../lib/flashPostBridge');
describe("FlashPostBridge setup", function() {
it("Should initialize the posting bridge on the DOM", function(done) {
flashPostBridge.init().then(function() {
should(window['FlashPostingBridge']).not.equal(null);
done();
});
});
});
describe("FlashPostBridge post(Endpoint, {})", function() {
DataService.init(accountToken.account, accountToken.token);
var Endpoint = DataService.Endpoint;
Endpoint.registerDataService("Category", 'Media Data Service', '1.7.0', 'Category', {putMethod: 'Flash'});
before(function(done) {
Endpoint.init(accountToken.account, accountToken.token).then(function(epts) {
done();
});
});
var params = {
title : "TestTitle_"+uid(20),
scheme : "nav",
fields : "title"
};
var newCategoryId;
it("Should POST a new category and return object with title = "+params.title, function(done) {
DataService.post(Endpoint.getEndpoint('Category'), params, "title")
.then(function(data) {
console.log(data);
newCategoryId = data.id;
data.title.should.eql(params.title);
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) {
done();
}).catch(function(err) {
err.code.should.eql(422);
done();
});
});
var params2 = {
title : "Paul_RULES"+uid(20),
id : newCategoryId,
fields : "title"
};
console.log("id: ",params2.id);
it("Should POST a new category and return object with title = "+params2.title, function(done) {
this.timeout(3000);
DataService.put(Endpoint.getEndpoint('Category'), params2)
.then(function(data) {
console.log("done: ",data);
data.should.have.property("title");
params2.title.should.equal(data.title);
done();
}).catch(function(err) {
done(err);
});
});
it("Should delete the new Category", function(done) {
DataService.remove(Endpoint.getEndpoint('Category'), newCategoryId)
.then(function(data) {
console.log("done deleting: ",data);
data.entries.length.should.equal(0);
data.totalResults.should.equal(1);
done();
}).catch(function(err) {
done(err);
});
})
});