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:
Riqwan Thamir
2024-09-11 15:08:37 +02:00
committed by GitHub
parent fdd0543011
commit a729fb3fbb
29 changed files with 1037 additions and 464 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)