Skip to content

Commit

Permalink
Merge branch 'develop' into fix/create-shipping-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl committed Feb 6, 2023
2 parents 16d3f90 + 4d6e63d commit f719693
Show file tree
Hide file tree
Showing 53 changed files with 2,703 additions and 253 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-scissors-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(medusa): Option to override existing cron job
6 changes: 6 additions & 0 deletions .changeset/pretty-parents-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"medusa-payment-stripe": patch
"@medusajs/medusa": patch
---

feat(medusa-payment-stripe): Avoid unnecessary customer update if the stripe id already exists
5 changes: 5 additions & 0 deletions .changeset/rare-buckets-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(medusa): Include `rolling` in session options config with default of false
5 changes: 5 additions & 0 deletions .changeset/smooth-trees-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): `fields` param in store products/orders endpoints
5 changes: 5 additions & 0 deletions .changeset/spicy-jokes-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): ShippingOption type on `listAndCount`
5 changes: 5 additions & 0 deletions .changeset/tame-items-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(medusa): decorate order edit line items with totals
5 changes: 5 additions & 0 deletions .changeset/wild-ravens-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"medusa-payment-stripe": patch
---

fix(medusa-payment-stripe): Prevent Stripe events from retrying
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
const path = require("path")
const { IdMap } = require("medusa-test-utils")

const startServerWithEnvironment =
require("../../../../helpers/start-server-with-environment").default
const { useApi } = require("../../../../helpers/use-api")
const { useDb } = require("../../../../helpers/use-db")

const adminSeeder = require("../../../helpers/admin-seeder")

const {
simpleProductFactory,
simpleRegionFactory,
simpleCartFactory,
} = require("../../../factories")

jest.setTimeout(30000)

const adminReqConfig = {
headers: {
Authorization: "Bearer test_token",
},
}

describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/order-edits", () => {
let medusaProcess
let dbConnection

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
const [process, connection] = await startServerWithEnvironment({
cwd,
env: { MEDUSA_FF_TAX_INCLUSIVE_PRICING: true },
})
dbConnection = connection
medusaProcess = process
})

afterAll(async () => {
const db = useDb()
await db.shutdown()

medusaProcess.kill()
})

