diff --git a/README.md b/README.md index 232a252..c195011 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ API: | Customers | +Consents +| Orders | Products @@ -477,6 +479,20 @@ client.customers.updateConsents(customer, consents) --- +### Consents API +Methods are provided within `client.consents.*` namespace. + +- [List Customers](#list-customers) + +You can [update Customer's consents](#update-customers-consents) in Customer namespace. + +#### [List Consents] +```javascript +client.consents.list() +``` + +--- + ### Orders API Methods are provided within `client.orders.*` namespace. @@ -1117,6 +1133,7 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github [Delete Customer]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-customer [List Customers]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-customers [Update Customer's Consents]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-customers-consents +[List Consents]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-consents [Create Order]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-order [Get Order]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-order diff --git a/src/Consents.js b/src/Consents.js new file mode 100644 index 0000000..24473c9 --- /dev/null +++ b/src/Consents.js @@ -0,0 +1,11 @@ +'use strict' + +module.exports = class Consents { + constructor (client) { + this.client = client + } + + list (callback) { + return this.client.get('/consents', null, callback) + } +} diff --git a/src/index.js b/src/index.js index 7420c3c..196a04c 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,7 @@ const Redemptions = require('./Redemptions') const PromotionTiers = require('./PromotionTiers') const Promotions = require('./Promotions') const Customers = require('./Customers') +const Consents = require('./Consents') const Orders = require('./Orders') const Products = require('./Products') const Rewards = require('./Rewards') @@ -36,6 +37,7 @@ module.exports = function (options) { const validations = new Validations(client, promotions) const redemptions = new Redemptions(client, promotions) const customers = new Customers(client) + const consents = new Consents(client) const orders = new Orders(client) const products = new Products(client) const rewards = new Rewards(client) @@ -51,6 +53,7 @@ module.exports = function (options) { redemptions, promotions, customers, + consents, orders, products, rewards, diff --git a/test/consents-api.spec.js b/test/consents-api.spec.js new file mode 100644 index 0000000..645b8b7 --- /dev/null +++ b/test/consents-api.spec.js @@ -0,0 +1,43 @@ +/* eslint-env mocha */ +/* eslint-disable no-unused-expressions */ + +const nock = require('nock') +const { expect } = require('chai') +const VoucherifyClient = require('./client-loader') +const fixtures = require('./fixtures') +const reqWithoutBody = fixtures.reqWithoutBody + +nock.disableNetConnect() + +describe('Consents API', function () { + var client = new VoucherifyClient({ + applicationId: 'node-sdk-test-id', + clientSecretKey: 'node-sdk-test-secret' + }) + + describe('list', function () { + it('should list all consents', function (done) { + var server = nock('https://api.voucherify.io', reqWithoutBody) + .get('/v1/consents') + .reply(200, []) + + client.consents.list() + .then(function () { + server.done() + done() + }) + }) + + it('should list all consents (callback)', function (done) { + var server = nock('https://api.voucherify.io', reqWithoutBody) + .get('/v1/consents') + .reply(200, []) + + client.consents.list(function (err) { + expect(err).to.be.null + server.done() + done() + }) + }) + }) +})