Skip to content

Commit

Permalink
added support for retrieving branding themes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 15, 2017
1 parent 16c5b96 commit a1e6368
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/core.js
Expand Up @@ -7,14 +7,15 @@ var HELPERS = {
items: { file: 'items' },
bankTransactions: { file: 'banktransactions' },
bankTransfers: { file: 'banktransfers' },
brandingThemes: { file: 'brandingthemes' },
journals: { file: 'journals' },
attachments: { file: 'attachments' },
accounts: { file: 'accounts' },
invoices: { file: 'invoices' },
trackingCategories: { file: 'trackingcategories' },
users: { file: 'users' },
payments: { file: 'payments' },
taxrates: { file: 'taxrates' }
taxRates: { file: 'taxrates' }
};

function Core(application, options) {
Expand Down
21 changes: 21 additions & 0 deletions lib/entities/brandingtheme.js
@@ -0,0 +1,21 @@
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger')

var BrandingThemeSchema = new Entity.SchemaObject({
BrandingThemeID: { type: String },
Name: { type: String },
SortOrder: { type: String },
CreatedDateUTC: { type: String }
});

var BrandingTheme = Entity.extend(BrandingThemeSchema, {
constructor: function(application, data, options) {
logger.debug('BrandingTheme::constructor');
this.Entity.apply(this, arguments);
},
initialize: function(data, options) {}
});


module.exports = BrandingTheme;
2 changes: 1 addition & 1 deletion lib/entities/taxrate.js
Expand Up @@ -56,7 +56,7 @@ var TaxRate = Entity.extend(TaxRateSchema, {
} else {
method = 'put'
}
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'TaxRates.TaxRate', entityConstructor: function(data) { return self.application.core.taxrates.newTaxRate(data) } });
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'TaxRates.TaxRate', entityConstructor: function(data) { return self.application.core.taxRates.newTaxRate(data) } });
},
delete: function(options) {
this.Status = "DELETED";
Expand Down
25 changes: 25 additions & 0 deletions lib/entity_helpers/brandingthemes.js
@@ -0,0 +1,25 @@
var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
BrandingTheme = require('../entities/brandingtheme'),
util = require('util')

var BrandingThemes = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, Object.assign({ entityName: 'BrandingTheme', entityPlural: 'BrandingThemes' }, options));
},
getBrandingThemes: function(options, callback) {
var self = this;
var clonedOptions = _.clone(options || {});
clonedOptions.entityConstructor = function(data) { return new BrandingTheme(data) };
return this.getEntities(clonedOptions)
},
getBrandingTheme: function(id) {
return this.getBrandingThemes({ id: id })
.then(function(brandingThemes) {
return _.first(brandingThemes);
})
},
})

module.exports = BrandingThemes;
19 changes: 18 additions & 1 deletion sample_app/index.js
Expand Up @@ -184,9 +184,26 @@ app.get('/organisations', function(req, res) {
})
});

app.get('/brandingthemes', function(req, res) {
authorizedOperation(req, res, '/brandingthemes', function(xeroClient) {
xeroClient.core.brandingThemes.getBrandingThemes()
.then(function(brandingthemes) {
res.render('brandingthemes', {
brandingthemes: brandingthemes,
active: {
brandingthemes: true
}
});
})
.catch(function(err) {
handleErr(err, req, res, 'brandingthemes');
})
})
});

