Skip to content

Commit

Permalink
Merge pull request #35 from PlayNetwork/v1.1.0
Browse files Browse the repository at this point in the history
encapsulating host information into the client sub-document as requir…
  • Loading branch information
brozeph committed Nov 16, 2016
2 parents 3ca376f + 384bc05 commit eb97d65
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.1.0 - 2016/11/16

* Fixed defect in the `recordPlay` method of `playback` sub-module - this change modified the interface for expected data

# v1.0.34 - 2016/10/28

* Resolved `UnhandledPromiseRejectionWarning` messages
Expand Down
14 changes: 11 additions & 3 deletions lib/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ module.exports = function (playbackOptions, ensureAuthHeaders, self) {
return yield Promise.reject(new Error('content information is required'));
}

if (validation.isEmpty(playback.client)) {
return yield Promise.reject(new Error('client information is required'));
}

if (validation.isEmpty(playback.client.host)) {
return yield Promise.reject(new Error('host information is required'));
}

// ensure content identifier is set
if (validation.isEmpty(playback.content.assetId) &&
validation.isEmpty(playback.content.legacyTrackToken) &&
Expand All @@ -99,9 +107,9 @@ module.exports = function (playbackOptions, ensureAuthHeaders, self) {
}

// ensure device identifier is set
if (validation.isEmpty(playback.deviceId) &&
(validation.isEmpty(playback.legacy) ||
validation.isEmpty(playback.legacy.deviceToken))) {
if (validation.isEmpty(playback.client.host.deviceId) &&
(validation.isEmpty(playback.client.host.legacy) ||
validation.isEmpty(playback.client.host.legacy.deviceToken))) {
return yield Promise.reject(new Error('device identifier is required'));
}

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": "playnetwork-sdk",
"version": "1.0.34",
"version": "1.1.0",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down
63 changes: 58 additions & 5 deletions test/lib/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ describe('playback', () => {
content : {
assetId : 'test'
},
deviceId : 'aabbcc112233'
client : {
host : {
deviceId : 'aabbcc112233'
}
}
};

it('should require play', (done) => {
Expand All @@ -149,7 +153,13 @@ describe('playback', () => {
});

it('should require content information', (done) => {
playback.recordPlay({ deviceId : 'test' }, function (err, result) {
playback.recordPlay({
client : {
host : {
deviceId : 'test'
}
}
}, function (err, result) {
should.not.exist(result);
should.exist(err);
should.exist(err.message);
Expand All @@ -164,7 +174,11 @@ describe('playback', () => {
content : {
test : true
},
deviceId : 'test'
client : {
host : {
deviceId : 'test'
}
}
}, function (err, result) {
should.not.exist(result);
should.exist(err);
Expand All @@ -175,10 +189,49 @@ describe('playback', () => {
});
});

it('should require client information', (done) => {
playback.recordPlay({
content : {
assetId : 'test'
}
}, function (err, result) {
should.not.exist(result);
should.exist(err);
should.exist(err.message);
err.message.should.contain('client information is required');

return done();
});
});


it('should require host information', (done) => {
playback.recordPlay({
content : {
assetId : 'test'
},
client : {
test : 'test'
}
}, function (err, result) {
should.not.exist(result);
should.exist(err);
should.exist(err.message);
err.message.should.contain('host information is required');

return done();
});
});

it('should require deviceId or legacy.deviceToken', (done) => {
playback.recordPlay({
content : {
assetId : 'test'
},
client : {
host : {
test : 'test'
}
}
}, function (err, result) {
should.not.exist(result);
Expand Down Expand Up @@ -227,10 +280,10 @@ describe('playback', () => {
});

it('should properly record playback (with legacy.deviceToken)', (done) => {
mockPlay.legacy = {
mockPlay.client.host.legacy = {
deviceToken : 1234
};
delete mockPlay.deviceId;
delete mockPlay.client.host.deviceId;

// intercept outbound request
nock('https://playback-api.apps.playnetwork.com')
Expand Down

0 comments on commit eb97d65

Please sign in to comment.