Skip to content

Commit

Permalink
Merge pull request #94 from PlayNetwork/feature/bms-370
Browse files Browse the repository at this point in the history
BMS-370: Add ability to get profile based on authentication headers
  • Loading branch information
akobyshchatt committed Jan 14, 2020
2 parents b86b6f1 + b87021d commit cc7ff6c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
8 changes: 5 additions & 3 deletions lib/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var
validation = require('./validation');

const
CLIENT_ID = 'x-client-id',
DEFAULT_HOST = 'provision-api.apps.playnetwork.com',
DEFAULT_SECURE = true,
EVENT_ERROR = 'error',
Expand Down Expand Up @@ -364,12 +365,13 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
}

let exec = co(function *() {
let headers = yield ensureAuthHeaders();

if (validation.isEmpty(profileAlias)) {
return yield Promise.reject(new Error('profileAlias is required'));
const clientId = headers[CLIENT_ID];
profileAlias = `clientId:${clientId}`;
}

let headers = yield ensureAuthHeaders();

return yield req.get({
headers : headers,
pathname : `/v2/profiles/${profileAlias}`,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playnetwork-sdk",
"version": "1.4.6",
"version": "1.4.7",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down
35 changes: 19 additions & 16 deletions test/lib/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,27 +550,30 @@ describe('provision', () => {
});

describe('#getProfile', () => {
it('should require a profileAlias (promise)', (done) => {
provision.getProfile()
.then(() => {
return done(new Error('should require profileAlias'));
})
.catch((err) => {
should.exist(err);
should.exist(err.message);
err.message.should.contain('profileAlias is required');
it('should properly retrieve profile even without profileAlias', function (done) {
// intercept outbound request
nock('https://provision-api.apps.playnetwork.com')
.get('/v2/profiles/clientId:test')
.reply(200, { total : 0 });

provision.getProfile()
.then(function () {
return done();
});
})
.catch(function (err) {
return done(err);
})
});

it('should require profileAlias (callback)', (done) => {
provision.getProfile(function (err, result) {
should.exist(err);
should.exist(err.message);
err.message.should.contain('profileAlias is required');
should.not.exist(result);
it('should properly retrieve profile even without profileAlias (callback)', function (done) {
// intercept outbound request
nock('https://provision-api.apps.playnetwork.com')
.get('/v2/profiles/clientId:test')
.reply(200, { total : 0 });

provision.getProfile(function (err, result) {
should.not.exist(err);
should.exist(result);
return done();
});
});
Expand Down

0 comments on commit cc7ff6c

Please sign in to comment.