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 17 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
6 changes: 6 additions & 0 deletions .changeset/poor-deers-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@azure-tools/cadl-ranch-specs": minor
"@azure-tools/cadl-ranch": minor
---

Remove handler code and commonapi file
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",
},
]);
Loading
Loading