Skip to content

Commit

Permalink
Merge pull request #3 from juanrossi/master
Browse files Browse the repository at this point in the history
Added Promotions resource with Get/List and added tests.
  • Loading branch information
impronunciable committed Mar 9, 2015
2 parents e611ef9 + 198eec9 commit 1aed1a7
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You can also work with all the other resources authenticated with a secret API K
- [Cards](https://developers.getmango.com/en/api/cards/?platform=node)
- [Queue](https://developers.getmango.com/en/api/queue/?platform=node)
- [Installments](https://developers.getmango.com/en/api/installments/?platform=node)
- [Promotions](https://developers.getmango.com/en/api/promotions/?platform=node)

## Tests

Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var Charges = require('./resources/charges');
var Refunds = require('./resources/refunds');
var Queue = require('./resources/queue');
var Installments = require('./resources/installments');
var Promotions = require('./resources/promotions');

/**
* Expose constructor
Expand Down Expand Up @@ -49,6 +50,7 @@ function Mango(options) {
this.Refunds = new Refunds(this);
this.Queue = new Queue(this);
this.Installments = new Installments(this);
this.Promotions = new Promotions(this);

debug('Client intialized');
}
48 changes: 48 additions & 0 deletions lib/resources/promotions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

/**
* Module dependencies
*/

var util = require('util');
var Resource = require('./');

/**
* Expose constructor
*/

module.exports = Promotions;

/**
* Promotions constructor
*/

function Promotions(mango) {
Resource.call(this, mango);
}

util.inherits(Promotions, Resource);

/**
* Get promotion
*
* @param {String} uid
* @param {Function} callback
* @api public
*/

Promotions.prototype.get = function(uid, fn) {
return this.request('get', '/promotions/' + uid + '/', fn);
};

/**
* List promotions
*
* @param {Object} options
* @param {Function} callback
* @api public
*/

Promotions.prototype.list = function(options, fn) {
return this.request('get', '/promotions/', options, fn);
};

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mango",
"version": "0.0.0",
"version": "0.0.1",
"description": "Mango API client for node.js",
"main": "lib/index.js",
"scripts": {
Expand All @@ -15,7 +15,12 @@
"Mango",
"API"
],
"author": "Dan Zajdband <[email protected]>",
"author": "Mango <[email protected]> (https://getmango.com)",
"contributors": [
"Dan Zajdband <[email protected]>",
"Guillermo Paz <[email protected]>",
"Juan Rossi <[email protected]>"
],
"license": "MIT",
"dependencies": {
"debug": "2.1.0",
Expand Down
51 changes: 51 additions & 0 deletions test/promotions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

/**
* Module dependencies
*/

var request = require('superagent');

/**
* Aux function to create promotions generation requirements
*/

describe('Promotions', function(){

describe('base', function(){
it('Inherits from Resource', function(){
assert(mango.Promotions instanceof require('../lib/resources'));
});

it('Has all required methods', function(){
['get', 'list'].forEach(function(method){
assert('function' == typeof mango.Promotions[method]);
});
});
});

describe('#get', function(){
it('Get a promotion', function(done){
mango.Promotions.list({'status': 'active'}, function(err, data){
mango.Promotions.get(data[0].uid, function(err, promotion){
assert('object' == typeof promotion);
assert(promotion.status === 'active');
assert(promotion.live === false);
done(err);
});
});
});
});

describe('#list', function(){
it('List promotions', function(done){
mango.Promotions.list({'status': 'active'}, function(err, data){
assert(Array.isArray(data));
assert(data.length);
assert(data[0].status === 'active');
assert(!data[0].live);
done(err);
});
});
});

});

0 comments on commit 1aed1a7

Please sign in to comment.