Skip to content

Commit

Permalink
Merge pull request #47 from zylcom/preview
Browse files Browse the repository at this point in the history
update order service
  • Loading branch information
zylcom authored May 24, 2024
2 parents 2720fc0 + 6fb37bc commit fdcbc26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions __test__/order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ describe("GET /api/orders/:orderId", function () {
expect(result.status).toBe(200);
expect(result.body.data.id).toBe(order.body.data.id);
expect(result.body.data.items).toBeDefined();
expect(result.body.data.shipment).toBeDefined();
expect(result.body.data.payment).toBeDefined();
expect(result.body.data.username).toBe(order.body.data.username);
});

Expand All @@ -237,6 +239,8 @@ describe("GET /api/orders/:orderId", function () {
expect(result.status).toBe(200);
expect(result.body.data.id).toBe(order.body.data.id);
expect(result.body.data.items).toBeDefined();
expect(result.body.data.shipment).toBeDefined();
expect(result.body.data.payment).toBeDefined();
expect(result.body.data.guestId).toBe(order.body.data.guestId);
});

Expand Down Expand Up @@ -276,6 +280,8 @@ describe("POST /api/orders/:orderId/cancel", function () {
expect(result.body.data.id).toBe(order.body.data.id);
expect(result.body.data.status).toBe("canceled");
expect(result.body.data.items).toBeDefined();
expect(result.body.data.shipment).toBeDefined();
expect(result.body.data.payment).toBeDefined();
});

it("should can cancel order as guest user", async () => {
Expand All @@ -295,6 +301,8 @@ describe("POST /api/orders/:orderId/cancel", function () {
expect(result.body.data.id).toBe(order.body.data.id);
expect(result.body.data.status).toBe("canceled");
expect(result.body.data.items).toBeDefined();
expect(result.body.data.shipment).toBeDefined();
expect(result.body.data.payment).toBeDefined();
});

it("should reject if token is invalid", async () => {
Expand Down
6 changes: 5 additions & 1 deletion src/services/order-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ const cancel = async (request) => {
throw new ResponseError(404, "Order not found");
}

return prismaClient.order.update({ where: { id: order.id }, data: { status: "canceled" }, include: { items: { include: { product: true } } } });
return prismaClient.order.update({
where: { id: order.id },
data: { status: "canceled" },
include: { payment: true, shipment: true, items: { include: { product: true } } },
});
};

const listOrder = async (request) => {
Expand Down

0 comments on commit fdcbc26

Please sign in to comment.