Skip to content

Commit

Permalink
test(endpoints): alphabetical ordering of endpoints and a programmati…
Browse files Browse the repository at this point in the history
…cally resolved list of endpoint tests
  • Loading branch information
jzsfkzm committed Aug 12, 2015
1 parent 58c6e7e commit 106b72d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 47 deletions.
26 changes: 15 additions & 11 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

var SuiteRequest = require('escher-suiteapi-js');
var ApiRequest = require('./../lib/api-request');

var AdministratorAPI = require('./endpoints/administrator');
var ContactAPI = require('./endpoints/contact');
var ContactListAPI = require('./endpoints/contactlist');
var LanguageAPI = require('./endpoints/language');
var ExternalEventAPI = require('./endpoints/externalevent');
var SettingsAPI = require('./endpoints/settings');
var EmailAPI = require('./endpoints/email');
var ExternalEventAPI = require('./endpoints/externalevent');
var FieldAPI = require('./endpoints/field');
var SegmentAPI = require('./endpoints/segment');
var LanguageAPI = require('./endpoints/language');
var PurchaseAPI = require('./endpoints/purchase');
var SegmentAPI = require('./endpoints/segment');
var SettingsAPI = require('./endpoints/settings');

var KeyPool = require('escher-keypool');
var _ = require('lodash');

