Feat(medusa-js, medusa-react): Upload endpoints in medusa js and react (#1716)
* export types from admin uploads * add delete and download to medusa-js * add upload endpoints to hooks * remove upload from js and react * pr feedback * Apply suggestions from code review Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * rename types for admin uploads Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
bf47d1aecd
commit
9018d270be
@@ -0,0 +1,46 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import {
|
||||
useAdminDeleteFile,
|
||||
useAdminCreatePresignedDownloadUrl,
|
||||
} from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminDeleteFile hook", () => {
|
||||
test("Removes file with key and returns deleteresult", async () => {
|
||||
const file_key = "test"
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteFile(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate({ file_key })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data).toEqual(
|
||||
expect.objectContaining({ id: file_key, object: "file", deleted: true })
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreatePresignedDownloadUrl hook", () => {
|
||||
test("", async () => {
|
||||
const file_key = "test"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreatePresignedDownloadUrl(),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({ file_key })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.download_url).toEqual(fixtures.get("upload").url)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user