Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Check for existence of email field in profile.

  • Loading branch information...
commit af8bad0041f7b8e902af3d81cbe6f197d825eb55 1 parent 0cb0209
Jared Hanson authored
4 lib/profile.js
View
@@ -15,7 +15,9 @@ exports.parse = function(json) {
profile.displayName = json.name;
profile.username = json.login;
profile.profileUrl = json.html_url;
- profile.emails = [{ value: json.email }];
+ if (json.email) {
+ profile.emails = [{ value: json.email }];
+ }
return profile;
};
32 test/data/example-null-email.json
View
@@ -0,0 +1,32 @@
+{
+ "login": "octocat",
+ "id": 1,
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
+ "url": "https://api.github.com/users/octocat",
+ "html_url": "https://github.com/octocat",
+ "followers_url": "https://api.github.com/users/octocat/followers",
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
+ "repos_url": "https://api.github.com/users/octocat/repos",
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
+ "type": "User",
+ "site_admin": false,
+ "name": "monalisa octocat",
+ "company": "GitHub",
+ "blog": "https://github.com/blog",
+ "location": "San Francisco",
+ "email": null,
+ "hireable": false,
+ "bio": "There once was...",
+ "public_repos": 2,
+ "public_gists": 1,
+ "followers": 20,
+ "following": 0,
+ "created_at": "2008-01-14T04:33:35Z",
+ "updated_at": "2008-01-14T04:33:35Z"
+}
32 test/data/example.json
View
@@ -0,0 +1,32 @@
+{
+ "login": "octocat",
+ "id": 1,
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
+ "url": "https://api.github.com/users/octocat",
+ "html_url": "https://github.com/octocat",
+ "followers_url": "https://api.github.com/users/octocat/followers",
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
+ "repos_url": "https://api.github.com/users/octocat/repos",
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
+ "type": "User",
+ "site_admin": false,
+ "name": "monalisa octocat",
+ "company": "GitHub",
+ "blog": "https://github.com/blog",
+ "location": "San Francisco",
+ "email": "octocat@github.com",
+ "hireable": false,
+ "bio": "There once was...",
+ "public_repos": 2,
+ "public_gists": 1,
+ "followers": 20,
+ "following": 0,
+ "created_at": "2008-01-14T04:33:35Z",
+ "updated_at": "2008-01-14T04:33:35Z"
+}
51 test/profile.test.js
View
@@ -0,0 +1,51 @@
+/* global describe, it, expect, before */
+/* jshint expr: true */
+
+var fs = require('fs')
+ , parse = require('../lib/profile').parse;
+
+
+describe('profile.parse', function() {
+
+ describe('example profile', function() {
+ var profile;
+
+ before(function(done) {
+ fs.readFile('test/data/example.json', 'utf8', function(err, data) {
+ if (err) { return done(err); }
+ profile = parse(data);
+ done();
+ });
+ });
+
+ it('should parse profile', function() {
+ expect(profile.id).to.equal('1');
+ expect(profile.username).to.equal('octocat');
+ expect(profile.displayName).to.equal('monalisa octocat');
+ expect(profile.profileUrl).to.equal('https://github.com/octocat');
+ expect(profile.emails).to.have.length(1);
+ expect(profile.emails[0].value).to.equal('octocat@github.com');
+ });
+ });
+
+ describe('example profile with null email', function() {
+ var profile;
+
+ before(function(done) {
+ fs.readFile('test/data/example-null-email.json', 'utf8', function(err, data) {
+ if (err) { return done(err); }
+ profile = parse(data);
+ done();
+ });
+ });
+
+ it('should parse profile', function() {
+ expect(profile.id).to.equal('1');
+ expect(profile.username).to.equal('octocat');
+ expect(profile.displayName).to.equal('monalisa octocat');
+ expect(profile.profileUrl).to.equal('https://github.com/octocat');
+ expect(profile.emails).to.be.undefined;
+ });
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.