api-client/packages/hoppscotch-common/src/helpers/__tests__/postman-import.spec.ts
okxint 174c87d5d3
fix(common): handle non-string values in Postman collection import (#6137)
Co-authored-by: atharvasingh7007 <singhatharva7007@gmail.com>
Co-authored-by: XHamzaX <hamzaswitch1221@gmail.com>
Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com>
2026-04-15 20:14:42 +05:30

60 lines
1.5 KiB
TypeScript

import * as E from "fp-ts/Either"
import { describe, expect, it } from "vitest"
import { hoppPostmanImporter } from "../import-export/import/postman"
const postmanCollectionWithArrayHeader = JSON.stringify({
info: {
name: "Array Header Import",
schema:
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
},
item: [
{
name: "Import Array Header",
request: {
method: "GET",
header: [
{
key: "Authorization",
value: ["Basic xxxxx", "Basic xxxxxxxxxxxx="],
},
{
key: "Content-Type",
value: "application/x-www-form-urlencoded",
},
],
url: "https://echo.hoppscotch.io/get",
},
},
],
})
describe("Postman importer", () => {
it("coerces array header values instead of crashing during import", async () => {
const result = await hoppPostmanImporter([
postmanCollectionWithArrayHeader,
])()
expect(E.isRight(result)).toBe(true)
if (E.isLeft(result)) {
throw new Error("Expected Postman import to succeed")
}
expect(result.right[0].requests[0].headers).toEqual(
expect.arrayContaining([
expect.objectContaining({
key: "Authorization",
value: "Basic xxxxx,Basic xxxxxxxxxxxx=",
active: true,
}),
expect.objectContaining({
key: "Content-Type",
value: "application/x-www-form-urlencoded",
active: true,
}),
])
)
})
})