feat(medusa-js, medusa-react): PublishableKeys SC management (#2734)
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
useAdminRevokePublishableApiKey,
|
||||
useAdminUpdatePublishableApiKey,
|
||||
useAdminCreatePublishableApiKey,
|
||||
useAdminAddPublishableKeySalesChannelsBatch,
|
||||
useAdminRemovePublishableKeySalesChannelsBatch,
|
||||
} from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
@@ -113,3 +115,53 @@ describe("useAdminDeletePublishableApiKey hook", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminAddPublishableKeySalesChannelsBatch hook", () => {
|
||||
test("Adds a SC to the publishable api key scope", async () => {
|
||||
const id = "pubkey_1234"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminAddPublishableKeySalesChannelsBatch(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
sales_channel_ids: [{ id: "rand_id" }],
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.publishable_api_key).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("publishable_api_key"),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRemovePublishableKeySalesChannelsBatch hook", () => {
|
||||
test("Deletes a SC from the publishable api key scope", async () => {
|
||||
const id = "pubkey_1234"
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminRemovePublishableKeySalesChannelsBatch(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
sales_channel_ids: [{ id: "rand_id" }],
|
||||
})
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.publishable_api_key).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("publishable_api_key"),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { renderHook } from "@testing-library/react-hooks"
|
||||
import {
|
||||
useAdminPublishableApiKey,
|
||||
useAdminPublishableApiKeys,
|
||||
useAdminPublishableApiKeySalesChannels,
|
||||
} from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
@@ -39,3 +40,23 @@ describe("useAdminPublishableApiKeys hook", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminPublishableApiKeySalesChannels hook", () => {
|
||||
test("returns a list of sales channels of a publishable api key", async () => {
|
||||
const publishable_api_key = fixtures.get("publishable_api_key")
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminPublishableApiKeySalesChannels(publishable_api_key.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.sales_channels).toEqual(
|
||||
fixtures.get("sales_channels")
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user