From 0cb0da8c7a001a174f5200c8cde5259060e42d8f Mon Sep 17 00:00:00 2001 From: em-ant Date: Sun, 1 Jul 2018 10:18:09 +0200 Subject: [PATCH] feat(challenge): add tests for the timestamp microservice challenge --- .../apis-and-microservices-projects.json | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/challenges/05-apis-and-microservices/apis-and-microservices-projects.json b/challenges/05-apis-and-microservices/apis-and-microservices-projects.json index ae6e64dbc..3f810dba7 100644 --- a/challenges/05-apis-and-microservices/apis-and-microservices-projects.json +++ b/challenges/05-apis-and-microservices/apis-and-microservices-projects.json @@ -14,16 +14,28 @@ ], "tests": [ { - "text": "I can pass a string as a parameter, and it will check to see whether that string contains either a unix timestamp or a natural language date (example: January 1, 2016).", - "testString": "" + "text": "It should handle a valid date, and return the correct unix timestamp", + "testString": "getUserInput => $.get(getUserInput('url') + '/api/timestamp/2016-12-25').then(data => { assert.equal(data.unix, 1482624000000, 'Should be a valid unix timestamp'); }, xhr => { throw new Error(xhr.responseText); })" }, { - "text": "If it does, it returns both the Unix timestamp and the natural language form of that date.", - "testString": "" + "text": "It should handle a valid date, and return the correct UTC string", + "testString": "getUserInput => $.get(getUserInput('url')+ '/api/timestamp/2016-12-25').then(data => { assert.equal(data.utc, 'Sun, 25 Dec 2016 00:00:00 GMT', 'Should be a valid UTC date string'); }, xhr => { throw new Error(xhr.responseText); })" }, { - "text": "If it does not contain a date or Unix timestamp, it returns null for those properties.", - "testString": "" + "text": "It should handle a valid unix date, and return the correct unix timestamp", + "testString": "getUserInput => $.get(getUserInput('url') + '/api/timestamp/1482624000000').then(data => { assert.equal(data.unix, 1482624000000) ; }, xhr => { throw new Error(xhr.responseText); })" + }, + { + "text": "It should return the expected error message for an invalid date", + "testString": "getUserInput => $.get(getUserInput('url') + '/api/timestamp/this-is-not-a-date').then(data => { assert.equal(data.error.toLowerCase(), 'invalid date');}, xhr => { throw new Error(xhr.responseText); })" + }, + { + "text": "It should handle an empty date parameter, and return the current time in unix format", + "testString": "getUserInput => $.get(getUserInput('url') + '/api/timestamp').then(data => { var now = Date.now(); assert.approximately(data.unix, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })" + }, + { + "text": "It should handle an empty date parameter, and return the current time in UTC format", + "testString": "getUserInput => $.get(getUserInput('url') + '/api/timestamp').then(data => { var now = Date.now(); var serverTime = (new Date(data.utc)).getTime(); assert.approximately(serverTime, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [],