Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/api/walletAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export class WalletAuthAPI {
"POST",
`/api/v2/drops/${segment(slug)}/items/media`,
body,
undefined,
{ camelizeResponse: false },
)
}

Expand All @@ -250,6 +252,9 @@ export class WalletAuthAPI {
return this.fetcher.request<OperationResponse<"upload_drop_allowlist">>(
"POST",
`/api/v2/drops/${segment(slug)}/allowlist`,
undefined,
undefined,
{ camelizeResponse: false },
)
}

Expand Down Expand Up @@ -301,6 +306,9 @@ export class WalletAuthAPI {
return this.fetcher.request<OperationResponse<"upload_collection_image">>(
"POST",
`/api/v2/collections/${segment(slug)}/images/${segment(imageType)}?${query}`,
undefined,
undefined,
{ camelizeResponse: false },
)
}

Expand Down Expand Up @@ -340,7 +348,7 @@ export class WalletAuthAPI {
"/api/v2/profile/images",
body,
undefined,
{ snakeizeBody: false },
{ snakeizeBody: false, camelizeResponse: false },
)
}

Expand Down
75 changes: 75 additions & 0 deletions test/api/walletAuthUploadContext.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { afterEach, describe, expect, it, vi } from "vitest"
import { OpenSeaAPI } from "../../src/api/api"
import type { WalletAuthFetcher } from "../../src/api/fetcher"
import { WalletAuthAPI, type WalletAuthRequest } from "../../src/api/walletAuth"

const uploadContext = {
url: "https://uploads.example.com/",
method: "POST",
fields: {
key: "uploads/example.png",
"Content-Type": "image/png",
success_action_status: "201",
},
token: "upload-token-example",
}

afterEach(() => {
vi.unstubAllGlobals()
vi.restoreAllMocks()
})

describe("wallet-auth upload context response casing", () => {
it("preserves signed multipart field names through the real fetch boundary", async () => {
const responses = [uploadContext, [uploadContext]]
vi.stubGlobal(
"fetch",
vi.fn(
async () =>
new Response(JSON.stringify(responses.shift()), { status: 200 }),
),
)
const api = new OpenSeaAPI({ apiKey: "key", authToken: "jwt" })

const profile = await api.walletAuth.createProfileImageUpload({
imageType: "PROFILE",
contentType: "image/png",
})
const dropMedia = await api.walletAuth.createDropItemMediaUpload("drop", {
filenames: [],
})

expect(profile.fields).toEqual(uploadContext.fields)
expect(dropMedia[0].fields).toEqual(uploadContext.fields)
})

it("opts every UploadContext helper out of response camelization", async () => {
const request = vi.fn().mockResolvedValue({})
const api = new WalletAuthAPI({
get: vi.fn(),
request,
} as unknown as WalletAuthFetcher)
const dropMediaBody: WalletAuthRequest<"upload_drop_item_media"> = {
filenames: [],
}
const profileImageBody: WalletAuthRequest<"upload_profile_image"> = {
imageType: "PROFILE",
contentType: "image/png",
}
const calls = [
() => api.createDropItemMediaUpload("drop", dropMediaBody),
() => api.createDropAllowlistUpload("drop"),
() =>
api.createCollectionImageUpload("collection", "banner", "image/png"),
() => api.createProfileImageUpload(profileImageBody),
]

for (const call of calls) {
request.mockClear()
await call()
expect(request.mock.calls[0]?.[4]).toMatchObject({
camelizeResponse: false,
})
}
})
})