feat(medusa,medusa-js,medusa-react): Add BatchJob API support in medusa-js + medusa-react (#1704)
* Add BatchJob API to medusa-js * Adds BatchJob API hooks * Fix tests in medusa-react
This commit is contained in:
committed by
GitHub
parent
5f2744eb9f
commit
7302d76e12
@@ -0,0 +1,78 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import {
|
||||
useAdminCancelBatchJob,
|
||||
useAdminConfirmBatchJob,
|
||||
useAdminCreateBatchJob,
|
||||
} from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateBatchJob hook", () => {
|
||||
test("creates a batch job and returns it", async () => {
|
||||
const batch = {
|
||||
type: "product_export",
|
||||
dry_run: false,
|
||||
context: {},
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateBatchJob(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(batch)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data?.response.status).toEqual(200)
|
||||
expect(result.current.data?.batch_job).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("batch_job"),
|
||||
...batch,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelBatchJob hook", () => {
|
||||
test("cancels a batch job and returns it", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCancelBatchJob(fixtures.get("batch_job").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data?.response.status).toEqual(200)
|
||||
expect(result.current.data?.batch_job).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("batch_job"),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminConfirmBatchJob hook", () => {
|
||||
test("confirms a batch job and returns it", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminConfirmBatchJob(fixtures.get("batch_job").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data?.response.status).toEqual(200)
|
||||
expect(result.current.data?.batch_job).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("batch_job"),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { useAdminBatchJob, useAdminBatchJobs } from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminBatchJobs hook", () => {
|
||||
test("returns a list of batch job", async () => {
|
||||
const batchJobs = fixtures.list("batch_job")
|
||||
const { result, waitFor } = renderHook(() => useAdminBatchJobs(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response?.status).toEqual(200)
|
||||
expect(result.current.batch_jobs).toEqual(batchJobs)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminBatchJob hook", () => {
|
||||
test("returns a batch job", async () => {
|
||||
const batchJob = fixtures.get("batch_job")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminBatchJob(batchJob.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response?.status).toEqual(200)
|
||||
expect(result.current.batch_job).toEqual(batchJob)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user