Skip to content

Commit

Permalink
Merge pull request #6 from Nimblr/master
Browse files Browse the repository at this point in the history
Update strategy to use the Portable Contacts format
  • Loading branch information
clocked0ne authored Sep 1, 2016
2 parents 05bef76 + 1fb5934 commit b1326ed
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
16 changes: 11 additions & 5 deletions lib/profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Parse profile.
*
* The Outlook API response is transformed to the Portable Contacts format, defines for PassportJS.
*
* @param {Object|String} json
* @return {Object}
* @api private
Expand All @@ -11,11 +13,15 @@ exports.parse = function(json) {
}

var profile = {};
profile.Id = json.Id;
profile.EmailAddress = json.EmailAddress;
profile.DisplayName = json.DisplayName;
profile.Alias = json.Alias;
profile.MailboxGuid = json.MailboxGuid;
profile.id = json.Id;
if (json.EmailAddress) {
profile.emails = [ {
value: json.EmailAddress, type: "home"
}];
}
profile.displayName = json.DisplayName;
profile.alias = json.Alias;
profile.mailboxGuid = json.MailboxGuid;

return profile;
};
2 changes: 1 addition & 1 deletion lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Strategy.prototype.userProfile = function (accessToken, done) {
return done(new Error('Failed to parse user profile'));
}

var profile = json;
var profile = Profile.parse(json);
profile.provider = 'windowslive';
profile._raw = body;
profile._json = json;
Expand Down
11 changes: 6 additions & 5 deletions test/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ describe('profile.parse', function() {
});

it('should parse profile', function() {
expect(profile.Id).to.equal('0dbf6616-20bd-4cbd-860d-47c5b7953e76@c512ffd1-581d-4dc0-a672-faee32f6387c');
expect(profile.EmailAddress).to.equal('AllieB@oauthplay.onmicrosoft.com');
expect(profile.DisplayName).to.equal('Allie Bellew');
expect(profile.Alias).to.equal('AllieB');
expect(profile.MailboxGuid).to.equal('8d899a1e-bde4-4946-8817-005e6f11d36d');
expect(profile.id).to.equal('0dbf6616-20bd-4cbd-860d-47c5b7953e76@c512ffd1-581d-4dc0-a672-faee32f6387c');
expect(profile.emails[0].type).to.equal('home');
expect(profile.emails[0].value).to.equal('AllieB@oauthplay.onmicrosoft.com');
expect(profile.displayName).to.equal('Allie Bellew');
expect(profile.alias).to.equal('AllieB');
expect(profile.mailboxGuid).to.equal('8d899a1e-bde4-4946-8817-005e6f11d36d');
});
});

Expand Down
11 changes: 6 additions & 5 deletions test/strategy.profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ describe('Strategy#userProfile', function() {
it('should parse profile', function() {
expect(profile.provider).to.equal('windowslive');

expect(profile.Id).to.equal('0dbf6616-20bd-4cbd-860d-47c5b7953e76@c512ffd1-581d-4dc0-a672-faee32f6387c');
expect(profile.EmailAddress).to.equal('AllieB@oauthplay.onmicrosoft.com');
expect(profile.DisplayName).to.equal('Allie Bellew');
expect(profile.Alias).to.equal('AllieB');
expect(profile.MailboxGuid).to.equal('8d899a1e-bde4-4946-8817-005e6f11d36d');
expect(profile.id).to.equal('0dbf6616-20bd-4cbd-860d-47c5b7953e76@c512ffd1-581d-4dc0-a672-faee32f6387c');
expect(profile.emails[0].type).to.equal('home');
expect(profile.emails[0].value).to.equal('AllieB@oauthplay.onmicrosoft.com');
expect(profile.displayName).to.equal('Allie Bellew');
expect(profile.alias).to.equal('AllieB');
expect(profile.mailboxGuid).to.equal('8d899a1e-bde4-4946-8817-005e6f11d36d');
});

it('should set raw property', function() {
Expand Down

0 comments on commit b1326ed

Please sign in to comment.