Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
2.0.2: allow overriding paymentId during getPromotion (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
evq authored Nov 23, 2017
1 parent a09dcda commit 0b6d0b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ Client.prototype.publisherInfo = function (publisher, callback) {
})
}

Client.prototype.getPromotion = function (lang, callback) {
Client.prototype.getPromotion = function (lang, forPaymentId, callback) {
const self = this

let path, params, paymentId
Expand All @@ -691,8 +691,12 @@ Client.prototype.getPromotion = function (lang, callback) {

path = '/v1/grants'
if (lang) params.lang = lang
paymentId = self.state && self.state.properties && self.state.properties.wallet && self.state.properties.wallet.paymentId
if (paymentId) params.paymentId = paymentId
if (forPaymentId) {
params.paymentId = paymentId = forPaymentId
} else {
paymentId = self.state && self.state.properties && self.state.properties.wallet && self.state.properties.wallet.paymentId
if (paymentId) params.paymentId = paymentId
}
if ((lang) || (paymentId)) path += '?' + querystring.stringify(params)
self._retryTrip(self, { path: path, method: 'GET' }, function (err, response, body) {
self._log('getPromotion', { method: 'GET', path: path, errP: !!err })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bat-client",
"version": "2.0.1",
"version": "2.0.2",
"description": "An example of client code for the BAT.",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions test/integrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const test = require('tape')

const options = { debugP: true, version: 'v2', environment: 'staging' }

/*
test('recoverWallet', async (t) => {
t.plan(6)
const client = new Ledger(null, options)
Expand Down Expand Up @@ -65,23 +64,26 @@ test('balance', async (t) => {
})
})
})
*/

test('promotion', async (t) => {
t.plan(6)
t.plan(7)
const client = new Ledger(null, options)
const client2 = new Ledger(null, options)

client.sync(function () {
client.getPromotion(null, function (err, resp) {
client.getPromotion(null, null, function (err, resp) {
t.false(err)
t.true(resp.hasOwnProperty('promotionId'))
client.setPromotion(resp.promotionId, function (err, resp) {
t.false(err)
t.true(resp.hasOwnProperty('probi'))
grantProbi = resp.probi
const grantProbi = resp.probi
client.getWalletProperties(function (err, resp) {
t.false(err)
t.equal(resp.probi, grantProbi)
client2.getPromotion(null, client.getPaymentId(), function (err, resp) {
t.true(err)
})
})
})
})
Expand Down

0 comments on commit 0b6d0b4

Please sign in to comment.