Back End Development and API Cert - Timestamp Microservice

So, I think I’m done but I’m not passing my tests for some reason? Despite doing the tests manually and getting the correct responses, I simply don’t pass them… Does anyone have any idea what I could do to pass them?

Github: FCC_backend_apis/boilerplate-project-timestamp at main · moppdev/FCC_backend_apis · GitHub
Gitpod Deploy: https://freecodecam-boilerplate-gdeust6rwvy.ws-eu117.gitpod.io/

Errors I’m getting on the submission page:

are you submitting the live app url?

You shouldn’t be getting that error with your code if you are submitting it correctly.

The test that is throwing.

(getUserInput) =>
  $.get(getUserInput('url') + '/api/this-is-not-a-date').then(
    (data) => {
      assert.equal(data.error.toLowerCase(), 'invalid date');
    },
    (xhr) => {
      assert(xhr.responseJSON.error.toLowerCase() === 'invalid date');
    }
  );

But you are failing test #7. Log out the params and submit. It isn’t what you think it is when the date params is missing.

Yes, I’m submitting that.

What is “that”?

You should submit the URL with the port number from the preview window (with it running obviously).

https://3000-freecodecam-boilerplate-gdeust6rwvy.ws-eu117.gitpod.io/


Is the code on GitHub and Gitpod in sync. I can only test the GitHub code, and it passes that test for me (not a date test), but correctly fails test #7.

Not submitting correctly? Odd.

Here’s an example of me entering “2018-05-08” into the URL.

Here’s an example of me entering 1451001600000 into the URL like the test:

Yes, that URL is what I’ve been submitting…

I have a question tho, the way I understand 7 and 8 is it should return something like this?

EDIT: Just tested again, everything passes now for some reason (doing this from my desktop instead of laptop), but it does fail 7 as you said

Test #6 is testing a payload that isn’t a valid date /api/this-is-not-a-date

Test #7/8 is testing an empty params (which isn’t null or an empty string but something else, log it out as said).

Ok, 6 is passing, it’s just 7 now… But aren’t 7 and 8 interconnected? Since it seems they have to be returned to the same JSON object…

Should I test for undefined too? Since I have but it doesn’t change anything…

Yes, 7 and 8 are related. But for the two different properties of the JSON object unix and utc.

Just log out the params and submit to see what it is. But the short answer is yes.

Push or post your latest code so we can see it.

Just solved it. Didn’t add the hours, minutes and seconds to Date.UTC. That’s why it didn’t fire properly.

unix: new Number(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 
      date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()))

Also uploaded the new code to the github

1 Like

Good that you fixed it.

  1. The logic you have for the empty params seems convoluted. All three values are falsy values so you really do not need to check them separately. Also, setting dateParam to an empty string probably isn’t the right choice, seeing as that isn’t what an empty params will be. It could cause issues in a larger code base if you use unexpected values. If you really did want to use a fixed false value for it, I would use null and not an empty string.

  2. You can use getTime to get the unix value.

On point 2, I’m stumped lol, since all my searches lead me to Date.UTC…

Not sure what you mean by stumped?

You can call getTime() on the date object for the unix property.

let date = new Date();
res.json({
  unix: date.getTime(),
  utc: date.toUTCString(),
});