Expand All @@ -25,12 +27,12 @@ var SuiteAPI = function(options) {
this.contact = ContactAPI.create(this._apiRequest, options);
this.contactList = ContactListAPI.create(this._apiRequest, options);
this.email = EmailAPI.create(this._apiRequest, options);
this.externalEvent = ExternalEventAPI.create(this._apiRequest, options);
this.field = FieldAPI.create(this._apiRequest, options);
this.segment = SegmentAPI.create(this._apiRequest, options);
this.language = LanguageAPI.create(this._apiRequest, options);
this.externalEvent = ExternalEventAPI.create(this._apiRequest, options);
this.settings = SettingsAPI.create(this._apiRequest, options);
this.purchase = PurchaseAPI.create(this._apiRequest, options);
this.segment = SegmentAPI.create(this._apiRequest, options);
this.settings = SettingsAPI.create(this._apiRequest, options);

this.environment = options.environment;
};
Expand Down Expand Up @@ -90,14 +92,16 @@ SuiteAPI.createWithCache = function(cacheId, options) {


module.exports = SuiteAPI;

module.exports.Administrator = AdministratorAPI;
module.exports.Contact = ContactAPI;
module.exports.ContactList = ContactListAPI;
module.exports.Language = LanguageAPI;
module.exports.ExternalEvent = ExternalEventAPI;
module.exports.Settings = SettingsAPI;
module.exports.Purchase = PurchaseAPI;
module.exports.Email = EmailAPI;
module.exports.ExternalEvent = ExternalEventAPI;
module.exports.Field = FieldAPI;
module.exports.Language = LanguageAPI;
module.exports.Purchase = PurchaseAPI;
module.exports.Segment = SegmentAPI;
module.exports.Settings = SettingsAPI;

module.exports.SuiteRequestError = SuiteRequest.Error;
119 changes: 83 additions & 36 deletions api/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

var SuiteRequest = require('escher-suiteapi-js');
var SuiteAPI = require('./');

var AdministratorAPI = require('./endpoints/administrator');
var ContactAPI = require('./endpoints/contact');
var ContactListAPI = require('./endpoints/contactlist');
var EmailAPI = require('./endpoints/email');
var SegmentAPI = require('./endpoints/segment');
var LanguageAPI = require('./endpoints/language');
var ExternalEventAPI = require('./endpoints/externalevent');
var FieldAPI = require('./endpoints/field');
var LanguageAPI = require('./endpoints/language');
var PurchaseAPI = require('./endpoints/purchase');
var SegmentAPI = require('./endpoints/segment');
var SettingsAPI = require('./endpoints/settings');

var Request = require('./../lib/api-request');
var expect = require('chai').expect;
var SuiteRequestOptions = SuiteRequest.Options;
Expand Down Expand Up @@ -166,11 +171,15 @@ describe('SuiteApi', function() {

this.sandbox.stub(AdministratorAPI, 'create').returns('FromAdministratorEndpointStub');
this.sandbox.stub(ContactAPI, 'create').returns('FromContactEndpointStub');
this.sandbox.stub(ContactListAPI, 'create').returns('FromContactListEndpointStub');
this.sandbox.stub(EmailAPI, 'create').returns('FromEmailEndpointStub');
this.sandbox.stub(SegmentAPI, 'create').returns('FromSegmentEndpointStub');
this.sandbox.stub(LanguageAPI, 'create').returns('FromLanguageEndpointStub');
this.sandbox.stub(ExternalEventAPI, 'create').returns('FromExternalEventEndpointStub');
this.sandbox.stub(FieldAPI, 'create').returns('FromFieldEndpointStub');
this.sandbox.stub(LanguageAPI, 'create').returns('FromLanguageEndpointStub');
this.sandbox.stub(PurchaseAPI, 'create').returns('FromPurchaseEndpointStub');
this.sandbox.stub(SegmentAPI, 'create').returns('FromSegmentEndpointStub');
this.sandbox.stub(SettingsAPI, 'create').returns('FromSettingsEndpointStub');

var suiteRequestStub = this.sandbox.stub(SuiteRequest, 'create');
suiteRequestStub.withArgs(apiKey, apiSecret, 'SuiteRequestOptionsStub').returns('SuiteRequestStub');
suiteRequestStub.withArgs(apiKey, apiSecret, 'SuiteServiceRequestOptionsStub').returns('SuiteServiceRequestStub');
Expand All @@ -180,39 +189,77 @@ describe('SuiteApi', function() {
});


it('should have an SDK object with Administrator endpoint', function() {
expect(sdk.administrator).to.eql('FromAdministratorEndpointStub');
expect(AdministratorAPI.create).to.have.been.calledWith(fakeRequest, options);
});


it('should have an SDK object with Contact endpoint', function() {
expect(sdk.contact).to.eql('FromContactEndpointStub');
expect(ContactAPI.create).to.have.been.calledWith(fakeRequest);
});


it('should have an SDK object with Segment endpoint', function() {
expect(sdk.segment).to.eql('FromSegmentEndpointStub');
expect(SegmentAPI.create).to.have.been.calledWith(fakeRequest);
});


it('should have an SDK object with Language endpoint', function() {
expect(sdk.language).to.eql('FromLanguageEndpointStub');
expect(LanguageAPI.create).to.have.been.calledWith(fakeRequest);
});


it('should have an SDK object with ExternalEvent endpoint', function() {
expect(sdk.externalEvent).to.eql('FromExternalEventEndpointStub');
expect(ExternalEventAPI.create).to.have.been.calledWith(fakeRequest);
});

var testCases = [
{
endpoint: 'Administrator',
sdkKey: 'administrator',
api: AdministratorAPI,
stub: 'FromAdministratorEndpointStub'
},
{
endpoint: 'Contact',
sdkKey: 'contact',
api: ContactAPI,
stub: 'FromContactEndpointStub'
},
{
endpoint: 'ContactList',
sdkKey: 'contactList',
api: ContactListAPI,
stub: 'FromContactListEndpointStub'
},
{
endpoint: 'Email',
sdkKey: 'email',
api: EmailAPI,
stub: 'FromEmailEndpointStub'
},
{
endpoint: 'ExternalEvent',
sdkKey: 'externalEvent',
api: ExternalEventAPI,
stub: 'FromExternalEventEndpointStub'
},
{
endpoint: 'Field',
sdkKey: 'field',
api: FieldAPI,
stub: 'FromFieldEndpointStub'
},
{
endpoint: 'Language',
sdkKey: 'language',
api: LanguageAPI,
stub: 'FromLanguageEndpointStub'
},
{
endpoint: 'Purchase',
sdkKey: 'purchase',
api: PurchaseAPI,
stub: 'FromPurchaseEndpointStub'
},
{
endpoint: 'Segment',
sdkKey: 'segment',
api: SegmentAPI,
stub: 'FromSegmentEndpointStub'
},
{
endpoint: 'Settings',
sdkKey: 'settings',
api: SettingsAPI,
stub: 'FromSettingsEndpointStub'
}
];

testCases.forEach(function(testCase) {
it('should have an SDK object with ' + testCase.endpoint + ' endpoint', function() {
expect(sdk[testCase.sdkKey]).to.eql(testCase.stub);
});

it('should have an SDK object with Settings endpoint', function() {
expect(sdk.settings).to.eql('FromSettingsEndpointStub');
expect(SettingsAPI.create).to.have.been.calledWith(fakeRequest);
it('should have been called with fake request when creating api.' + testCase.sdkKey, function() {
expect(testCase.api.create).to.have.been.calledWith(fakeRequest, options);
});
});

});
Expand Down

0 comments on commit 106b72d

Please sign in to comment.