Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS-3223] Consistently use Integer for Product price #41

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions __tests__/products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ describe("Products", () => {
const missingRes = await req(app).post(`/products`).send(rest);
expect(missingRes.status).toEqual(400);
expect(missingRes.body.message).toEqual(
"Price must be a number greater than 0."
"Price must be an integer greater than 0."
);
const invalidRes = await req(app)
.post(`/products`)
.send({ ...rest, price: "foo" });
expect(invalidRes.status).toEqual(400);
expect(invalidRes.body.message).toEqual(
"Price must be a number greater than 0."
"Price must be an integer greater than 0."
);
});

Expand All @@ -154,14 +154,14 @@ describe("Products", () => {
const missingRes = await req(app).post(`/products`).send(rest);
expect(missingRes.status).toEqual(400);
expect(missingRes.body.message).toEqual(
"Stock must be a number greater than or equal to 0."
"Stock must be an integer greater than or equal to 0."
);
const invalidRes = await req(app)
.post(`/products`)
.send({ ...rest, stock: -1 });
expect(invalidRes.status).toEqual(400);
expect(invalidRes.body.message).toEqual(
"Stock must be a number greater than or equal to 0."
"Stock must be an integer greater than or equal to 0."
);
});

Expand Down Expand Up @@ -204,25 +204,25 @@ describe("Products", () => {
describe("PATCH /products/:name", () => {
it("updates a product", async () => {
// Create a new product.
const product = mockProduct({ price: 10.99, category: "electronics" });
const product = mockProduct({ price: 10_99, category: "electronics" });
const createRes = await req(app).post(`/products`).send(product);
productsToCleanup.push(createRes.body);
// Check that the product was created successfully.
expect(createRes.status).toEqual(201);
expect(createRes.body.price).toEqual(10.99);
expect(createRes.body.price).toEqual(10_99);
// Update the product.
const updateRes = await req(app)
.patch(`/products/${createRes.body.id}`)
.send({ price: 19.99 });
.send({ price: 19_99 });
// Check that the product was updated successfully.
expect(updateRes.status).toEqual(200);
expect(updateRes.body.price).toEqual(19.99);
expect(updateRes.body.price).toEqual(19_99);
expect(updateRes.body.name).toEqual(product.name);
expect(Object.keys(updateRes.body).sort()).toEqual(productFields.sort());
});

it("returns a 404 if the product does not exist", async () => {
const res = await req(app).patch(`/products/1234`).send({ price: 19.99 });
const res = await req(app).patch(`/products/1234`).send({ price: 19_99 });
expect(res.status).toEqual(404);
expect(res.body.message).toEqual("No product with id '1234' exists.");
});
Expand Down Expand Up @@ -250,14 +250,14 @@ describe("Products", () => {
.send({ price: "not a number" });
expect(priceAsString.status).toEqual(400);
expect(priceAsString.body.message).toEqual(
"Price must be a number greater than 0 or be omitted."
"Price must be an integer greater than 0 or be omitted."
);
const negativePrice = await req(app)
.patch("/products/does-not-matter")
.send({ price: -1 });
expect(negativePrice.status).toEqual(400);
expect(negativePrice.body.message).toEqual(
"Price must be a number greater than 0 or be omitted."
"Price must be an integer greater than 0 or be omitted."
);
});

Expand All @@ -267,14 +267,14 @@ describe("Products", () => {
.send({ stock: "not a number" });
expect(stockAsString.status).toEqual(400);
expect(stockAsString.body.message).toEqual(
"Stock must be a number greater than or equal to 0 or be omitted."
"Stock must be an integer greater than or equal to 0 or be omitted."
);
const negativeStock = await req(app)
.patch("/products/does-not-matter")
.send({ stock: -1 });
expect(negativeStock.status).toEqual(400);
expect(negativeStock.body.message).toEqual(
"Stock must be a number greater than or equal to 0 or be omitted."
"Stock must be an integer greater than or equal to 0 or be omitted."
);
});

Expand Down Expand Up @@ -319,8 +319,8 @@ describe("Products", () => {

describe("GET /products/by-price", () => {
it("gets products within a price range", async () => {
const minPrice = 10;
const maxPrice = 50;
const minPrice = 10_00;
const maxPrice = 50_00;
const res = await req(app).get(
`/products/by-price?minPrice=${minPrice}&maxPrice=${maxPrice}`
);
Expand Down
Loading