Last active
January 18, 2016 18:17
-
-
Save cromwellryan/7c9ef59868c3f0734819 to your computer and use it in GitHub Desktop.
Mow Your Own Lawn Post (https://docs.google.com/document/d/1okP_aDz9zDea5F5PRpjdb_Ka6VAeHjmygLGB06IrL9E/edit?userstoinvite=nathan@heysparkbox.com&ts=569d0414&actionButton=1#)
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
describe('myApp', () => { | |
describe('.formatActivityMessage', () => { | |
it('shows all data', () => { | |
var activity = { | |
"displayName": "Skippy John Jones", | |
"formattedDateTime": "Earlier today", | |
"activity": "Flew to space" | |
} | |
var result = myApp.formatActivityMessage(activity); | |
expect(result).toEqual("Earlier today, Skippy John Jones Flew to space"); | |
}); | |
}); | |
describe('.formatActivities', () => { | |
it('displayName happy path', () => { | |
var activities = [{ | |
"user": { firstName: "Skippy", "lastName": "John Jones", "userName": "skippyJJ" }, | |
"written_at": "2012-04-23T18:25:43.511Z", | |
"activity": "Space flight" | |
}]; | |
var result = myApp.formatActivities(activities); | |
expect(result[0].displayName).toEqual("Skippy John Jones (skippyJJ)"); | |
}); | |
}); | |
}); |
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
var myApp = { | |
formatActivities(data, asOf) { | |
var activities = data.activity; | |
asOf = asOf || moment(); // optional arguments make testing easier... sometimes | |
var formatted = activities.map( (activity) => { | |
return { | |
"displayName": `${activity.user.firstName} ${activity.user.lastName} (${activity.user.username})`, | |
"formattedDateTime": moment(activity.written_at).from(asOf), | |
"activity": activity.activity | |
}; | |
}); | |
return formatted.map(myApp.formatActivityMessage); | |
}, | |
formatActivityMessage(activity) { | |
return `${activity.formattedDateTime}, ${activity.displayName} ${activity.activity}`; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment