mirror of
https://github.com/anomalyco/opencode.git
synced 2026-10-24 05:50:01 +00:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { SalesforceCliError, salesforceCliResponse } from "./salesforce-cli-response"
|
|
|
|
test("unwraps a successful Salesforce Lead creation from the CLI HTTP envelope", () => {
|
|
expect(
|
|
salesforceCliResponse(
|
|
JSON.stringify({
|
|
status: 0,
|
|
result: { statusCode: 201, headers: {}, body: { id: "test-lead", success: true, errors: [] } },
|
|
}),
|
|
),
|
|
).toEqual({ id: "test-lead", success: true, errors: [] })
|
|
})
|
|
|
|
test("rejects a Salesforce HTTP failure even if the CLI exits successfully", () => {
|
|
expect(() =>
|
|
salesforceCliResponse(
|
|
JSON.stringify({
|
|
status: 0,
|
|
result: { statusCode: 400, body: [{ errorCode: "INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST" }] },
|
|
}),
|
|
),
|
|
).toThrow()
|
|
})
|
|
|
|
test("rejects CLI errors and responses missing the HTTP envelope", () => {
|
|
expect(() => salesforceCliResponse(JSON.stringify({ status: 1, message: "CLI error" }))).toThrow()
|
|
expect(() => salesforceCliResponse(JSON.stringify({ status: 0, result: { success: true } }))).toThrow()
|
|
})
|
|
|
|
test("preserves the Salesforce rejection code when the CLI exits nonzero", () => {
|
|
expect(() =>
|
|
salesforceCliResponse(
|
|
JSON.stringify({
|
|
status: 1,
|
|
result: { statusCode: 400, body: [{ errorCode: "DUPLICATES_DETECTED", message: "Duplicate found" }] },
|
|
}),
|
|
),
|
|
).toThrow(new SalesforceCliError("DUPLICATES_DETECTED"))
|
|
})
|