Skip to content

Commit

Permalink
More test cases for profile parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Jan 28, 2016
1 parent 29bec13 commit 4f98a75
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 51 deletions.
3 changes: 3 additions & 0 deletions lib/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ exports.parse = function(json) {
if (json.id_str) { profile.id = json.id_str; }
profile.username = json.screen_name;
profile.displayName = json.name;
if (json.email) {
profile.emails = [{ value: json.email }];
}
profile.photos = [{ value: json.profile_image_url_https }];

return profile;
Expand Down
105 changes: 105 additions & 0 deletions test/fixtures/account/theSeanCook-include_email.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"contributors_enabled": true,
"created_at": "Sat May 09 17:58:22 +0000 2009",
"default_profile": false,
"default_profile_image": false,
"description": "I taught your phone that thing you like. The Mobile Partner Engineer @Twitter. ",
"email": "theSeanCook@example.test",
"favourites_count": 588,
"follow_request_sent": null,
"followers_count": 10625,
"following": null,
"friends_count": 1181,
"geo_enabled": true,
"id": 38895958,
"id_str": "38895958",
"is_translator": false,
"lang": "en",
"listed_count": 190,
"location": "San Francisco",
"name": "Sean Cook",
"notifications": null,
"profile_background_color": "1A1B1F",
"profile_background_image_url": "http://a0.twimg.com/profile_background_images/495742332/purty_wood.png",
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/495742332/purty_wood.png",
"profile_background_tile": true,
"profile_image_url": "http://a0.twimg.com/profile_images/1751506047/dead_sexy_normal.JPG",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1751506047/dead_sexy_normal.JPG",
"profile_link_color": "2FC2EF",
"profile_sidebar_border_color": "181A1E",
"profile_sidebar_fill_color": "252429",
"profile_text_color": "666666",
"profile_use_background_image": true,
"protected": false,
"screen_name": "theSeanCook",
"show_all_inline_media": true,
"status": {
"contributors": null,
"coordinates": {
"coordinates": [
-122.45037293,
37.76484123
],
"type": "Point"
},
"created_at": "Tue Aug 28 05:44:24 +0000 2012",
"favorited": false,
"geo": {
"coordinates": [
37.76484123,
-122.45037293
],
"type": "Point"
},
"id": 240323931419062272,
"id_str": "240323931419062272",
"in_reply_to_screen_name": "messl",
"in_reply_to_status_id": 240316959173009410,
"in_reply_to_status_id_str": "240316959173009410",
"in_reply_to_user_id": 18707866,
"in_reply_to_user_id_str": "18707866",
"place": {
"attributes": {},
"bounding_box": {
"coordinates": [
[
[
-122.45778216,
37.75932999
],
[
-122.44248216,
37.75932999
],
[
-122.44248216,
37.76752899
],
[
-122.45778216,
37.76752899
]
]
],
"type": "Polygon"
},
"country": "United States",
"country_code": "US",
"full_name": "Ashbury Heights, San Francisco",
"id": "866269c983527d5a",
"name": "Ashbury Heights",
"place_type": "neighborhood",
"url": "http://api.twitter.com/1/geo/id/866269c983527d5a.json"
},
"retweet_count": 0,
"retweeted": false,
"source": "<a href=\"//twitter.com%5C%22\" rel=\"nofollow\">Twitter for iPhone</a>",
"text": "@messl congrats! So happy for all 3 of you.",
"truncated": false
},
"statuses_count": 2609,
"time_zone": "Pacific Time (US & Canada)",
"url": null,
"utc_offset": -28800,
"verified": false
}
104 changes: 104 additions & 0 deletions test/fixtures/account/theSeanCook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"contributors_enabled": true,
"created_at": "Sat May 09 17:58:22 +0000 2009",
"default_profile": false,
"default_profile_image": false,
"description": "I taught your phone that thing you like. The Mobile Partner Engineer @Twitter. ",
"favourites_count": 588,
"follow_request_sent": null,
"followers_count": 10625,
"following": null,
"friends_count": 1181,
"geo_enabled": true,
"id": 38895958,
"id_str": "38895958",
"is_translator": false,
"lang": "en",
"listed_count": 190,
"location": "San Francisco",
"name": "Sean Cook",
"notifications": null,
"profile_background_color": "1A1B1F",
"profile_background_image_url": "http://a0.twimg.com/profile_background_images/495742332/purty_wood.png",
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/495742332/purty_wood.png",
"profile_background_tile": true,
"profile_image_url": "http://a0.twimg.com/profile_images/1751506047/dead_sexy_normal.JPG",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1751506047/dead_sexy_normal.JPG",
"profile_link_color": "2FC2EF",
"profile_sidebar_border_color": "181A1E",
"profile_sidebar_fill_color": "252429",
"profile_text_color": "666666",
"profile_use_background_image": true,
"protected": false,
"screen_name": "theSeanCook",
"show_all_inline_media": true,
"status": {
"contributors": null,
"coordinates": {
"coordinates": [
-122.45037293,
37.76484123
],
"type": "Point"
},
"created_at": "Tue Aug 28 05:44:24 +0000 2012",
"favorited": false,
"geo": {
"coordinates": [
37.76484123,
-122.45037293
],
"type": "Point"
},
"id": 240323931419062272,
"id_str": "240323931419062272",
"in_reply_to_screen_name": "messl",
"in_reply_to_status_id": 240316959173009410,
"in_reply_to_status_id_str": "240316959173009410",
"in_reply_to_user_id": 18707866,
"in_reply_to_user_id_str": "18707866",
"place": {
"attributes": {},
"bounding_box": {
"coordinates": [
[
[
-122.45778216,
37.75932999
],
[
-122.44248216,
37.75932999
],
[
-122.44248216,
37.76752899
],
[
-122.45778216,
37.76752899
]
]
],
"type": "Polygon"
},
"country": "United States",
"country_code": "US",
"full_name": "Ashbury Heights, San Francisco",
"id": "866269c983527d5a",
"name": "Ashbury Heights",
"place_type": "neighborhood",
"url": "http://api.twitter.com/1/geo/id/866269c983527d5a.json"
},
"retweet_count": 0,
"retweeted": false,
"source": "<a href=\"//twitter.com%5C%22\" rel=\"nofollow\">Twitter for iPhone</a>",
"text": "@messl congrats! So happy for all 3 of you.",
"truncated": false
},
"statuses_count": 2609,
"time_zone": "Pacific Time (US & Canada)",
"url": null,
"utc_offset": -28800,
"verified": false
}
10 changes: 5 additions & 5 deletions test/package.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var strategy = require('..');

