-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promotions: Added Promotions resource with Get/List and added tests.
- Loading branch information
Juan Rossi
committed
Mar 7, 2015
1 parent
e611ef9
commit 198eec9
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
|
@@ -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", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |