Skip to content

Commit

Permalink
[@typespec/http-specs] - Remove handler for majority of the Scenarios (
Browse files Browse the repository at this point in the history
…#4725)

This PR handles the removal of `handler` property in majority of the
Scenarios. All Scenarios are validated and tested. Please review and
approve the PR. Thanks
  • Loading branch information
sarangan12 authored Oct 14, 2024
1 parent ab6d951 commit 3dfdd79
Show file tree
Hide file tree
Showing 48 changed files with 113 additions and 815 deletions.
14 changes: 1 addition & 13 deletions packages/http-specs/specs/authentication/api-key/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -17,14 +17,6 @@ Scenarios.Authentication_ApiKey_invalid = passOnSuccess({
error: "invalid-api-key",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-api-key",
}),
};
},
kind: "MockApiDefinition",
});

Expand All @@ -39,9 +31,5 @@ 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",
});
14 changes: 1 addition & 13 deletions packages/http-specs/specs/authentication/http/custom/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -13,10 +13,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 @@ -35,13 +31,5 @@ Scenarios.Authentication_Http_Custom_invalid = passOnSuccess({
error: "invalid-api-key",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-api-key",
}),
};
},
kind: "MockApiDefinition",
});
14 changes: 1 addition & 13 deletions packages/http-specs/specs/authentication/oauth2/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -13,10 +13,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 @@ -32,13 +28,5 @@ Scenarios.Authentication_OAuth2_invalid = passOnSuccess({
error: "invalid-grant",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-grant",
}),
};
},
kind: "MockApiDefinition",
});
10 changes: 1 addition & 9 deletions packages/http-specs/specs/authentication/union/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -13,10 +13,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 @@ -31,9 +27,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",
});
21 changes: 1 addition & 20 deletions packages/http-specs/specs/encode/bytes/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { resolvePath } from "@typespec/compiler";
import {
CollectionFormat,
json,
MockRequest,
passOnSuccess,
ScenarioMockApi,
} from "@typespec/spec-api";
import { CollectionFormat, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { readFileSync } from "fs";
import { fileURLToPath } from "url";

Expand Down Expand Up @@ -78,13 +72,6 @@ function createPropertyServerTests(uri: string, data: any, value: any) {
response: {
status: 200,
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals({ value: value });
return {
status: 200,
body: json({ value: value }),
};
},
kind: "MockApiDefinition",
});
}
Expand Down Expand Up @@ -126,12 +113,6 @@ function createHeaderServerTests(uri: string, data: any, value: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("value", value);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
}
Expand Down
26 changes: 3 additions & 23 deletions packages/http-specs/specs/encode/duration/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ function createBodyServerTests(uri: string, data: any, value: any) {
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals({ value: value });
return {
status: 200,
body: json({ value: value }),
};
},
kind: "MockApiDefinition",
});
}
Expand Down Expand Up @@ -150,12 +143,6 @@ function createHeaderServerTests(uri: string, headersData: any, value: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("duration", value);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
}
Expand All @@ -177,28 +164,21 @@ Scenarios.Encode_Duration_Header_iso8601 = createHeaderServerTests(
Scenarios.Encode_Duration_Header_int32Seconds = createHeaderServerTests(
"/encode/duration/header/int32-seconds",
{
duration: 36,
duration: "36",
},
"36",
);
Scenarios.Encode_Duration_Header_floatSeconds = createHeaderServerTests(
"/encode/duration/header/float-seconds",
{
duration: 35.625,
},
"35.625",
);
Scenarios.Encode_Duration_Header_floatSeconds = createHeaderServerTests(
"/encode/duration/header/float64-seconds",
{
duration: 35.625,
duration: "35.625",
},
"35.625",
);
Scenarios.Encode_Duration_Header_float64Seconds = createHeaderServerTests(
"/encode/duration/header/float64-seconds",
{
duration: 35.625,
duration: "35.625",
},
"35.625",
);
Expand Down
9 changes: 1 addition & 8 deletions packages/http-specs/specs/encode/numeric/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -15,13 +15,6 @@ function createTests(uri: string, value: any) {
status: 200,
body: json({ value }),
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals({ value });
return {
status: 200,
body: json({ value }),
};
},
kind: "MockApiDefinition",
});
}
Expand Down
6 changes: 1 addition & 5 deletions packages/http-specs/specs/parameters/basic/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
function createServerTests(uri: string) {
Expand All @@ -13,10 +13,6 @@ function createServerTests(uri: string) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ function createServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
}
Expand All @@ -38,10 +34,6 @@ Scenarios.Parameters_BodyOptionality_OptionalExplicit = passOnSuccess([
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
},
{
Expand Down
30 changes: 0 additions & 30 deletions packages/http-specs/specs/parameters/collection-format/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ Scenarios.Parameters_CollectionFormat_Query_csv = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("colors", ["blue", "red", "green"], "csv");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Expand All @@ -49,12 +43,6 @@ Scenarios.Parameters_CollectionFormat_Query_ssv = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("colors", ["blue", "red", "green"], "ssv");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Expand All @@ -67,12 +55,6 @@ Scenarios.Parameters_CollectionFormat_Query_tsv = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("colors", ["blue", "red", "green"], "tsv");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Expand All @@ -85,12 +67,6 @@ Scenarios.Parameters_CollectionFormat_Query_pipes = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("colors", ["blue", "red", "green"], "pipes");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Expand All @@ -103,11 +79,5 @@ Scenarios.Parameters_CollectionFormat_Header_csv = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("colors", "blue,red,green");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Loading

0 comments on commit 3dfdd79

Please sign in to comment.