Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(spec-parser): add a test case for specParser.browser.test.ts #11528

Merged
merged 1 commit into from
May 6, 2024
Merged
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
191 changes: 190 additions & 1 deletion packages/spec-parser/test/browser/specParser.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,196 @@ describe("SpecParser in Browser", () => {
sinon.restore();
});

describe("listSupportedAPIInfo", () => {
describe("listSupporttedAPIInfo", () => {
it("should list parameters successfully with required and optional parameters", async () => {
const specPath = "valid-spec.yaml";
const specParser = new SpecParser(specPath, {
allowMissingId: false,
allowMultipleParameters: true,
});
const spec = {
openapi: "3.0.0",
info: {
title: "Repair Service",
description: "A simple service to manage repairs",
version: "1.0.0",
},
servers: [
{
url: "https://poc-apim-gateway-fkh0bdaufkfpdugz.b02.azurefd.net",
description: "The repair api server",
},
],
paths: {
"/assignRepair": {
get: {
operationId: "assignRepair",
summary:
"Assign repair to technician for the customer based on car type and repair type",
description:
"Assign repair to technician for the customer based on car type and repair type",
parameters: [
{
name: "carType",
in: "query",
description: "Car type to repair",
schema: {
type: "string",
},
required: false,
},
{
name: "customerStatus",
in: "query",
description: "Customer status",
schema: {
type: "string",
enum: ["available", "pending", "sold"],
},
},
{
name: "customerToggle",
in: "query",
description: "Customer Toggle",
schema: {
type: "boolean",
},
allowEmptyValue: true,
required: true,
},
{
name: "limit",
in: "query",
schema: {
type: "integer",
minimum: 1,
maximum: 50,
},
description: "The numbers of items to return",
required: true,
},
{
name: "startDateString",
in: "query",
schema: {
type: "string",
},
description: "The start date for the report in different format",
required: true,
},
],
responses: {
"200": {
description: "The response that represents an appointment for the repair",
content: {
"application/json": {
schema: {
type: "object",
properties: {
id: {
type: "string",
description: "Id of the repair",
},
title: {
type: "string",
description: "The short summary of the repair",
},
assignedTo: {
type: "string",
description: "The engineer who is responsible for the repair",
},
customerPhoneNumber: {
type: "string",
description: "The phone number of the customer",
},
date: {
type: "string",
format: "date-time",
description:
"The date and time when the repair is scheduled or completed",
},
image: {
type: "string",
format: "uri",
description:
"The URL of the image of the item to be repaired or the repair process",
},
},
},
},
},
},
},
},
},
},
};

const parseStub = sinon.stub(specParser.parser, "parse").resolves(spec as any);
const dereferenceStub = sinon.stub(specParser.parser, "dereference").resolves(spec as any);

const result = await specParser.listSupportedAPIInfo();
expect(result).to.deep.equal([
{
method: "GET",
path: "/assignRepair",
title: "Assign repair to technician for ",
id: "assignRepair",
description:
"Assign repair to technician for the customer based on car type and repair type",
parameters: [
{
name: "customerToggle",
title: "CustomerToggle",
description: "Customer Toggle",
inputType: "toggle",
isRequired: true,
},
{
name: "limit",
title: "Limit",
description: "The numbers of items to return",
inputType: "number",
isRequired: true,
},
{
name: "startDateString",
title: "StartDateString",
description: "The start date for the report in different format",
inputType: "text",
isRequired: true,
},
{
name: "carType",
title: "CarType",
description: "Car type to repair",
inputType: "text",
},
{
name: "customerStatus",
title: "CustomerStatus",
description: "Customer status",
inputType: "choiceset",
choices: [
{
title: "available",
value: "available",
},
{
title: "pending",
value: "pending",
},
{
title: "sold",
value: "sold",
},
],
},
],
},
]);
});

it("should return a list of HTTP methods and paths for all GET with 1 parameter and without security", async () => {
const specPath = "valid-spec.yaml";
const specParser = new SpecParser(specPath, { allowMissingId: false });
Expand Down
Loading