describe('passport-twitter', function() {

it('should export Strategy constructor directly from package', function() {
expect(strategy).to.be.a('function');
expect(strategy).to.equal(strategy.Strategy);
});

it('should export Strategy constructor', function() {
expect(strategy.Strategy).to.be.a('function');
});

it('should export Strategy constructor as module', function() {
expect(strategy).to.be.a('function');
expect(strategy).to.equal(strategy.Strategy);
});

});
43 changes: 42 additions & 1 deletion test/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,49 @@ var Profile = require('../lib/profile')


describe('Profile.parse', function() {

describe('profile obtained from GET account/verify_credentials documentation on 2016/01/28', function() {
var profile;

before(function(done) {
fs.readFile('test/fixtures/account/theSeanCook.json', 'utf8', function(err, data) {
if (err) { return done(err); }
profile = Profile.parse(data);
done();
});
});

it('should parse profile', function() {
expect(profile.id).to.equal('38895958');
expect(profile.username).to.equal('theSeanCook');
expect(profile.displayName).to.equal('Sean Cook');
expect(profile.emails).to.be.undefined;
expect(profile.photos[0].value).to.equal('https://si0.twimg.com/profile_images/1751506047/dead_sexy_normal.JPG');
});
});

describe('profile obtained from GET account/verify_credentials documentation on 2016/01/28, with email attribute', function() {
var profile;

describe('profile obtained from documentation at some unknown date', function() {
before(function(done) {
fs.readFile('test/fixtures/account/theSeanCook-include_email.json', 'utf8', function(err, data) {
if (err) { return done(err); }
profile = Profile.parse(data);
done();
});
});

it('should parse profile', function() {
expect(profile.id).to.equal('38895958');
expect(profile.username).to.equal('theSeanCook');
expect(profile.displayName).to.equal('Sean Cook');
expect(profile.emails).to.have.length(1);
expect(profile.emails[0].value).to.equal('theSeanCook@example.test');
expect(profile.photos[0].value).to.equal('https://si0.twimg.com/profile_images/1751506047/dead_sexy_normal.JPG');
});
});

describe('profile obtained from unknown source on unknown date', function() {
var profile;

before(function(done) {
Expand Down
Loading

0 comments on commit 4f98a75

Please sign in to comment.