hinchley2018 / learning-ecommerce

Small e-commerce project to learn full-stack development
MIT License
7 stars 9 forks source link

Build get products endpoint #5

Closed hinchley2018 closed 6 months ago

hinchley2018 commented 7 months ago

Returns a list of products Each product has id, description, price

At first just return mock data (ask ChatGPT to create a list of ten products with those fields above)

teoh4770 commented 7 months ago

Can I tackle this issue @hinchley2018 ?

I believe the way to do this is

  1. Running a get method with express
  2. Setup the endpoint in the first get method parameter (in this case, i believe it is "/products")
  3. Setup the callback function in the second get method parameter (in this case, a callback that returns a list of mock object?)
hinchley2018 commented 7 months ago

@teoh4770 of course lmk if you get stuck or need help

teoh4770 commented 7 months ago

Thanks @hinchley2018

teoh4770 commented 6 months ago

Hi @hinchley2018, got a few questions related to this issue. So I have setup the "/products" route that return a list of products when being requested. However, I stuck at a few parts:

  1. I'm gonna setup the api functions in "frontend" folder similar to this, do you think it is a good structure? Or do you prefer to call it "controller" instead of "api" in this case?

File structures:

api/
  ProductsAPI.js
  ProductsAPI.test.js

Reference Image:

Screenshot 2024-03-18 at 11 50 14 PM
  1. In the ProductsAPI, there's a function "getProducts" that fetch the products using the endpoint setup at the backend. I wanna setup a test for the "getProducts" async function, but I realise that I didn't know how to setup a mock test for async function. I directly called the function inside the test block, which I know is incorrect. Any example of how to do this?
hinchley2018 commented 6 months ago

closed by #22