app.get('/taxrates', function(req, res) {
authorizedOperation(req, res, '/taxrates', function(xeroClient) {
xeroClient.core.taxrates.getTaxRates()
xeroClient.core.taxRates.getTaxRates()
.then(function(taxrates) {
res.render('taxrates', {
taxrates: taxrates,
Expand Down
19 changes: 19 additions & 0 deletions sample_app/views/brandingthemes.handlebars
@@ -0,0 +1,19 @@
<h3>Branding Themes</h3>
<table class="table table-bordered table-striped table-collapsed">
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>SortOrder</td>
<td>CreatedDateUTC</td>
</tr>
</thead>
{{#each brandingthemes}}
<tr>
<td>{{ this.BrandingThemeID }}</td>
<td>{{ this.Name }}</td>
<td>{{ this.SortOrder }}</td>
<td>{{ this.CreatedDateUTC }}</td>
</tr>
{{/each}}
</table>
2 changes: 2 additions & 0 deletions sample_app/views/index.handlebars
Expand Up @@ -12,12 +12,14 @@
<li>Accounts</li>
<li>BankTransactions</li>
<li>BankTransfers</li>
<li>BrandingThemes</li>
<li>Contacts</li>
<li>Invoices</li>
<li>Items</li>
<li>Journals</li>
<li>Organisations</li>
<li>Payments</li>
<li>Reports</li>
<li>TaxRates</li>
<li>TrackingCategories (and TrackingOptions)</li>
<li>Users</li>
Expand Down
1 change: 1 addition & 0 deletions sample_app/views/partials/nav.handlebars
Expand Up @@ -6,6 +6,7 @@
<li class="{{#if active.accounts}}active{{/if}}"><a href="/accounts">List Accounts</a></li>
<li class="{{#if active.banktransactions}}active{{/if}}"><a href="/banktransactions">List Bank Transactions</a></li>
<li class="{{#if active.banktransfers}}active{{/if}}"><a href="/banktransfers">List Bank Transfers</a></li>
<li class="{{#if active.brandingthemes}}active{{/if}}"><a href="/brandingthemes">List Branding Themes</a></li>
<li class="{{#if active.contacts}}active{{/if}}"><a href="/contacts">List Contacts</a></li>
<li class="{{#if active.invoices}}active{{/if}}"><a href="/invoices">List Invoices</a></li>
<li class="{{#if active.items}}active{{/if}}"><a href="/items">List Items</a></li>
Expand Down
48 changes: 45 additions & 3 deletions test/accountingtests.js
Expand Up @@ -302,12 +302,54 @@ describe('regression tests', function() {
})
})

describe('taxrates', function() {
describe('branding themes', function() {

var brandingThemeID = "";

it('get', function(done) {
currentApp.core.brandingThemes.getBrandingThemes()
.then(function(brandingThemes) {
expect(brandingThemes).to.have.length.greaterThan(0);
brandingThemes.forEach(function(brandingTheme) {
expect(brandingTheme.BrandingThemeID).to.not.equal(undefined);
expect(brandingTheme.BrandingThemeID).to.not.equal("");
expect(brandingTheme.Name).to.not.equal(undefined);
expect(brandingTheme.Name).to.not.equal("");

brandingThemeID = brandingTheme.BrandingThemeID;
});
done();
})
.catch(function(err) {
console.log(err);
done(wrapError(err));
})
});

it('get by ID', function(done) {
currentApp.core.brandingThemes.getBrandingTheme(brandingThemeID)
.then(function(brandingTheme) {

expect(brandingTheme.BrandingThemeID).to.not.equal(undefined);
expect(brandingTheme.BrandingThemeID).to.not.equal("");
expect(brandingTheme.Name).to.not.equal(undefined);
expect(brandingTheme.Name).to.not.equal("");

done();
})
.catch(function(err) {
console.log(err);
done(wrapError(err));
})
})
})

describe('taxRates', function() {

var createdTaxRate;

it('gets tax rates', function(done) {
currentApp.core.taxrates.getTaxRates()
currentApp.core.taxRates.getTaxRates()
.then(function(taxRates) {
// This test requires that some tax rates are set up in the targeted company
expect(taxRates).to.have.length.greaterThan(0);
Expand Down Expand Up @@ -352,7 +394,7 @@ describe('regression tests', function() {
ReportTaxType: 'INPUT'
}

var taxRate = currentApp.core.taxrates.newTaxRate(taxrate);
var taxRate = currentApp.core.taxRates.newTaxRate(taxrate);

taxRate.save()
.then(function(response) {
Expand Down

0 comments on commit a1e6368

Please sign in to comment.