chore: Create publishable API key as part of the defaults (#14356)
* wip * chore: fix tests * Create tiny-carrots-bathe.md
This commit is contained in:
1 parent
11de7e3e34
commit
7e3ed913a6
5 files changed
+160
-10
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { ApiKeyType } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { ApiKeyType } from "@medusajs/utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
@@ -74,7 +74,7 @@ medusaIntegrationTestRunner({
|
||||
const listedApiKeys = await api.get(`/admin/api-keys`, adminHeaders)
|
||||
|
||||
expect(deleted.status).toEqual(200)
|
||||
expect(listedApiKeys.data.api_keys).toHaveLength(0)
|
||||
expect(listedApiKeys.data.api_keys).toHaveLength(1) // we still have the default publishable api key
|
||||
})
|
||||
|
||||
it("should allow searching for api keys", async () => {
|
||||
@@ -108,9 +108,16 @@ medusaIntegrationTestRunner({
|
||||
expect(listedSecretKeys.data.api_keys[0].title).toEqual(
|
||||
"Test Secret Key"
|
||||
)
|
||||
expect(listedPublishableKeys.data.api_keys).toHaveLength(1)
|
||||
expect(listedPublishableKeys.data.api_keys[0].title).toEqual(
|
||||
"Test Publishable Key"
|
||||
expect(listedPublishableKeys.data.api_keys).toHaveLength(2)
|
||||
expect(listedPublishableKeys.data.api_keys).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
title: "Test Publishable Key",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Default Publishable API Key",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.data.count).toBe(2)
|
||||
expect(response.data.count).toBe(3) // two created keys and the default publishable api key
|
||||
expect(response.data.limit).toBe(2)
|
||||
expect(response.data.offset).toBe(0)
|
||||
expect(response.data.api_keys).toHaveLength(2)
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { createDefaultsWorkflow } from "@medusajs/core-flows"
|
||||
import { Query } from "@medusajs/modules-sdk"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = {}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ getContainer }) => {
|
||||
describe("Defaults", () => {
|
||||
let appContainer
|
||||
let query: Query
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
query = appContainer.resolve("query")
|
||||
})
|
||||
|
||||
it("should successfully create default data on first run", async () => {
|
||||
const {
|
||||
data: [store],
|
||||
} = await query.graph({
|
||||
entity: "store",
|
||||
fields: ["id", "name", "default_sales_channel_id"],
|
||||
})
|
||||
const {
|
||||
data: [salesChannel],
|
||||
} = await query.graph({
|
||||
entity: "sales_channel",
|
||||
fields: ["id", "name"],
|
||||
})
|
||||
const {
|
||||
data: [publishableApiKey],
|
||||
} = await query.graph({
|
||||
entity: "api_key",
|
||||
fields: ["id", "type", "title"],
|
||||
filters: {
|
||||
type: "publishable",
|
||||
},
|
||||
})
|
||||
|
||||
expect(store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
default_sales_channel_id: salesChannel.id,
|
||||
})
|
||||
)
|
||||
expect(salesChannel).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "Default Sales Channel",
|
||||
})
|
||||
)
|
||||
expect(publishableApiKey).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
title: "Default Publishable API Key",
|
||||
type: "publishable",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should skip creating default data on n+1 runs", async () => {
|
||||
await createDefaultsWorkflow(appContainer).run()
|
||||
|
||||
const { data: stores } = await query.graph({
|
||||
entity: "store",
|
||||
fields: ["id"],
|
||||
})
|
||||
const { data: salesChannels } = await query.graph({
|
||||
entity: "sales_channel",
|
||||
fields: ["id"],
|
||||
})
|
||||
const { data: publishableApiKeys } = await query.graph({
|
||||
entity: "api_key",
|
||||
fields: ["id", "type"],
|
||||
filters: {
|
||||
type: "publishable",
|
||||
},
|
||||
})
|
||||
|
||||
expect(stores.length).toEqual(1)
|
||||
expect(salesChannels.length).toEqual(1)
|
||||
expect(publishableApiKeys.length).toEqual(1)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user