describe("Items totals", () => {
let product1
const prodId1 = IdMap.getId("prodId1")
const lineItemId1 = IdMap.getId("line-item-1")

beforeEach(async () => {
await adminSeeder(dbConnection)

product1 = await simpleProductFactory(dbConnection, {
id: prodId1,
})
})

afterEach(async () => {
const db = useDb()
return await db.teardown()
})

it("decorates items with (tax-inclusive) totals", async () => {
const taxInclusiveRegion = await simpleRegionFactory(dbConnection, {
tax_rate: 25,
includes_tax: true,
})

const taxInclusiveCart = await simpleCartFactory(dbConnection, {
email: "adrien@test.com",
region: taxInclusiveRegion.id,
line_items: [
{
id: lineItemId1,
variant_id: product1.variants[0].id,
quantity: 2,
unit_price: 10000,
includes_tax: true,
},
],
})

const api = useApi()

await api.post(`/store/carts/${taxInclusiveCart.id}/payment-sessions`)

const completeRes = await api.post(
`/store/carts/${taxInclusiveCart.id}/complete`
)

const order = completeRes.data.data

const response = await api.post(
`/admin/order-edits/`,
{
order_id: order.id,
internal_note: "This is an internal note",
},
adminReqConfig
)

expect(response.status).toEqual(200)
expect(response.data.order_edit).toEqual(
expect.objectContaining({
items: expect.arrayContaining([
expect.objectContaining({
// 2x items | unit_price: 10000 (tax incl.) | 25% tax
original_item_id: lineItemId1,
subtotal: 2 * 8000,
discount_total: 0,
total: 2 * 10000,
unit_price: 10000,
original_total: 2 * 10000,
original_tax_total: 2 * 2000,
tax_total: 2 * 2000,
}),
]),
discount_total: 0,
gift_card_total: 0,
gift_card_tax_total: 0,
shipping_total: 0,
subtotal: 16000,
tax_total: 4000,
total: 20000,
difference_due: 0,
})
)
})

it("decorates items with (tax-exclusive) totals", async () => {
const taxInclusiveRegion = await simpleRegionFactory(dbConnection, {
tax_rate: 25,
})

const cart = await simpleCartFactory(dbConnection, {
email: "adrien@test.com",
region: taxInclusiveRegion.id,
line_items: [
{
id: lineItemId1,
variant_id: product1.variants[0].id,
quantity: 2,
unit_price: 10000,
},
],
})

const api = useApi()

await api.post(`/store/carts/${cart.id}/payment-sessions`)

const completeRes = await api.post(`/store/carts/${cart.id}/complete`)

const order = completeRes.data.data

const response = await api.post(
`/admin/order-edits/`,
{
order_id: order.id,
internal_note: "This is an internal note",
},
adminReqConfig
)

expect(response.status).toEqual(200)
expect(response.data.order_edit).toEqual(
expect.objectContaining({
items: expect.arrayContaining([
expect.objectContaining({
original_item_id: lineItemId1,
subtotal: 2 * 10000,
discount_total: 0,
unit_price: 10000,
total: 2 * 10000 + 2 * 2500,
original_total: 2 * 10000 + 2 * 2500,
original_tax_total: 2 * 2500,
tax_total: 2 * 2500,
}),
]),
discount_total: 0,
gift_card_total: 0,
gift_card_tax_total: 0,
shipping_total: 0,
subtotal: 20000,
tax_total: 5000,
total: 25000,
difference_due: 0,
})
)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
const path = require("path")
const { OrderEditItemChangeType, OrderEdit } = require("@medusajs/medusa")
const { IdMap } = require("medusa-test-utils")

const startServerWithEnvironment =
require("../../../helpers/start-server-with-environment").default
const { useApi } = require("../../../helpers/use-api")
const { useDb, initDb } = require("../../../helpers/use-db")
const adminSeeder = require("../../helpers/admin-seeder")
const { useApi } = require("../../../../helpers/use-api")
const { useDb, initDb } = require("../../../../helpers/use-db")
const adminSeeder = require("../../../helpers/admin-seeder")
const {
simpleOrderEditFactory,
} = require("../../factories/simple-order-edit-factory")
const { IdMap } = require("medusa-test-utils")
} = require("../../../factories/simple-order-edit-factory")
const {
simpleOrderItemChangeFactory,
} = require("../../factories/simple-order-item-change-factory")
} = require("../../../factories/simple-order-item-change-factory")
const {
simpleLineItemFactory,
simpleProductFactory,
simpleOrderFactory,
simpleDiscountFactory,
simpleCartFactory,
simpleRegionFactory,
} = require("../../factories")
const { OrderEditItemChangeType, OrderEdit } = require("@medusajs/medusa")
const setupServer = require("../../../helpers/setup-server")
} = require("../../../factories")
const setupServer = require("../../../../helpers/setup-server")

jest.setTimeout(30000)

Expand All @@ -37,11 +35,9 @@ describe("/admin/order-edits", () => {
const adminUserId = "admin_user"

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({
cwd,
})
medusaProcess = await setupServer({ cwd })
})

afterAll(async () => {
Expand Down Expand Up @@ -1167,6 +1163,7 @@ describe("/admin/order-edits", () => {
id: orderId1,
fulfillment_status: "fulfilled",
payment_status: "captured",
tax_rate: null,
region: {
id: "test-region",
name: "Test region",
Expand Down Expand Up @@ -2572,13 +2569,15 @@ describe("/admin/order-edits", () => {
]),
}),
]),
discount_total: 2000,
// rounding issue since we are allocating 1/3 of the discount to one item and 2/3 to the other item where both cost 10
// resulting in adjustment amounts like: 1333...
discount_total: 2001,
total: 1099,
gift_card_total: 0,
gift_card_tax_total: 0,
shipping_total: 0,
subtotal: 3000,
tax_total: 100,
total: 1100,
})
)

Expand Down
52 changes: 52 additions & 0 deletions integration-tests/api/__tests__/store/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,58 @@ describe("/store/carts", () => {
)
})

it("lookup order response contains only fields defined with `fields` param", async () => {
const api = useApi()

const response = await api
.get(
"/store/orders?display_id=111&email=test@email.com&fields=status,object"
)
.catch((err) => {
return err.response
})

expect(Object.keys(response.data.order)).toEqual([
// fields
"status",
"object",
// relations
"shipping_address",
"fulfillments",
"items",
"shipping_methods",
"discounts",
"customer",
"payments",
"region",
])
})

it("get order response contains only fields defined with `fields` param", async () => {
const api = useApi()

const response = await api
.get("/store/orders/order_test?fields=status,object")
.catch((err) => {
return err.response
})

expect(Object.keys(response.data.order)).toEqual([
// fields
"status",
"object",
// relations
"shipping_address",
"fulfillments",
"items",
"shipping_methods",
"discounts",
"customer",
"payments",
"region",
])
})

it("looks up order", async () => {
const api = useApi()

Expand Down

0 comments on commit f719693

Please sign in to comment.