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

[@azure-tools/cadl-ranch-specs] - Handle PassOnCode, Remove Handler & Remove commonapi.ts file #755

Merged
merged 18 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -14,10 +14,6 @@ Scenarios.Authentication_ApiKey_valid = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("x-ms-api-key", "valid-key");
return { status: 204 };
},
kind: "MockApiDefinition",
});

Expand All @@ -36,13 +32,5 @@ Scenarios.Authentication_ApiKey_invalid = passOnCode(403, {
error: "invalid-api-key",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-api-key",
}),
};
},
kind: "MockApiDefinition",
});
43 changes: 0 additions & 43 deletions packages/cadl-ranch-specs/http/authentication/commonapi.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { json, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -14,10 +14,6 @@ Scenarios.Authentication_Http_Custom_valid = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("authorization", "SharedAccessKey valid-key");
return { status: 204 };
},
kind: "MockApiDefinition",
});

Expand All @@ -36,13 +32,5 @@ Scenarios.Authentication_Http_Custom_invalid = passOnCode(403, {
error: "invalid-api-key",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-api-key",
}),
};
},
kind: "MockApiDefinition",
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { json, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -14,10 +14,6 @@ Scenarios.Authentication_OAuth2_valid = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("authorization", "Bearer https://security.microsoft.com/.default");
return { status: 204 };
},
kind: "MockApiDefinition",
});

Expand All @@ -33,13 +29,5 @@ Scenarios.Authentication_OAuth2_invalid = passOnCode(403, {
error: "invalid-grant",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-grant",
}),
};
},
kind: "MockApiDefinition",
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -14,10 +14,6 @@ Scenarios.Authentication_Union_validKey = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("x-ms-api-key", "valid-key");
return { status: 204 };
},
kind: "MockApiDefinition",
});

Expand All @@ -32,9 +28,5 @@ Scenarios.Authentication_Union_validToken = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("authorization", "Bearer https://security.microsoft.com/.default");
return { status: 204 };
},
kind: "MockApiDefinition",
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { passOnSuccess, ValidationError, json, MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, json, MockApiDefinition } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -16,15 +16,6 @@ function createMockApiDefinitions(route: string): MockApiDefinition {
status: 200,
body: json({ name: "sample" }),
},
handler: (req: MockRequest) => {
if (!("name" in req.query)) {
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
throw new ValidationError("Should submit name query", "any string", undefined);
}
return {
status: 200,
body: json({ name: req.query["name"] }),
};
},
kind: "MockApiDefinition",
};
}
Expand Down Expand Up @@ -58,15 +49,6 @@ Scenarios.Azure_ClientGenerator_Core_Access_RelativeModelInOperation = passOnSuc
status: 200,
body: json({ name: "Madge", inner: { name: "Madge" } }),
},
handler: (req: MockRequest) => {
if (!("name" in req.query)) {
throw new ValidationError("Should submit name query", "any string", undefined);
}
return {
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
status: 200,
body: json({ name: "Madge", inner: { name: "Madge" } }),
};
},
kind: "MockApiDefinition",
},
{
Expand All @@ -81,15 +63,6 @@ Scenarios.Azure_ClientGenerator_Core_Access_RelativeModelInOperation = passOnSuc
status: 200,
body: json({ name: "Madge", kind: "real" }),
},
handler: (req: MockRequest) => {
if (!("kind" in req.query)) {
throw new ValidationError("Should submit name query", "any string", undefined);
}
return {
status: 200,
body: json({ name: "Madge", kind: "real" }),
};
},
kind: "MockApiDefinition",
},
]);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { passOnSuccess, json, MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, json, MockApiDefinition } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -13,13 +13,6 @@ function createMockApiDefinitions(route: string, request: any, response: any): M
status: 200,
body: json(response),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(request);
return {
status: 200,
body: json(response),
};
},
kind: "MockApiDefinition",
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -15,11 +15,6 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([
response: {
status: 204,
},
handler: (req: MockRequest) => {
const validBody = { name: "Madge" };
req.expect.bodyEquals(validBody);
return { status: 204 };
},
kind: "MockApiDefinition",
},
{
Expand All @@ -30,12 +25,6 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([
status: 200,
body: json({ name: "Madge" }),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json({ name: "Madge" }),
};
},
kind: "MockApiDefinition",
},
{
Expand All @@ -46,12 +35,6 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([
status: 200,
body: json({ result: { name: "Madge" } }),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json({ result: { name: "Madge" } }),
};
},
kind: "MockApiDefinition",
},
]);
65 changes: 1 addition & 64 deletions packages/cadl-ranch-specs/http/azure/core/basic/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { passOnSuccess, json, ValidationError, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -18,16 +18,6 @@ Scenarios.Azure_Core_Basic_createOrUpdate = passOnSuccess({
body: { name: "Madge" },
},
response: { status: 200, body: json(validUser) },
handler: (req: MockRequest) => {
if (req.params.id !== "1") {
throw new ValidationError("Expected path param id=1", "1", req.params.id);
}
req.expect.containsHeader("content-type", "application/merge-patch+json");
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
const validBody = { name: "Madge" };
req.expect.bodyEquals(validBody);
return { status: 200, body: json(validUser) };
},
kind: "MockApiDefinition",
});

