feat(medusa-js, medusa-react): PublishableKeys SC management (#2734)

This commit is contained in:
Frane Polić
2022-12-07 12:16:48 +01:00
committed by GitHub
parent 322d462311
commit 3b2c929408
6 changed files with 228 additions and 3 deletions
@@ -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")
)
})
})