Hi leaders
,
I’m running into an issue with the final two tests for the Timestamp Microservice project.
- An empty date parameter should return the current time in a JSON object with a
unix
key
- An empty date parameter should return the current time in a JSON object with a
utc
key
When I run my project locally or on repl.it, it appears to return the correct JSON object when an empty date string parameter is passed.
If I open up the dev tools, open the network tab, and run the tests, I see this for the failing tests:
Drilling down, I see this:
I think (afaik) you will need a separate endpoint for that.
to separate the end point like?
You need an endpoint that listens to /api
. You have one that listens for /api/:date
, but I don’t think that will work for both cases - I may be wrong, it’s been a while since I’ve written an API.
1 Like
I am curious self. I still can’t figure this out.
when you pass an empty date it will be considered as /api
not /api/:date
. so you have to listen on that endpoint
2 Likes
Yes, like @adramelech is saying, we see this listener:
app.get("/api/:date", function (req, res) {
// ...
that will work if you are passing a date. But you also need one that handles no date, which would look like …
2 Likes
this what I did but it does not work.
When I go to the replit link that you provided, I don’t see that. If you are working in a different repl, please provide the link.
1 Like
@laminsuwareh9 Have you fixed it. @kevinSmith It seems working now
Yup, passes for me. I guess I was looking at cached code.
2 Likes
Thank you comrade its’s working now. but can you help me by explaining the codes because I don’t Understand them.
Thank you comrade its’s working now. but can you help me by explaining the codes because I don’t Understand how it works.
Quote the code you didnt get
1 Like
the whole solutions. check my first screenshot.
We don’t have a screenshot of your code. We can’t go line by line and explain every line of every file. If you have a question about a specific line or lines, then please provide. If you don’t understand a concept, please ask about it specifically.
1 Like
A request to /api/:date?
with a valid date should return a JSON object with a unix
key that is a Unix timestamp of the input date in milliseconds
A request to /api/:date?
with a valid date should return a JSON object with a utc
key that is a string of the input date in the format: Thu, 01 Jan 1970 00:00:00 GMT
A request to /api/1451001600000
should return { unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }
Your project can handle dates that can be successfully parsed by new Date(date_string)
If the input date string is invalid, the api returns an object having the structure { error : "Invalid Date" }
An empty date parameter should return the current time in a JSON object with a unix
key
An empty date parameter should return the current time in a JSON object with a utc
key
help how and where are these questions are answered in the code. see codes here: https://replit.com/@LaminSuwareh/boilerplate-project-timestamp-1#server.js
I don’t understand. You wrote the code, right? How did you know what to write?
Part of being a good dev is being a good engineer. Engineers like taking things apart. Maybe start commenting out code and see how that affects various tests.
1 Like
yes I wrote them but I am bit curious that’s why it took almost 3 days to complete it and that’s why I came for help.