Expand All @@ -42,16 +32,6 @@ Scenarios.Azure_Core_Basic_createOrReplace = passOnSuccess({
body: { name: "Madge" },
},
response: { status: 200, body: json(validUser) },
handler: (req: MockRequest) => {
if (req.params.id !== "1") {
throw new ValidationError("Expected path param id=1", "1", req.params.id);
}
req.expect.containsHeader("content-type", "application/json");
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
const validBody = { name: "Madge" };
req.expect.bodyEquals(validBody);
return { status: 200, body: json(validUser) };
},
kind: "MockApiDefinition",
});

Expand All @@ -65,13 +45,6 @@ Scenarios.Azure_Core_Basic_get = passOnSuccess({
},
},
response: { status: 200, body: json(validUser) },
handler: (req: MockRequest) => {
if (req.params.id !== "1") {
throw new ValidationError("Expected path param id=1", "1", req.params.id);
}
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
return { status: 200, body: json(validUser) };
},
kind: "MockApiDefinition",
});
const responseBody = {
Expand Down Expand Up @@ -105,22 +78,6 @@ Scenarios.Azure_Core_Basic_list = passOnSuccess({
},
},
response: { status: 200, body: json(responseBody) },
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
req.expect.containsQueryParam("top", "5");
req.expect.containsQueryParam("skip", "10");
req.expect.containsQueryParam("orderby", "id");
req.expect.containsQueryParam("filter", "id lt 10");
if (!req.originalRequest.originalUrl.includes("select=id&select=orders&select=etag")) {
throw new ValidationError(
"Expected query param select=id&select=orders&select=etag ",
"select=id&select=orders&select=etag",
req.originalRequest.originalUrl,
);
}
req.expect.containsQueryParam("expand", "orders");
return { status: 200, body: json(responseBody) };
},
kind: "MockApiDefinition",
});

Expand All @@ -136,13 +93,6 @@ Scenarios.Azure_Core_Basic_delete = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
if (req.params.id !== "1") {
throw new ValidationError("Expected path param id=1", "1", req.params.id);
}
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
return { status: 204 };
},
kind: "MockApiDefinition",
});

Expand All @@ -160,14 +110,6 @@ Scenarios.Azure_Core_Basic_export = passOnSuccess({
status: 200,
body: json(validUser),
},
handler: (req: MockRequest) => {
if (req.params.id !== "1") {
throw new ValidationError("Expected path param id=1", "1", req.params.id);
}
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
req.expect.containsQueryParam("format", "json");
return { status: 200, body: json(validUser) };
},
kind: "MockApiDefinition",
});

Expand All @@ -182,10 +124,5 @@ Scenarios.Azure_Core_Basic_exportAllUsers = passOnSuccess({
},
},
response: { status: 200, body: json(expectBody) },
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
req.expect.containsQueryParam("format", "json");
return { status: 200, body: json(expectBody) };
},
kind: "MockApiDefinition",
});
Loading
Loading