Skip to content

Commit

Permalink
Allow to list all promotion tiers.
Browse files Browse the repository at this point in the history
Relates to #88
  • Loading branch information
frakti committed Sep 17, 2020
1 parent 3d69223 commit 96a5649
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Methods are provided within `client.promotions.*` namespace.
- [Create Promotion Campaign](#create-promotion-campaign)
- [Validate Promotion Campaign](#validate-promotion-campaign)
- [List Promotion's Tiers](#list-promotions-tiers)
- [List All Promotion Tiers](#doc-list-all-promotion-tiers)
- [Create Promotion's Tier](#create-promotions-tier)
- [Redeem Promotion's Tier](#redeem-promotions-tier)
- [Update Promotion's Tier](#update-promotions-tier)
Expand All @@ -386,6 +387,14 @@ client.promotions.validate(validationContext)
client.promotions.tiers.list(promotionCampaignId)
```
Check [promotion's tier object](http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#the-promotion-object)
#### [List All Promotion Tiers]
```javascript
client.promotions.tiers.listAll()
client.promotions.tiers.listAll({ is_available: true })
client.promotions.tiers.listAll({ page: 2, limit: 10 })
```
You can list all currently available promotions by specifying `is_available` flag.

#### [Create Promotion's Tier]
```javascript
client.promotions.tiers.create(promotionId, promotionsTier)
Expand Down Expand Up @@ -1122,6 +1131,7 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github
[Create Promotion Campaign]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-promotion-campaign
[Validate Promotion Campaign]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-promotions-1
[List Promotion's Tiers]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-promotions
[Doc List All Promotion Tiers]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-promotion-tiers
[Create Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-promotion-tier-to-campaign
[Redeem Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-promotion
[Update Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-promotion
Expand Down
4 changes: 4 additions & 0 deletions src/PromotionTiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = class PromotionTiers {
this.client = client
}

listAll (params = {}, callback) {
return this.client.get('/promotions/tiers', params, callback)
}

list (promotionId, callback) {
return this.client.get(`/promotions/${encode(promotionId)}/tiers`, null, callback)
}
Expand Down
25 changes: 25 additions & 0 deletions test/promotions-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ describe('Promotions API', function () {
})

describe('promotion tiers', function () {
describe('all tiers', function () {
it('should list all promotion tiers in specific page', function (done) {
var server = nock('https://api.voucherify.io', reqWithoutBody)
.get('/v1/promotions/tiers?limit=10&page=2')
.reply(200, {})

client.promotions.tiers.listAll({ limit: 10, page: 2 })
.then(function () {
server.done()
done()
})
})
it('should list all available promotion tiers', function (done) {
var server = nock('https://api.voucherify.io', reqWithoutBody)
.get('/v1/promotions/tiers?is_available=true')
.reply(200, {})

client.promotions.tiers.listAll({ is_available: true })
.then(function () {
server.done()
done()
})
})
})

it('should list promotion tiers', function (done) {
var server = nock('https://api.voucherify.io', reqWithoutBody)
.get('/v1/promotions/promo_test_id/tiers')
Expand Down

0 comments on commit 96a5649

Please sign in to comment.