Skip to content

Commit

Permalink
Merge branch 'develop' into feat/payments
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Aug 18, 2024
2 parents 2c2d373 + 66c39ef commit 52dd2ec
Show file tree
Hide file tree
Showing 2,828 changed files with 81,835 additions and 92,854 deletions.
3 changes: 2 additions & 1 deletion integration-tests/http/__tests__/auth/admin/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ medusaIntegrationTestRunner({
await createAdminUser(dbConnection, adminHeaders, getContainer())
})

it.only("test the entire authentication flow", async () => {
// TODO: This test won't work since we don't allow creating a user through HTTP. We need to have the invite flow plugged in here.
it.skip("test the entire authentication flow", async () => {
// BREAKING: `/admin/auth` changes to `/auth/user/emailpass`
const signup = await api.post("/auth/user/emailpass", {
email: "[email protected]",
Expand Down
81 changes: 1 addition & 80 deletions integration-tests/http/__tests__/user/admin/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -80,84 +79,6 @@ medusaIntegrationTestRunner({
})
})

describe("POST /admin/users", () => {
let token

beforeEach(async () => {
token = (
await api.post("/auth/user/emailpass", {
email: "[email protected]",
password: "test123",
})
).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: "[email protected]",
}

// 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: "[email protected]",
})
)
})

// 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: "[email protected]",
password: "test123",
})

const token = emailPassResponse.data.token

const headers = (token) => ({
headers: { Authorization: `Bearer ${token}` },
})

const res = await api.post(
"/admin/users",
{
email: "[email protected]",
},
headers(token)
)

const authenticated = await api.post("/auth/user/emailpass", {
email: "[email protected]",
password: "test123",
})

const payload = {
email: "[email protected]",
}

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", () => {
it("should update a user", async () => {
const updateResponse = (
Expand Down
13 changes: 0 additions & 13 deletions packages/medusa/src/api/admin/users/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as QueryConfig from "./query-config"

import {
AdminCreateUser,
AdminGetUserParams,
AdminGetUsersParams,
AdminUpdateUser,
Expand All @@ -26,18 +25,6 @@ export const adminUserRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["POST"],
matcher: "/admin/users",
middlewares: [
authenticate("user", ["bearer", "session"], { allowUnregistered: true }),
validateAndTransformBody(AdminCreateUser),
validateAndTransformQuery(
AdminGetUserParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["GET"],
matcher: "/admin/users/:id",
Expand Down
35 changes: 1 addition & 34 deletions packages/medusa/src/api/admin/users/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { createUserAccountWorkflow } from "@medusajs/core-flows"
import { CreateUserDTO, HttpTypes } from "@medusajs/types"
import { HttpTypes } from "@medusajs/types"
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../types/routing"
import { refetchUser } from "./helpers"

export const GET = async (
req: AuthenticatedMedusaRequest,
Expand All @@ -35,34 +32,4 @@ export const GET = async (
})
}

export const POST = async (
req: AuthenticatedMedusaRequest<CreateUserDTO>,
res: MedusaResponse<HttpTypes.AdminUserResponse>
) => {
// If `actor_id` is present, the request carries authentication for an existing user
if (req.auth_context.actor_id) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Request carries authentication for an existing user"
)
}

const input = {
input: {
userData: req.validatedBody,
authIdentityId: req.auth_context.auth_identity_id,
},
}

const { result } = await createUserAccountWorkflow(req.scope).run(input)

const user = await refetchUser(
result.id,
req.scope,
req.remoteQueryConfig.fields
)

res.status(200).json({ user })
}

export const AUTHENTICATE = false
17 changes: 17 additions & 0 deletions packages/modules/order/integration-tests/__tests__/create-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ moduleIntegrationTestRunner<IOrderModuleService>({
})
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,
Expand All @@ -226,6 +235,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({

expect(serializedOrder.summary).toEqual(
expect.objectContaining({
transaction_total: 48,
pending_difference: -0.21999000999001,
paid_total: 68,
refunded_total: 20,
})
Expand All @@ -243,6 +254,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({

expect(serializedOrder2.summary).toEqual(
expect.objectContaining({
transaction_total: 68,
pending_difference: -20.21999000999001,
paid_total: 68,
refunded_total: 0,
})
Expand All @@ -268,6 +281,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({
expect.objectContaining({
paid_total: 68,
refunded_total: 50,
transaction_total: 18,
pending_difference: 29.78000999000999,
})
)

Expand All @@ -285,6 +300,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({
expect.objectContaining({
paid_total: 68,
refunded_total: 70,
transaction_total: -2,
pending_difference: 49.78000999000999,
})
)
})
Expand Down
11 changes: 11 additions & 0 deletions packages/modules/order/src/services/order-module-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
curl -X POST '{backend_url}/admin/payment-collections' \
-H 'x-medusa-access-token: {api_token}' \
-H 'Content-Type: application/json' \
--data-raw '{
"order_id": "{value}"
}'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: object
description: SUMMARY
x-schemaName: AdminPaymentCollectionResponse
required:
- payment_collection
properties:
payment_collection:
$ref: ./AdminPaymentCollection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
type: object
description: SUMMARY
x-schemaName: CreateCartWorkflowInput
properties:
region_id:
type: string
title: region_id
description: The cart's region id.
customer_id:
type: string
title: customer_id
description: The cart's customer id.
sales_channel_id:
type: string
title: sales_channel_id
description: The cart's sales channel id.
email:
type: string
title: email
description: The cart's email.
format: email
currency_code:
type: string
title: currency_code
description: The cart's currency code.
shipping_address_id:
type: string
title: shipping_address_id
description: The cart's shipping address id.
billing_address_id:
type: string
title: billing_address_id
description: The cart's billing address id.
shipping_address:
oneOf:
- type: string
title: shipping_address
description: The cart's shipping address.
- $ref: ./CreateCartAddress.yaml
billing_address:
oneOf:
- type: string
title: billing_address
description: The cart's billing address.
- $ref: ./CreateCartAddress.yaml
metadata:
type: object
description: The cart's metadata.
items:
type: array
description: The cart's items.
items:
$ref: ./CreateCartCreateLineItem.yaml
promo_codes:
type: array
description: The cart's promo codes.
items:
type: string
title: promo_codes
description: The promo code's promo codes.

This file was deleted.

Loading

0 comments on commit 52dd2ec

Please sign in to comment.