-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c6f33a
commit 223a89f
Showing
1 changed file
with
140 additions
and
0 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
packages/parsers/src/openapi/3.1/paths/__test__/ExampleObjectConverter.node.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { createMockContext } from "../../../../__test__/createMockContext.util"; | ||
import { ExampleObjectConverterNode } from "../ExampleObjectConverter.node"; | ||
import { RequestMediaTypeObjectConverterNode } from "../request/RequestMediaTypeObjectConverter.node"; | ||
|
||
describe("ExampleObjectConverterNode", () => { | ||
const mockContext = createMockContext(); | ||
|
||
describe("validateFormDataRequestExample", () => { | ||
it("should return false if input value is not an object", () => { | ||
const node = new ExampleObjectConverterNode( | ||
{ | ||
input: { | ||
requestExample: { value: "not an object" }, | ||
responseExample: undefined, | ||
}, | ||
context: mockContext, | ||
accessPath: [], | ||
pathId: "test", | ||
}, | ||
"/test", | ||
200, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
); | ||
|
||
node.resolvedRequestInput = { value: "not an object" }; | ||
expect(node.validateFormDataRequestExample()).toBe(false); | ||
}); | ||
|
||
it("should validate file fields", () => { | ||
const node = new ExampleObjectConverterNode( | ||
{ | ||
input: { | ||
requestExample: { | ||
value: { | ||
file: { filename: "test.txt", data: "base64data" }, | ||
}, | ||
}, | ||
responseExample: undefined, | ||
}, | ||
context: mockContext, | ||
accessPath: [], | ||
pathId: "test", | ||
}, | ||
"/test", | ||
200, | ||
undefined, | ||
{ | ||
contentType: "form-data", | ||
fields: { | ||
file: { multipartType: "file" }, | ||
}, | ||
} as RequestMediaTypeObjectConverterNode, | ||
undefined, | ||
undefined, | ||
); | ||
|
||
node.resolvedRequestInput = { | ||
value: { | ||
file: { filename: "test.txt", data: "base64data" }, | ||
}, | ||
}; | ||
expect(node.validateFormDataRequestExample()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe("convert", () => { | ||
it("should convert JSON request example", () => { | ||
const node = new ExampleObjectConverterNode( | ||
{ | ||
input: { | ||
requestExample: { value: { foo: "bar" } }, | ||
responseExample: undefined, | ||
}, | ||
context: mockContext, | ||
accessPath: [], | ||
pathId: "test", | ||
}, | ||
"/test", | ||
200, | ||
"test example", | ||
{ contentType: "json" } as RequestMediaTypeObjectConverterNode, | ||
undefined, | ||
undefined, | ||
); | ||
|
||
node.resolvedRequestInput = { value: { foo: "bar" } }; | ||
const result = node.convert(); | ||
|
||
expect(result).toEqual({ | ||
path: "/test", | ||
responseStatusCode: 200, | ||
name: "test example", | ||
description: undefined, | ||
pathParameters: undefined, | ||
queryParameters: undefined, | ||
headers: undefined, | ||
requestBody: { | ||
type: "json", | ||
value: { foo: "bar" }, | ||
}, | ||
responseBody: undefined, | ||
snippets: undefined, | ||
}); | ||
}); | ||
|
||
it("should convert bytes request example", () => { | ||
const node = new ExampleObjectConverterNode( | ||
{ | ||
input: { | ||
requestExample: { value: "base64string" }, | ||
responseExample: undefined, | ||
}, | ||
context: mockContext, | ||
accessPath: [], | ||
pathId: "test", | ||
}, | ||
"/test", | ||
200, | ||
undefined, | ||
{ contentType: "bytes" } as RequestMediaTypeObjectConverterNode, | ||
undefined, | ||
undefined, | ||
); | ||
|
||
node.resolvedRequestInput = { value: "base64string" }; | ||
const result = node.convert(); | ||
|
||
expect(result?.requestBody).toEqual({ | ||
type: "bytes", | ||
value: { | ||
type: "base64", | ||
value: "base64string", | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |