diff --git a/integration-tests/http/__tests__/user/admin/user.spec.ts b/integration-tests/http/__tests__/user/admin/user.spec.ts index 0bce05ac99..3fd8e13959 100644 --- a/integration-tests/http/__tests__/user/admin/user.spec.ts +++ b/integration-tests/http/__tests__/user/admin/user.spec.ts @@ -40,8 +40,7 @@ medusaIntegrationTestRunner({ describe("GET /admin/users", () => { it("should list users", async () => { - const response = await api - .get("/admin/users", adminHeaders) + const response = await api.get("/admin/users", adminHeaders) expect(response.status).toEqual(200) @@ -91,71 +90,6 @@ medusaIntegrationTestRunner({ }) ).data.token }) - - // BREAKING: V2 users do not require a role - // We should probably remove this endpoint? - it("should create a user", async () => { - const payload = { - email: "test@test123.com", - } - - // In V2, the flow to create an authenticated user depends on the token or session of a previously created auth user - const headers = { - headers: { Authorization: `Bearer ${token}` }, - } - - const response = await api.post("/admin/users", payload, headers) - - expect(response.status).toEqual(200) - expect(response.data.user).toEqual( - expect.objectContaining({ - id: expect.stringMatching(/^user_*/), - created_at: expect.any(String), - updated_at: expect.any(String), - email: "test@test123.com", - }) - ) - }) - - // V2 only test - it("should throw, if session/bearer auth is present for existing user", async () => { - const emailPassResponse = await api.post("/auth/user/emailpass", { - email: "test@test123.com", - password: "test123", - }) - - const token = emailPassResponse.data.token - - const headers = (token) => ({ - headers: { Authorization: `Bearer ${token}` }, - }) - - const res = await api.post( - "/admin/users", - { - email: "test@test123.com", - }, - headers(token) - ) - - const authenticated = await api.post("/auth/user/emailpass", { - email: "test@test123.com", - password: "test123", - }) - - const payload = { - email: "different@email.com", - } - - const errorResponse = await api - .post("/admin/users", payload, headers(authenticated.data.token)) - .catch((err) => err.response) - - expect(errorResponse.status).toEqual(400) - expect(errorResponse.data.message).toEqual( - "Request carries authentication for an existing user" - ) - }) }) describe("POST /admin/users/:id", () => { diff --git a/packages/modules/order/integration-tests/__tests__/create-order.ts b/packages/modules/order/integration-tests/__tests__/create-order.ts index 726123e39f..bb9687ec75 100644 --- a/packages/modules/order/integration-tests/__tests__/create-order.ts +++ b/packages/modules/order/integration-tests/__tests__/create-order.ts @@ -208,6 +208,15 @@ moduleIntegrationTestRunner({ }) const created = await service.createOrders(inpCopy) + expect(created.summary).toEqual( + expect.objectContaining({ + transaction_total: 68, + pending_difference: -20.21999000999001, + paid_total: 68, + refunded_total: 0, + }) + ) + const refund = await service.addTransactions([ { order_id: created.id, @@ -226,6 +235,8 @@ moduleIntegrationTestRunner({ expect(serializedOrder.summary).toEqual( expect.objectContaining({ + transaction_total: 48, + pending_difference: -0.21999000999001, paid_total: 68, refunded_total: 20, }) @@ -243,6 +254,8 @@ moduleIntegrationTestRunner({ expect(serializedOrder2.summary).toEqual( expect.objectContaining({ + transaction_total: 68, + pending_difference: -20.21999000999001, paid_total: 68, refunded_total: 0, }) @@ -268,6 +281,8 @@ moduleIntegrationTestRunner({ expect.objectContaining({ paid_total: 68, refunded_total: 50, + transaction_total: 18, + pending_difference: 29.78000999000999, }) ) @@ -285,6 +300,8 @@ moduleIntegrationTestRunner({ expect.objectContaining({ paid_total: 68, refunded_total: 70, + transaction_total: -2, + pending_difference: 49.78000999000999, }) ) }) diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 26c556142b..ad165fd97d 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -2921,7 +2921,18 @@ export default class OrderModuleService< op(summary.totals.refunded_total, MathBN.abs(trx.amount)) ) } + + summary.totals.transaction_total = new BigNumber( + op(summary.totals.transaction_total, trx.amount) + ) } + + summary.totals.pending_difference = new BigNumber( + MathBN.sub( + summary.totals.current_order_total, + summary.totals.transaction_total + ) + ) }) createRawPropertiesFromBigNumber(summaries)