feat(utils,types,framework,medusa): store endpoints should require publishable key (#9068)
* feat(utils,types,framework,medusa): store endpoints should require publishable key * chore: fix specs * chore: fix more specs * chore: update js-sdk * chore: fix specs wrt to default SC * chore: revert custom headers + change error message * chore: fix specs * chore: fix new store specs
This commit is contained in:
@@ -10,6 +10,8 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -24,6 +26,7 @@ medusaIntegrationTestRunner({
|
||||
let cartModuleService: ICartModuleService
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
let remoteLinkService: RemoteLink
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -38,6 +41,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/promotions", () => {
|
||||
@@ -123,9 +128,11 @@ medusaIntegrationTestRunner({
|
||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||
})
|
||||
|
||||
const created = await api.post(`/store/carts/${cart.id}/promotions`, {
|
||||
promo_codes: [createdPromotion.code],
|
||||
})
|
||||
const created = await api.post(
|
||||
`/store/carts/${cart.id}/promotions`,
|
||||
{ promo_codes: [createdPromotion.code] },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(created.status).toEqual(200)
|
||||
expect(created.data.cart).toEqual(
|
||||
@@ -264,9 +271,11 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const created = await api.post(`/store/carts/${cart.id}/promotions`, {
|
||||
promo_codes: [newPromotion.code],
|
||||
})
|
||||
const created = await api.post(
|
||||
`/store/carts/${cart.id}/promotions`,
|
||||
{ promo_codes: [newPromotion.code] },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(created.status).toEqual(200)
|
||||
expect(created.data.cart).toEqual(
|
||||
|
||||
@@ -25,7 +25,11 @@ import {
|
||||
RuleOperator,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||
import {
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { seedStorefrontDefaults } from "../../../../helpers/seed-storefront-defaults"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
import { setupTaxStructure } from "../../fixtures"
|
||||
@@ -58,6 +62,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
let region
|
||||
let store
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -84,6 +89,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
|
||||
const { store: defaultStore } = await seedStorefrontDefaults(
|
||||
appContainer,
|
||||
@@ -158,22 +165,26 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const created = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant_id: product.variants[1].id,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
})
|
||||
const created = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant_id: product.variants[1].id,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(created.status).toEqual(200)
|
||||
expect(created.data.cart).toEqual(
|
||||
@@ -230,25 +241,29 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const created = await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "NY",
|
||||
country_code: "US",
|
||||
province: "NY",
|
||||
postal_code: "94016",
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [
|
||||
{
|
||||
quantity: 1,
|
||||
variant_id: product.variants[0].id,
|
||||
const created = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "NY",
|
||||
country_code: "US",
|
||||
province: "NY",
|
||||
postal_code: "94016",
|
||||
},
|
||||
],
|
||||
})
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [
|
||||
{
|
||||
quantity: 1,
|
||||
variant_id: product.variants[0].id,
|
||||
},
|
||||
],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(created.status).toEqual(200)
|
||||
expect(created.data.cart).toEqual(
|
||||
@@ -283,10 +298,14 @@ medusaIntegrationTestRunner({
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
const response = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
})
|
||||
const response = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -310,10 +329,14 @@ medusaIntegrationTestRunner({
|
||||
default_sales_channel_id: sc.id,
|
||||
})
|
||||
|
||||
const response = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
})
|
||||
const response = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -332,10 +355,14 @@ medusaIntegrationTestRunner({
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
const response = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
region_id: region.id,
|
||||
})
|
||||
const response = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
email: "tony@stark.com",
|
||||
region_id: region.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -359,7 +386,10 @@ medusaIntegrationTestRunner({
|
||||
`/store/carts`,
|
||||
{},
|
||||
{
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -531,9 +561,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should respond 400 bad request on unknown props", async () => {
|
||||
await expect(
|
||||
api.post(`/store/carts`, {
|
||||
foo: "bar",
|
||||
})
|
||||
api.post(`/store/carts`, { foo: "bar" }, storeHeaders)
|
||||
).rejects.toThrow()
|
||||
})
|
||||
})
|
||||
@@ -624,9 +652,11 @@ medusaIntegrationTestRunner({
|
||||
])
|
||||
|
||||
// Should remove earlier adjustments from other promocodes
|
||||
let updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
promo_codes: [createdPromotion.code],
|
||||
})
|
||||
let updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ promo_codes: [createdPromotion.code] },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -654,9 +684,11 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
// Should remove all adjustments from other promo codes
|
||||
updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
promo_codes: [],
|
||||
})
|
||||
updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ promo_codes: [] },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -711,9 +743,11 @@ medusaIntegrationTestRunner({
|
||||
],
|
||||
})
|
||||
|
||||
let updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
email: "another@tax.com",
|
||||
})
|
||||
let updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ email: "another@tax.com" },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -733,9 +767,11 @@ medusaIntegrationTestRunner({
|
||||
region_id: region.id,
|
||||
})
|
||||
|
||||
updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
email: "another@tax.com",
|
||||
})
|
||||
updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ email: "another@tax.com" },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -860,11 +896,15 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
let updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
region_id: region.id,
|
||||
email: "tony@stark.com",
|
||||
sales_channel_id: salesChannel.id,
|
||||
})
|
||||
let updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{
|
||||
region_id: region.id,
|
||||
email: "tony@stark.com",
|
||||
sales_channel_id: salesChannel.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -930,10 +970,14 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
|
||||
updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
email: null,
|
||||
sales_channel_id: null,
|
||||
})
|
||||
updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{
|
||||
email: null,
|
||||
sales_channel_id: null,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -1063,9 +1107,11 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
let updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
email: "jon@stark.com",
|
||||
})
|
||||
let updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ email: "jon@stark.com" },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -1080,10 +1126,14 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
|
||||
updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
email: null,
|
||||
sales_channel_id: null,
|
||||
})
|
||||
updated = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{
|
||||
email: null,
|
||||
sales_channel_id: null,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -1107,12 +1157,16 @@ medusaIntegrationTestRunner({
|
||||
name: "Webshop",
|
||||
})
|
||||
|
||||
const created = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
})
|
||||
const created = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(created.status).toEqual(200)
|
||||
expect(created.data.cart).toEqual(
|
||||
@@ -1132,7 +1186,8 @@ medusaIntegrationTestRunner({
|
||||
`/store/carts/${created.data.cart.id}`,
|
||||
{
|
||||
email: "tony@stark-industries.com",
|
||||
}
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
@@ -1170,7 +1225,10 @@ medusaIntegrationTestRunner({
|
||||
sales_channel_id: salesChannel.id,
|
||||
})
|
||||
|
||||
const response = await api.get(`/store/carts/${cart.id}`)
|
||||
const response = await api.get(
|
||||
`/store/carts/${cart.id}`,
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -1373,10 +1431,14 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
let response = await api.post(`/store/carts/${cart.id}/line-items`, {
|
||||
variant_id: productWithSpecialTax.variants[0].id,
|
||||
quantity: 1,
|
||||
})
|
||||
let response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: productWithSpecialTax.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -1422,10 +1484,14 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
|
||||
response = await api.post(`/store/carts/${cart.id}/line-items`, {
|
||||
variant_id: productWithDefaultTax.variants[0].id,
|
||||
quantity: 1,
|
||||
})
|
||||
response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: productWithDefaultTax.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.data.cart).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -1458,31 +1524,39 @@ medusaIntegrationTestRunner({
|
||||
).data.product
|
||||
|
||||
const cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: region.currency_code,
|
||||
region_id: region.id,
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
metadata: {
|
||||
Size: "S",
|
||||
Color: "Black",
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
email: "tony@stark.com",
|
||||
currency_code: region.currency_code,
|
||||
region_id: region.id,
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
metadata: {
|
||||
Size: "S",
|
||||
Color: "Black",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
let response = await api.post(`/store/carts/${cart.id}/line-items`, {
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
metadata: {
|
||||
Size: "S",
|
||||
Color: "Black",
|
||||
let response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
metadata: {
|
||||
Size: "S",
|
||||
Color: "Black",
|
||||
},
|
||||
},
|
||||
})
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -1498,15 +1572,19 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
|
||||
response = await api.post(`/store/carts/${cart.id}/line-items`, {
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
metadata: {
|
||||
Size: "S",
|
||||
Color: "White",
|
||||
Special: "attribute",
|
||||
response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
metadata: {
|
||||
Size: "S",
|
||||
Color: "White",
|
||||
Special: "attribute",
|
||||
},
|
||||
},
|
||||
})
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -1541,9 +1619,11 @@ medusaIntegrationTestRunner({
|
||||
region_id: region.id,
|
||||
})
|
||||
|
||||
const response = await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
const response = await api.post(
|
||||
`/store/payment-collections`,
|
||||
{ cart_id: cart.id },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.payment_collection).toEqual(
|
||||
@@ -1566,14 +1646,22 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
const firstCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: cart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.payment_collection
|
||||
|
||||
const response = await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
const response = await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: cart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.payment_collection.id).toEqual(
|
||||
@@ -1598,15 +1686,23 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
const firstCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: firstCart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: firstCart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.payment_collection
|
||||
|
||||
const secondCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: secondCart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: secondCart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.payment_collection
|
||||
|
||||
expect(firstCollection.id).toBeTruthy()
|
||||
@@ -1646,7 +1742,11 @@ medusaIntegrationTestRunner({
|
||||
],
|
||||
})
|
||||
|
||||
let updated = await api.post(`/store/carts/${cart.id}/taxes`, {})
|
||||
let updated = await api.post(
|
||||
`/store/carts/${cart.id}/taxes`,
|
||||
{},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
|
||||
@@ -1696,7 +1796,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
let error = await api
|
||||
.post(`/store/carts/${cart.id}/taxes`, {})
|
||||
.post(`/store/carts/${cart.id}/taxes`, {}, storeHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.response.status).toEqual(400)
|
||||
@@ -1780,7 +1880,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
let response = await api.post(
|
||||
`/store/carts/${cart.id}/shipping-methods`,
|
||||
{ option_id: shippingOption.id }
|
||||
{ option_id: shippingOption.id },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -2016,36 +2117,46 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should create an order and create item reservations", async () => {
|
||||
const cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "ny",
|
||||
country_code: "us",
|
||||
province: "ny",
|
||||
postal_code: "94016",
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "ny",
|
||||
country_code: "us",
|
||||
province: "ny",
|
||||
postal_code: "94016",
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
})
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: cart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.payment_collection
|
||||
|
||||
await api.post(
|
||||
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||
{ provider_id: "pp_system_default" }
|
||||
{ provider_id: "pp_system_default" },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cart.id}/complete`,
|
||||
{}
|
||||
{},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -2152,16 +2263,20 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should throw an error when payment collection isn't created", async () => {
|
||||
const cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
})
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
const error = await api
|
||||
.post(`/store/carts/${cart.id}/complete`, {})
|
||||
.post(`/store/carts/${cart.id}/complete`, {}, storeHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.response.status).toEqual(400)
|
||||
@@ -2173,20 +2288,28 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should throw an error when payment collection isn't created", async () => {
|
||||
const cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
})
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: cart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
const error = await api
|
||||
.post(`/store/carts/${cart.id}/complete`, {})
|
||||
.post(`/store/carts/${cart.id}/complete`, {}, storeHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.response.status).toEqual(400)
|
||||
@@ -2198,51 +2321,69 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should fail to update cart when it is completed", async () => {
|
||||
const cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "ny",
|
||||
country_code: "us",
|
||||
province: "ny",
|
||||
postal_code: "94016",
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "ny",
|
||||
country_code: "us",
|
||||
province: "ny",
|
||||
postal_code: "94016",
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
})
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: cart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.payment_collection
|
||||
|
||||
await api.post(
|
||||
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||
{ provider_id: "pp_system_default" }
|
||||
{ provider_id: "pp_system_default" },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
await api.post(`/store/carts/${cart.id}/complete`, {})
|
||||
await api.post(`/store/carts/${cart.id}/complete`, {}, storeHeaders)
|
||||
|
||||
const cartRefetch = (await api.get(`/store/carts/${cart.id}`)).data
|
||||
.cart
|
||||
const cartRefetch = (
|
||||
await api.get(`/store/carts/${cart.id}`, storeHeaders)
|
||||
).data.cart
|
||||
|
||||
expect(cartRefetch.completed_at).toBeTruthy()
|
||||
|
||||
await expect(
|
||||
api.post(`/store/carts/${cart.id}/shipping-methods`, {
|
||||
option_id: shippingOption.id,
|
||||
})
|
||||
api.post(
|
||||
`/store/carts/${cart.id}/shipping-methods`,
|
||||
{
|
||||
option_id: shippingOption.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).rejects.toThrow()
|
||||
|
||||
const error = await api
|
||||
.post(`/store/carts/${cart.id}/line-items`, {
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
})
|
||||
.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.response.status).toEqual(400)
|
||||
@@ -2269,36 +2410,46 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
|
||||
const cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "ny",
|
||||
country_code: "us",
|
||||
province: "ny",
|
||||
postal_code: "94016",
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
shipping_address: {
|
||||
address_1: "test address 1",
|
||||
address_2: "test address 2",
|
||||
city: "ny",
|
||||
country_code: "us",
|
||||
province: "ny",
|
||||
postal_code: "94016",
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
},
|
||||
sales_channel_id: salesChannel.id,
|
||||
items: [{ quantity: 1, variant_id: product.variants[0].id }],
|
||||
})
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
})
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{
|
||||
cart_id: cart.id,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.payment_collection
|
||||
|
||||
await api.post(
|
||||
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||
{ provider_id: "pp_system_default" }
|
||||
{ provider_id: "pp_system_default" },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cart.id}/complete`,
|
||||
{}
|
||||
{},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -10,6 +10,8 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -24,6 +26,7 @@ medusaIntegrationTestRunner({
|
||||
let cartModuleService: ICartModuleService
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
let remoteLinkService: RemoteLink
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -38,6 +41,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
describe("DELETE /store/carts/:id/promotions", () => {
|
||||
@@ -147,6 +152,7 @@ medusaIntegrationTestRunner({
|
||||
data: {
|
||||
promo_codes: [appliedPromotionToRemove.code],
|
||||
},
|
||||
...storeHeaders,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -295,6 +301,7 @@ medusaIntegrationTestRunner({
|
||||
`/store/carts/${cart.id}/promotions`,
|
||||
{
|
||||
data: { promo_codes: [appliedPromotionToRemove.code] },
|
||||
...storeHeaders,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
const storeHeaders = {
|
||||
headers: {},
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ api }) => {
|
||||
testSuite: ({ api, getContainer }) => {
|
||||
describe("Currency - Store", () => {
|
||||
it("should correctly retrieve and list currencies", async () => {
|
||||
const publishableKey = await generatePublishableKey(getContainer())
|
||||
const storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
|
||||
const listResp = await api.get("/store/currencies", storeHeaders)
|
||||
|
||||
expect(listResp.data.currencies).toEqual(
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -13,6 +17,7 @@ medusaIntegrationTestRunner({
|
||||
describe("POST /store/customers/me/addresses", () => {
|
||||
let appContainer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -21,6 +26,11 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
it("should create a customer address", async () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
@@ -33,7 +43,12 @@ medusaIntegrationTestRunner({
|
||||
last_name: "Doe",
|
||||
address_1: "Test street 1",
|
||||
},
|
||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -9,6 +9,8 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -20,6 +22,7 @@ medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /store/customers", () => {
|
||||
let appContainer
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -27,6 +30,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
// TODO: Reenable once the customer authentication is fixed, and use the HTTP endpoints instead.
|
||||
@@ -55,7 +60,12 @@ medusaIntegrationTestRunner({
|
||||
last_name: "Doe",
|
||||
email: "john@me.com",
|
||||
},
|
||||
{ headers: { authorization: `Bearer ${token}` } }
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
@@ -13,6 +17,7 @@ medusaIntegrationTestRunner({
|
||||
describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
let appContainer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -21,6 +26,12 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
appContainer = getContainer()
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
it("should delete a customer address", async () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
@@ -35,7 +46,12 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const response = await api.delete(
|
||||
`/store/customers/me/addresses/${address.id}`,
|
||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -66,7 +82,10 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const response = await api
|
||||
.delete(`/store/customers/me/addresses/${address.id}`, {
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
})
|
||||
.catch((e) => e.response)
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -10,17 +14,25 @@ medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /store/customers", () => {
|
||||
let appContainer
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
appContainer = getContainer()
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
it("should retrieve auth user's customer", async () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
)
|
||||
|
||||
const response = await api.get(`/store/customers/me`, {
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
headers: { authorization: `Bearer ${jwt}`, ...storeHeaders.headers },
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
@@ -13,6 +17,7 @@ medusaIntegrationTestRunner({
|
||||
describe("GET /store/customers/me/addresses", () => {
|
||||
let appContainer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -21,6 +26,12 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
appContainer = getContainer()
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
it("should get all customer addresses and its count", async () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
@@ -60,7 +71,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
const response = await api.get(`/store/customers/me/addresses`, {
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
headers: { authorization: `Bearer ${jwt}`, ...storeHeaders.headers },
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -13,6 +17,7 @@ medusaIntegrationTestRunner({
|
||||
describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||
let appContainer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -21,7 +26,13 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a customer address", async () => {
|
||||
beforeEach(async () => {
|
||||
appContainer = getContainer()
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
it.only("should update a customer address", async () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
)
|
||||
@@ -38,7 +49,12 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
first_name: "Jane",
|
||||
},
|
||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -70,7 +86,12 @@ medusaIntegrationTestRunner({
|
||||
.post(
|
||||
`/store/customers/me/addresses/${address.id}`,
|
||||
{ first_name: "Jane" },
|
||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${jwt}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => e.response)
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||
import {
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { getProductFixture } from "../../../../helpers/fixtures"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -23,6 +27,7 @@ medusaIntegrationTestRunner({
|
||||
let product
|
||||
let variant
|
||||
let region
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -30,6 +35,9 @@ medusaIntegrationTestRunner({
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
appContainer = getContainer()
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
|
||||
region = (
|
||||
await api.post(
|
||||
@@ -87,7 +95,8 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
|
||||
let response = await api.get(
|
||||
`/store/products/${product.id}?currency_code=usd`
|
||||
`/store/products/${product.id}?currency_code=usd`,
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -149,7 +158,8 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
|
||||
let response = await api.get(
|
||||
`/store/products/${product.id}?currency_code=usd`
|
||||
`/store/products/${product.id}?currency_code=usd`,
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -184,10 +194,14 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
).data.customer_group
|
||||
|
||||
const authResponse = await api.post("/store/auth", {
|
||||
email: "test5@email-pl.com",
|
||||
password: "test",
|
||||
})
|
||||
const authResponse = await api.post(
|
||||
"/store/auth",
|
||||
{
|
||||
email: "test5@email-pl.com",
|
||||
password: "test",
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
|
||||
|
||||
@@ -215,6 +229,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
headers: {
|
||||
Cookie: authCookie,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -8,7 +8,11 @@ import {
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||
import {
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -31,6 +35,7 @@ medusaIntegrationTestRunner({
|
||||
let fulfillmentSet
|
||||
let cart
|
||||
let shippingOption
|
||||
let storeHeaders
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
@@ -38,6 +43,8 @@ medusaIntegrationTestRunner({
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -172,25 +179,30 @@ medusaIntegrationTestRunner({
|
||||
).data.shipping_option
|
||||
|
||||
cart = (
|
||||
await api.post(`/store/carts`, {
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
currency_code: "usd",
|
||||
email: "test@admin.com",
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
currency_code: "usd",
|
||||
email: "test@admin.com",
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
})
|
||||
|
||||
describe("GET /admin/shipping-options?cart_id=", () => {
|
||||
it("should get all shipping options for a cart successfully", async () => {
|
||||
const resp = await api.get(
|
||||
`/store/shipping-options?cart_id=${cart.id}`
|
||||
`/store/shipping-options?cart_id=${cart.id}`,
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
const shippingOptions = resp.data.shipping_options
|
||||
|
||||
Reference in New Issue
Block a user