-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): parse author env var for email (#452)
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,64 @@ describe('build-context.js', () => { | |
}); | ||
}); | ||
|
||
describe('#getEmailFromAuthor', () => { | ||
it('should work', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <[email protected]>')).toEqual( | ||
'[email protected]' | ||
); | ||
}); | ||
|
||
it('should not be overly strict about email format', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <a@b>')).toEqual('a@b'); | ||
}); | ||
|
||
it('returns null if there is not an @ sign', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <patrick>')).toBeNull(); | ||
}); | ||
|
||
it('returns null if email does not have a user to the left of the @', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <@gmail.com>')).toBeNull(); | ||
}); | ||
|
||
it('returns null if the user is just whitespace', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce < @gmail.com>')).toBeNull(); | ||
}); | ||
|
||
it('returns null if email does not have a host to the right of the @', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <patrick@>')).toBeNull(); | ||
}); | ||
|
||
it('returns null if the host is just whitespace', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <patrick@ >')).toBeNull(); | ||
}); | ||
|
||
it('should ignore angle brackets other than the last pair', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <fir@st> <se@cond>')).toEqual( | ||
'se@cond' | ||
); | ||
}); | ||
|
||
it('returns null if there is not a space between name and email', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce<[email protected]>')).toBeNull(); | ||
}); | ||
|
||
it('should not be sensitive to the author name itself', () => { | ||
expect(buildContext.getEmailFromAuthor(' <[email protected]>')).toEqual( | ||
'[email protected]' | ||
); | ||
}); | ||
|
||
it('returns null if there are not angle brackets surrounding the email', () => { | ||
expect(buildContext.getEmailFromAuthor('Patrick Hulce <[email protected]')).toBeNull(); | ||
}); | ||
|
||
it('returns null if the email is not at the end of the string', () => { | ||
expect( | ||
buildContext.getEmailFromAuthor('Patrick Hulce <[email protected]> ') | ||
).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('#getAvatarUrl()', () => { | ||
it('should work', () => { | ||
expect(buildContext.getAvatarUrl(hash)).toEqual( | ||
|
@@ -110,6 +168,20 @@ describe('build-context.js', () => { | |
process.env.LHCI_BUILD_CONTEXT__AVATAR_URL = 'http://localhost:1234/profile.jpg'; | ||
expect(buildContext.getAvatarUrl(hash)).toEqual('http://localhost:1234/profile.jpg'); | ||
}); | ||
|
||
it('should parse email from the complete author env override', () => { | ||
process.env.LHCI_BUILD_CONTEXT__AUTHOR = 'Paul Irish <[email protected]>'; | ||
expect(buildContext.getAvatarUrl(hash)).toEqual( | ||
'https://www.gravatar.com/avatar/629999fcb3f6a928abe5f65ed0ab09c2.jpg?d=identicon' | ||
); | ||
}); | ||
|
||
it('should use git if author env override does not have an email', () => { | ||
process.env.LHCI_BUILD_CONTEXT__AUTHOR = 'Paul Irish <localhost>'; | ||
expect(buildContext.getAvatarUrl(hash)).toEqual( | ||
'https://www.gravatar.com/avatar/78bafdcaf40e20b90bb76b9aa5834e11.jpg?d=identicon' | ||
); | ||
}); | ||
}); | ||
|
||
describe('#getGravatarUrlFromEmail()', () => { | ||
|