Skip to content

Commit 049f843

Browse files
committed
converted to TDD project
as all the tests are basically written right there in the acceptance criteria already
1 parent 6e9067b commit 049f843

5 files changed

Lines changed: 67 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
E-Commerce-API/node_modules/
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const express = require("express");
22
const app = express();
3-
const { Pool } = require("pg");
43
// Your code to run the server should go here
54
// Don't hardcode your DB password in the code or upload it to GitHub! Never ever do this ever.
65
// Use environment variables instead:
76
// https://www.codementor.io/@parthibakumarmurugesan/what-is-env-how-to-set-up-and-run-a-env-file-in-node-1pnyxw9yxj
7+
8+
module.exports = app;

E-Commerce-API/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "cyf-ecommerce-api",
3+
"version": "1.0.0",
4+
"description": "API for the CYF ecommerce application",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node app.js",
8+
"test": "jest"
9+
},
10+
"keywords": [
11+
"node",
12+
"express",
13+
"API",
14+
"CYF"
15+
],
16+
"author": "CYF",
17+
"license": "CC-BY-4-0",
18+
"dependencies": {
19+
"express": "^4.17.1"
20+
},
21+
"devDependencies": {
22+
"jest": "^27.2.5",
23+
"supertest": "^6.1.6"
24+
}
25+
}

E-Commerce-API/readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Project Brief: E-Commerce API
22

3+
You are a developer building an Express application to connect your e-commerce database to a shop front. Your client requires a fully tested API so you will write this application TDD-style: writing the test first and then the code to make the test pass. There is a starter test given to help you, that satisfies the first user story.
4+
5+
How will you make this test pass?
6+
37
## User Stories
48

59
As a developer, I want to add new API endpoints to the NodeJS application for the cyf-ecommerce-api, so that I can improve the functionality of the application.
610

11+
As a developer, I want to build up my API using TDD - writing the test first and then iterating : adding one feature to pass one unit test.
12+
713
- As a user, I want to view a list of all products with their prices and supplier names.
814
- As a user, I want to search for products by name.
915
- As a user, I want to view a single customer by their ID.
@@ -18,6 +24,11 @@ As a developer, I want to add new API endpoints to the NodeJS application for th
1824

1925
## Acceptance Criteria
2026

27+
- [ ] Each user story has an accompanying unit test
28+
- [ ] Secrets are not stored in the codebase
29+
30+
<details>
31+
<summary>Try writing out your own acceptance criteria from the user stories before looking here</summary>
2132
- [ ] Endpoint `/products` should return a list of all product names with their prices and supplier names.
2233
- [ ] Endpoint `/products` should filter the list of products by name using a query parameter, even if the parameter is not used.
2334
- [ ] Endpoint `/customers/:customerId` should load a single customer by their ID.
@@ -29,3 +40,12 @@ As a developer, I want to add new API endpoints to the NodeJS application for th
2940
- [ ] Endpoint `/orders/:orderId` should delete an existing order and all associated order items.
3041
- [ ] Endpoint `/customers/:customerId` should delete an existing customer only if the customer doesn't have any orders.
3142
- [ ] Endpoint `/customers/:customerId/orders` should load all the orders along with the items in the orders of a specific customer. The information returned should include order references, order dates, product names, unit prices, suppliers, and quantities.
43+
</details>
44+
45+
### Sanity check!
46+
47+
In this project, you must write the test first.
48+
49+
It's better to turn in a smaller set of user stories than to turn in untested features.
50+
51+
If you're running out of time, scope down your application rather than commit untested code. Cut your _scope_, not your quality.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const request = require("supertest");
2+
const app = require("../app");
3+
4+
describe("GET /products", () => {
5+
it("should return a list of all product names with their prices and supplier names", async () => {
6+
const response = await request(app).get("/products");
7+
expect(response.status).toBe(200);
8+
expect(response.body).toEqual(
9+
expect.arrayContaining([
10+
expect.objectContaining({
11+
name: expect.any(String),
12+
price: expect.any(Number),
13+
supplierName: expect.any(String),
14+
}),
15+
])
16+
);
17+
});
18+
});

0 commit comments

Comments
 (0)