Skip to content

Commit 1aed1a7

Browse files
Merge pull request #3 from juanrossi/master
Added Promotions resource with Get/List and added tests.
2 parents e611ef9 + 198eec9 commit 1aed1a7

File tree

5 files changed

+109
-2
lines changed

5 files changed

+109
-2
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ You can also work with all the other resources authenticated with a secret API K
3939
- [Cards](https://developers.getmango.com/en/api/cards/?platform=node)
4040
- [Queue](https://developers.getmango.com/en/api/queue/?platform=node)
4141
- [Installments](https://developers.getmango.com/en/api/installments/?platform=node)
42+
- [Promotions](https://developers.getmango.com/en/api/promotions/?platform=node)
4243

4344
## Tests
4445

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Charges = require('./resources/charges');
1616
var Refunds = require('./resources/refunds');
1717
var Queue = require('./resources/queue');
1818
var Installments = require('./resources/installments');
19+
var Promotions = require('./resources/promotions');
1920

2021
/**
2122
* Expose constructor
@@ -49,6 +50,7 @@ function Mango(options) {
4950
this.Refunds = new Refunds(this);
5051
this.Queue = new Queue(this);
5152
this.Installments = new Installments(this);
53+
this.Promotions = new Promotions(this);
5254

5355
debug('Client intialized');
5456
}

lib/resources/promotions.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
/**
3+
* Module dependencies
4+
*/
5+
6+
var util = require('util');
7+
var Resource = require('./');
8+
9+
/**
10+
* Expose constructor
11+
*/
12+
13+
module.exports = Promotions;
14+
15+
/**
16+
* Promotions constructor
17+
*/
18+
19+
function Promotions(mango) {
20+
Resource.call(this, mango);
21+
}
22+
23+
util.inherits(Promotions, Resource);
24+
25+
/**
26+
* Get promotion
27+
*
28+
* @param {String} uid
29+
* @param {Function} callback
30+
* @api public
31+
*/
32+
33+
Promotions.prototype.get = function(uid, fn) {
34+
return this.request('get', '/promotions/' + uid + '/', fn);
35+
};
36+
37+
/**
38+
* List promotions
39+
*
40+
* @param {Object} options
41+
* @param {Function} callback
42+
* @api public
43+
*/
44+
45+
Promotions.prototype.list = function(options, fn) {
46+
return this.request('get', '/promotions/', options, fn);
47+
};
48+

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mango",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"description": "Mango API client for node.js",
55
"main": "lib/index.js",
66
"scripts": {
@@ -15,7 +15,12 @@
1515
"Mango",
1616
"API"
1717
],
18-
"author": "Dan Zajdband <[email protected]>",
18+
"author": "Mango <[email protected]> (https://getmango.com)",
19+
"contributors": [
20+
"Dan Zajdband <[email protected]>",
21+
"Guillermo Paz <[email protected]>",
22+
"Juan Rossi <[email protected]>"
23+
],
1924
"license": "MIT",
2025
"dependencies": {
2126
"debug": "2.1.0",

test/promotions.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
/**
3+
* Module dependencies
4+
*/
5+
6+
var request = require('superagent');
7+
8+
/**
9+
* Aux function to create promotions generation requirements
10+
*/
11+
12+
describe('Promotions', function(){
13+
14+
describe('base', function(){
15+
it('Inherits from Resource', function(){
16+
assert(mango.Promotions instanceof require('../lib/resources'));
17+
});
18+
19+
it('Has all required methods', function(){
20+
['get', 'list'].forEach(function(method){
21+
assert('function' == typeof mango.Promotions[method]);
22+
});
23+
});
24+
});
25+
26+
describe('#get', function(){
27+
it('Get a promotion', function(done){
28+
mango.Promotions.list({'status': 'active'}, function(err, data){
29+
mango.Promotions.get(data[0].uid, function(err, promotion){
30+
assert('object' == typeof promotion);
31+
assert(promotion.status === 'active');
32+
assert(promotion.live === false);
33+
done(err);
34+
});
35+
});
36+
});
37+
});
38+
39+
describe('#list', function(){
40+
it('List promotions', function(done){
41+
mango.Promotions.list({'status': 'active'}, function(err, data){
42+
assert(Array.isArray(data));
43+
assert(data.length);
44+
assert(data[0].status === 'active');
45+
assert(!data[0].live);
46+
done(err);
47+
});
48+
});
49+
});
50+
51+
});

0 commit comments

Comments
 (0)