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

* Initial Commit

* Remove unused commonapi file

* Remove handler code

* Added Changeset

* Fix generated handler for handling params vs query params

* Add Handler to Traits

* Modify expectedUpdateBody in json-merge-patch

* Add body to encode bytes

* Added XML Condition check in app.ts

* One more change for json-merge-patch

* Add code to check for body object

* nit

* xml request body fix

* Add handler for xml case

* Remove xml(data)

* Modify spec summary

---------

Co-authored-by: tadelesh <tadelesh.shi@live.cn>
This commit is contained in:
Sarangan Rajamanickam 2024-10-17 22:34:06 -07:00 коммит произвёл GitHub
Родитель 170cc7ca7a
Коммит caa22906ae
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
67 изменённых файлов: 176 добавлений и 1523 удалений

Просмотреть файл

@ -0,0 +1,6 @@
---
"@azure-tools/cadl-ranch-specs": minor
"@azure-tools/cadl-ranch": minor
---
Remove handler code and commonapi file

Просмотреть файл

@ -79,12 +79,12 @@ Expects header 'authorization': 'Bearer https://security.microsoft.com/.default'
- `get /azure/client-generator-core/access/internalOperation/publicDecoratorInInternal`
This scenario contains internal operations. All should be generated but not exposed.
Expected query parameter: name=<any string>
Expected query parameter: name= "sample"
Expected response body:
```json
{
"name": <any string>
"name": "sample"
}
```
@ -95,12 +95,12 @@ Expected response body:
- `get /azure/client-generator-core/access/publicOperation/publicDecoratorInPublic`
This scenario contains public operations. It should be generated and exported.
Expected query parameter: name=<any string>
Expected query parameter: name="sample"
Expected response body:
```json
{
"name": <any string>
"name": "sample"
}
```
@ -119,12 +119,12 @@ This scenario contains internal operations. All should be generated but not expo
- `get /azure/client-generator-core/access/sharedModelInOperation/internal`
This scenario contains two operations, one public, another internal. The public one should be generated and exported while the internal one should be generated but not exposed.
Expected query parameter: name=<any string>
Expected query parameter: name= "sample"
Expected response body:
```json
{
"name": <any string>
"name": "sample"
}
```

Просмотреть файл

@ -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> = {};
@ -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",
});
@ -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",
});

Просмотреть файл

@ -1,43 +0,0 @@
import {
passOnSuccess,
passOnCode,
mockapi,
json,
PassOnSuccessScenario,
PassOnCodeScenario,
MockRequest,
} from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
interface ValidAndInvalidCodeScenarios {
valid: PassOnSuccessScenario;
invalid: PassOnCodeScenario;
}
export function getValidAndInvalidScenarios(
scenarioFolder: string,
errorCode: string,
authenticationValidation: (req: MockRequest) => void,
): ValidAndInvalidCodeScenarios {
return {
valid: passOnSuccess(
mockapi.get(`/authentication/${scenarioFolder}/valid`, (req) => {
authenticationValidation(req);
return { status: 204 };
}),
),
invalid: passOnCode(
403,
mockapi.get(`/authentication/${scenarioFolder}/invalid`, (req) => {
return {
status: 403,
body: json({
error: errorCode,
}),
};
}),
),
};
}

Просмотреть файл

@ -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> = {};
@ -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",
});
@ -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",
});

Просмотреть файл

@ -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> = {};
@ -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",
});
@ -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",
});

Просмотреть файл

@ -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> = {};
@ -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",
});
@ -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",
});

Просмотреть файл

@ -15,11 +15,11 @@ namespace _Specs_.Azure.ClientGenerator.Core.Access;
@scenario
@scenarioDoc("""
This scenario contains public operations. It should be generated and exported.
Expected query parameter: name=<any string>
Expected query parameter: name="sample"
Expected response body:
```json
{
"name": <any string>
"name": "sample"
}
```
""")
@ -51,11 +51,11 @@ namespace PublicOperation {
@scenario
@scenarioDoc("""
This scenario contains internal operations. All should be generated but not exposed.
Expected query parameter: name=<any string>
Expected query parameter: name= "sample"
Expected response body:
```json
{
"name": <any string>
"name": "sample"
}
```
""")
@ -98,11 +98,11 @@ namespace InternalOperation {
@scenario
@scenarioDoc("""
This scenario contains two operations, one public, another internal. The public one should be generated and exported while the internal one should be generated but not exposed.
Expected query parameter: name=<any string>
Expected query parameter: name= "sample"
Expected response body:
```json
{
"name": <any string>
"name": "sample"
}
```
""")
@ -157,14 +157,14 @@ namespace RelativeModelInOperation {
}
@doc("""
Expected query parameter: name=<any string>
Expected query parameter: name="Madge"
Expected response body:
```json
{
"name": <any string>,
"name": "Madge",
"inner":
{
"name": <any string>
"name": "Madge"
}
}
```
@ -175,11 +175,11 @@ namespace RelativeModelInOperation {
op operation(@query name: string): OuterModel;
@doc("""
Expected query parameter: kind=<any string>
Expected query parameter: kind= "real"
Expected response body:
```json
{
"name": <any string>,
"name": "Madge",
"kind": "real"
}
```

Просмотреть файл

@ -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> = {};
@ -16,15 +16,6 @@ function createMockApiDefinitions(route: string): MockApiDefinition {
status: 200,
body: json({ name: "sample" }),
},
handler: (req: MockRequest) => {
if (!("name" in req.query)) {
throw new ValidationError("Should submit name query", "any string", undefined);
}
return {
status: 200,
body: json({ name: req.query["name"] }),
};
},
kind: "MockApiDefinition",
};
}
@ -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 {
status: 200,
body: json({ name: "Madge", inner: { name: "Madge" } }),
};
},
kind: "MockApiDefinition",
},
{
@ -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",
},
]);

Просмотреть файл

@ -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> = {};
@ -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",
};
}

Просмотреть файл

@ -28,7 +28,7 @@ namespace ModelInOperation {
Expected body parameter:
```json
{
"name": <any string>
"name": "Madge"
}
```
""")
@ -48,7 +48,7 @@ namespace ModelInOperation {
Expected response body:
```json
{
"name": <any string>
"name": "Madge"
}
```
""")
@ -78,7 +78,7 @@ namespace ModelInOperation {
```json
{
"result": {
"name": <any string>
"name": "Madge"
}
}
```

Просмотреть файл

@ -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> = {};
@ -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",
},
{
@ -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",
},
{
@ -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",
},
]);

Просмотреть файл

@ -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> = {};
@ -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");
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",
});
@ -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",
});
@ -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 = {
@ -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",
});
@ -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",
});
@ -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",
});
@ -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",
});

Просмотреть файл

@ -105,9 +105,6 @@ Scenarios.Azure_Core_Lro_Standard_createOrReplace = passOnSuccess([
status: 200,
body: json(validUser),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(validUser) };
},
kind: "MockApiDefinition",
},
]);

Просмотреть файл

@ -8,9 +8,6 @@ Scenarios.Azure_Core_Model_AzureCoreEmbeddingVector_get = passOnSuccess({
method: "get",
request: {},
response: { status: 200, body: json([0, 1, 2, 3, 4]) },
handler: (req) => {
return { status: 200, body: json([0, 1, 2, 3, 4]) };
},
kind: "MockApiDefinition",
});
@ -21,10 +18,6 @@ Scenarios.Azure_Core_Model_AzureCoreEmbeddingVector_put = passOnSuccess({
body: [0, 1, 2, 3, 4],
},
response: { status: 204 },
handler: (req) => {
req.expect.bodyEquals([0, 1, 2, 3, 4]);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -34,12 +27,5 @@ Scenarios.Azure_Core_Model_AzureCoreEmbeddingVector_post = passOnSuccess({
method: "post",
request: { body: { embedding: [0, 1, 2, 3, 4] } },
response: { status: 200, body: json(responseBody) },
handler: (req) => {
req.expect.bodyEquals({ embedding: [0, 1, 2, 3, 4] });
return {
status: 200,
body: json(responseBody),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -9,12 +9,6 @@ Scenarios.Azure_Core_Page_listWithPage = passOnSuccess({
method: "get",
request: {},
response: { status: 200, body: json({ value: [validUser] }) },
handler: (req: MockRequest) => {
const responseBody = {
value: [validUser],
};
return { status: 200, body: json(responseBody) };
},
kind: "MockApiDefinition",
});
@ -28,17 +22,6 @@ Scenarios.Azure_Core_Page_listWithParameters = passOnSuccess({
body: { inputName: "Madge" },
},
response: { status: 200, body: json({ value: [validUser] }) },
handler: (req: MockRequest) => {
req.expect.containsQueryParam("another", "Second");
const validBody = { inputName: "Madge" };
req.expect.bodyEquals(validBody);
const responseBody = {
value: [validUser],
};
return { status: 200, body: json(responseBody) };
},
kind: "MockApiDefinition",
});
@ -48,12 +31,6 @@ Scenarios.Azure_Core_Page_TwoModelsAsPageItem = passOnSuccess([
method: "get",
request: {},
response: { status: 200, body: json({ value: [{ id: 1 }] }) },
handler: (req: MockRequest) => {
const responseBody = {
value: [{ id: 1 }],
};
return { status: 200, body: json(responseBody) };
},
kind: "MockApiDefinition",
},
{
@ -61,12 +38,6 @@ Scenarios.Azure_Core_Page_TwoModelsAsPageItem = passOnSuccess([
method: "get",
request: {},
response: { status: 200, body: json({ value: [{ name: "Madge" }] }) },
handler: (req: MockRequest) => {
const responseBody = {
value: [{ name: "Madge" }],
};
return { status: 200, body: json(responseBody) };
},
kind: "MockApiDefinition",
},
]);
@ -76,11 +47,5 @@ Scenarios.Azure_Core_Page_listWithCustomPageModel = passOnSuccess({
method: "get",
request: {},
response: { status: 200, body: json({ items: [validUser] }) },
handler: (req: MockRequest) => {
const responseBody = {
items: [validUser],
};
return { status: 200, body: json(responseBody) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -9,9 +9,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_get = passOnSuccess({
method: "get",
request: {},
response: { status: 200, body: json("eastus") },
handler: (req: MockRequest) => {
return { status: 200, body: json("eastus") };
},
kind: "MockApiDefinition",
});
@ -25,10 +22,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_put = passOnSuccess({
},
},
response: { status: 204 },
handler: (req: MockRequest) => {
req.expect.bodyEquals("eastus");
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -38,13 +31,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_post = passOnSuccess({
method: "post",
request: { body: azureLocation },
response: { status: 200, body: json(azureLocation) },
handler: (req: MockRequest) => {
req.expect.bodyEquals({ location: "eastus" });
return {
status: 200,
body: json(azureLocation),
};
},
kind: "MockApiDefinition",
});
@ -57,10 +43,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_header = passOnSuccess({
},
},
response: { status: 204 },
handler: (req: MockRequest) => {
req.expect.containsHeader("region", "eastus");
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -73,9 +55,5 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_query = passOnSuccess({
},
},
response: { status: 204 },
handler: (req: MockRequest) => {
req.expect.containsQueryParam("region", "eastus");
return { status: 204 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, json, ValidationError, validateValueFormat, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, json, validateValueFormat, ValidationError, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};

Просмотреть файл

@ -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> = {};
@ -33,29 +33,5 @@ Scenarios.Client_AzureExampleClient_basicAction = passOnSuccess({
stringProperty: "text",
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
req.expect.containsQueryParam("query-param", "query");
req.expect.containsHeader("header-param", "header");
const validBody = {
stringProperty: "text",
modelProperty: {
int32Property: 1,
float32Property: 1.5,
enumProperty: "EnumValue1",
},
arrayProperty: ["item"],
recordProperty: {
record: "value",
},
};
req.expect.bodyEquals(validBody);
return {
status: 200,
body: json({
stringProperty: "text",
}),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -78,26 +78,6 @@ Scenarios.Azure_ResourceManager_CommonProperties_ManagedIdentity_get = passOnSuc
status: 200,
body: json(validSystemAssignedManagedIdentityResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.managedIdentityResourceName.toLowerCase() !== "identity") {
throw new ValidationError(
"Unexpected managed identity resource name",
"identity",
req.params.managedIdentityResourceName,
);
}
return {
status: 200,
body: json(validSystemAssignedManagedIdentityResource),
};
},
kind: "MockApiDefinition",
});
@ -119,27 +99,6 @@ Scenarios.Azure_ResourceManager_CommonProperties_ManagedIdentity_createWithSyste
status: 200,
body: json(validSystemAssignedManagedIdentityResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.managedIdentityResourceName.toLowerCase() !== "identity") {
throw new ValidationError(
"Unexpected managed identity resource name",
"identity",
req.params.managedIdentityResourceName,
);
}
req.expect.deepEqual(req.body["identity"], createExpectedIdentity);
return {
status: 200,
body: json(validSystemAssignedManagedIdentityResource),
};
},
kind: "MockApiDefinition",
});
@ -165,26 +124,5 @@ Scenarios.Azure_ResourceManager_CommonProperties_ManagedIdentity_updateWithUserA
status: 200,
body: json(validUserAssignedAndSystemAssignedManagedIdentityResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.managedIdentityResourceName.toLowerCase() !== "identity") {
throw new ValidationError(
"Unexpected managed identity resource name",
"identity",
req.params.managedIdentityResourceName,
);
}
req.expect.deepEqual(req.body["identity"], updateExpectedIdentity);
return {
status: 200,
body: json(validUserAssignedAndSystemAssignedManagedIdentityResource),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -76,19 +76,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_getByResourceGroup = passOnS
status: 200,
body: json(validSingletonResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
return {
status: 200,
body: json(validSingletonResource),
};
},
kind: "MockApiDefinition",
});
@ -112,25 +99,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_createOrUpdate = passOnSucce
status: 200,
body: json(validSingletonResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
req.expect.bodyEquals({
location: "eastus",
properties: {
description: "valid",
},
});
return {
status: 200,
body: json(validSingletonResource),
};
},
kind: "MockApiDefinition",
});
@ -164,28 +132,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_update = passOnSuccess({
},
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
req.expect.bodyEquals({
location: "eastus2",
properties: {
description: "valid2",
},
});
const resource = JSON.parse(JSON.stringify(validSingletonResource));
resource.location = "eastus2";
resource.properties.description = "valid2";
return {
status: 200,
body: json(resource),
};
},
kind: "MockApiDefinition",
});
@ -205,21 +151,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_listByResourceGroup = passOn
value: [validSingletonResource],
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
return {
status: 200,
body: json({
value: [validSingletonResource],
}),
};
},
kind: "MockApiDefinition",
});
@ -241,25 +172,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_actionSync = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
req.expect.bodyEquals({
message: "Resource action at top level.",
urgent: true,
});
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -279,22 +191,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_get = passOnSuccess({
status: 200,
body: json(validTopLevelResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
return {
status: 200,
body: json(validTopLevelResource),
};
},
kind: "MockApiDefinition",
});
@ -319,28 +215,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_createOrReplace = passOnSucce
status: 200,
body: json(validTopLevelResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
req.expect.bodyEquals({
location: "eastus",
properties: {
description: "valid",
},
});
return {
status: 200,
body: json(validTopLevelResource),
};
},
kind: "MockApiDefinition",
});
@ -373,27 +247,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_update = passOnSuccess({
},
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
req.expect.deepEqual(req.body.properties, {
description: "valid2",
});
const resource = JSON.parse(JSON.stringify(validTopLevelResource));
resource.properties.description = "valid2";
return {
status: 200,
body: json(resource),
};
},
kind: "MockApiDefinition",
});
@ -411,21 +264,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_delete = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -445,21 +283,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_listByResourceGroup = passOnS
value: [validTopLevelResource],
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
return {
status: 200,
body: json({
value: [validTopLevelResource],
}),
};
},
kind: "MockApiDefinition",
});
@ -478,18 +301,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_listBySubscription = passOnSu
value: [validTopLevelResource],
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
return {
status: 200,
body: json({
value: [validTopLevelResource],
}),
};
},
kind: "MockApiDefinition",
});
@ -510,25 +321,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_get = passOnSuccess({
status: 200,
body: json(validNestedResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
if (req.params.nestedResourceName.toLowerCase() !== "nested") {
throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName);
}
return {
status: 200,
body: json(validNestedResource),
};
},
kind: "MockApiDefinition",
});
@ -553,30 +345,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_createOrReplace = passOnSuccess
status: 200,
body: json(validNestedResource),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
if (req.params.nestedResourceName.toLowerCase() !== "nested") {
throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName);
}
req.expect.bodyEquals({
properties: {
description: "valid",
},
});
return {
status: 200,
body: json(validNestedResource),
};
},
kind: "MockApiDefinition",
});
@ -610,32 +378,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_update = passOnSuccess({
},
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
if (req.params.nestedResourceName.toLowerCase() !== "nested") {
throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName);
}
req.expect.bodyEquals({
properties: {
description: "valid2",
},
});
const resource = JSON.parse(JSON.stringify(validNestedResource));
resource.properties.description = "valid2";
return {
status: 200,
body: json(resource),
};
},
kind: "MockApiDefinition",
});
@ -654,12 +396,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_delete = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -680,23 +416,5 @@ Scenarios.Azure_ResourceManager_Resources_Nested_listByTopLevelTrackedResource =
value: [validNestedResource],
}),
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.topLevelResourceName.toLowerCase() !== "top") {
throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName);
}
return {
status: 200,
body: json({
value: [validNestedResource],
}),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -12,12 +12,6 @@ Scenarios.Client_Naming_Property_client = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ defaultName: true });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -30,12 +24,6 @@ Scenarios.Client_Naming_Property_language = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ defaultName: true });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -48,12 +36,6 @@ Scenarios.Client_Naming_Property_compatibleWithEncodedName = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ wireName: true });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -64,11 +46,6 @@ Scenarios.Client_Naming_operation = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -81,12 +58,6 @@ Scenarios.Client_Naming_parameter = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("defaultName", "true");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -99,12 +70,6 @@ Scenarios.Client_Naming_Header_request = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("default-name", "true");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -118,14 +83,6 @@ Scenarios.Client_Naming_Header_response = passOnSuccess({
"default-name": "true",
},
},
handler: (req: MockRequest) => {
return {
status: 204,
headers: {
"default-name": "true",
},
};
},
kind: "MockApiDefinition",
});
@ -138,12 +95,6 @@ Scenarios.Client_Naming_Model_client = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ defaultName: true });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -156,12 +107,6 @@ Scenarios.Client_Naming_Model_language = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ defaultName: true });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -177,12 +122,6 @@ Scenarios.Client_Naming_UnionEnum_unionEnumName = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("value1");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -198,11 +137,5 @@ Scenarios.Client_Naming_UnionEnum_unionEnumMemberName = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("value1");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api";
import { MockApiDefinition } from "@azure-tools/cadl-ranch-api";
export function createServerTests(uri: string): MockApiDefinition {
return {
@ -6,9 +6,6 @@ export function createServerTests(uri: string): MockApiDefinition {
method: "post",
request: {},
response: { status: 204 },
handler: (req: MockRequest) => {
return { status: 204 };
},
kind: "MockApiDefinition",
};
}

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, json, CollectionFormat, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, CollectionFormat, MockRequest, json } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { resolvePath } from "@typespec/compiler";
import { readFileSync } from "fs";
@ -67,13 +67,7 @@ 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 }),
};
body: json({ value: value }),
},
kind: "MockApiDefinition",
});
@ -116,12 +110,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",
});
}

Просмотреть файл

@ -76,13 +76,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",
});
}
@ -138,12 +131,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",
});
}

Просмотреть файл

@ -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> = {};
@ -16,13 +16,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",
});
}

Просмотреть файл

@ -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> = {};
@ -15,10 +15,6 @@ function createServerTests(uri: string) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
}

Просмотреть файл

@ -12,10 +12,6 @@ function createServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
}
@ -39,10 +35,6 @@ Scenarios.Parameters_BodyOptionality_OptionalExplicit = passOnSuccess([
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
},
{

Просмотреть файл

@ -32,12 +32,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",
});
@ -50,12 +44,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",
});
@ -68,12 +56,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",
});
@ -86,12 +68,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",
});
@ -104,11 +80,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",
});

Просмотреть файл

@ -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> = {};
@ -14,10 +14,6 @@ Scenarios.Parameters_Spread_Model_spreadAsRequestBody = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -32,10 +28,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequestOnlyWithBody = passOnSuc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -50,10 +42,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequestWithoutBody = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("test-header", "bar");
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -71,11 +59,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequest = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("test-header", "bar");
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -93,11 +76,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequestMix = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("test-header", "bar");
req.expect.bodyEquals({ prop: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -112,10 +90,6 @@ Scenarios.Parameters_Spread_Alias_spreadAsRequestBody = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -133,11 +107,6 @@ Scenarios.Parameters_Spread_Alias_spreadAsRequestParameter = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("x-ms-test-header", "bar");
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -158,16 +127,6 @@ Scenarios.Parameters_Spread_Alias_spreadWithMultipleParameters = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("x-ms-test-header", "bar");
req.expect.bodyEquals({
requiredString: "foo",
optionalInt: 1,
requiredIntList: [1, 2],
optionalStringList: ["foo", "bar"],
});
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -185,11 +144,6 @@ Scenarios.Parameters_Spread_Alias_spreadParameterWithInnerModel = passOnSuccess(
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("x-ms-test-header", "bar");
req.expect.bodyEquals({ name: "foo" });
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -208,10 +162,5 @@ Scenarios.Parameters_Spread_Alias_spreadParameterWithInnerAlias = passOnSuccess(
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("x-ms-test-header", "bar");
req.expect.bodyEquals({ name: "foo", age: 1 });
return { status: 204 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -27,11 +27,11 @@ export const expectedCreateBody = {
};
export const expectedUpdateBody = {
name: "Madge",
// name: "Madge",
description: null,
map: {
key: {
name: "InnerMadge",
// name: "InnerMadge",
description: null,
},
key2: null,
@ -53,13 +53,6 @@ Scenarios.Payload_JsonMergePatch_createResource = passOnSuccess({
status: 200,
body: json(expectedCreateBody),
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals(expectedCreateBody);
return {
status: 200,
body: json(expectedCreateBody),
};
},
kind: "MockApiDefinition",
});
Scenarios.Payload_JsonMergePatch_updateResource = passOnSuccess({
@ -79,27 +72,6 @@ Scenarios.Payload_JsonMergePatch_updateResource = passOnSuccess({
},
}),
},
handler: (req: MockRequest) => {
req.expect.deepEqual(req.body.description, expectedUpdateBody.description);
req.expect.deepEqual(req.body.map.key.description, expectedUpdateBody.map.key.description);
req.expect.deepEqual(req.body.map.key2, expectedUpdateBody.map.key2);
req.expect.deepEqual(req.body.array, expectedUpdateBody.array);
req.expect.deepEqual(req.body.intValue, expectedUpdateBody.intValue);
req.expect.deepEqual(req.body.floatValue, expectedUpdateBody.floatValue);
req.expect.deepEqual(req.body.innerModel, expectedUpdateBody.innerModel);
req.expect.deepEqual(req.body.intArray, expectedUpdateBody.intArray);
return {
status: 200,
body: json({
name: "Madge",
map: {
key: {
name: "InnerMadge",
},
},
}),
};
},
kind: "MockApiDefinition",
});
Scenarios.Payload_JsonMergePatch_updateOptionalResource = passOnSuccess({
@ -119,26 +91,5 @@ Scenarios.Payload_JsonMergePatch_updateOptionalResource = passOnSuccess({
},
}),
},
handler: (req: MockRequest) => {
req.expect.deepEqual(req.body.description, expectedUpdateBody.description);
req.expect.deepEqual(req.body.map.key.description, expectedUpdateBody.map.key.description);
req.expect.deepEqual(req.body.map.key2, expectedUpdateBody.map.key2);
req.expect.deepEqual(req.body.array, expectedUpdateBody.array);
req.expect.deepEqual(req.body.intValue, expectedUpdateBody.intValue);
req.expect.deepEqual(req.body.floatValue, expectedUpdateBody.floatValue);
req.expect.deepEqual(req.body.innerModel, expectedUpdateBody.innerModel);
req.expect.deepEqual(req.body.intArray, expectedUpdateBody.intArray);
return {
status: 200,
body: json({
name: "Madge",
map: {
key: {
name: "InnerMadge",
},
},
}),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -15,11 +15,6 @@ Scenarios.Payload_MediaType_StringBody_sendAsText = passOnSuccess({
response: {
status: 200,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("content-type", "text/plain");
req.expect.bodyEquals("{cat}");
return { status: 200 };
},
kind: "MockApiDefinition",
});
@ -35,13 +30,6 @@ Scenarios.Payload_MediaType_StringBody_getAsText = passOnSuccess({
status: 200,
body: { rawContent: "{cat}", contentType: "text/plain" },
},
handler: (req: MockRequest) => {
req.expect.containsHeader("accept", "text/plain");
return {
status: 200,
body: { rawContent: "{cat}", contentType: "text/plain" },
};
},
kind: "MockApiDefinition",
});
@ -57,11 +45,6 @@ Scenarios.Payload_MediaType_StringBody_sendAsJson = passOnSuccess({
response: {
status: 200,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("content-type", "application/json");
req.expect.bodyEquals("foo");
return { status: 200 };
},
kind: "MockApiDefinition",
});
@ -77,13 +60,5 @@ Scenarios.Payload_MediaType_StringBody_getAsJson = passOnSuccess({
status: 200,
body: json("foo"),
},
handler: (req: MockRequest) => {
req.expect.containsHeader("accept", "application/json");
return {
status: 200,
body: json("foo"),
contentType: "application/json",
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, xml, MockRequest } from "@azure-tools/cadl-ranch-api";
import { MockRequest, passOnSuccess, xml } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -134,12 +134,6 @@ function createServerTests(uri: string, data?: any) {
status: 200,
body: xml(data),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: xml(data),
};
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -151,9 +145,6 @@ function createServerTests(uri: string, data?: any) {
"content-type": "application/xml",
},
},
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("content-type", "application/xml");
req.expect.xmlBodyEquals(data);
@ -161,6 +152,9 @@ function createServerTests(uri: string, data?: any) {
status: 204,
};
},
response: {
status: 204,
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -12,11 +12,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromNone = passOnSuccess([
response: {
status: 204,
},
handler: (req: MockRequest) => {
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
{
@ -26,11 +21,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromNone = passOnSuccess([
response: {
status: 204,
},
handler: (req: MockRequest) => {
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
{
@ -61,12 +51,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromNone = passOnSuccess([
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("new-parameter", "new");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
]);
@ -83,12 +67,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneRequired = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("parameter", "required");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
{
@ -102,12 +80,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneRequired = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("parameter", "required");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
{
@ -144,13 +116,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneRequired = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("parameter", "required");
req.expect.containsQueryParam("new-parameter", "new");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
]);
@ -167,12 +132,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneOptional = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("parameter", "optional");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
{
@ -186,12 +145,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneOptional = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("parameter", "optional");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
{
@ -228,13 +181,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneOptional = passOnSucc
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("parameter", "optional");
req.expect.containsQueryParam("new-parameter", "new");
return {
status: 204,
};
},
kind: "MockApiDefinition",
},
]);
@ -246,11 +192,6 @@ Scenarios.Resiliency_ServiceDriven_breakTheGlass = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -261,10 +202,5 @@ Scenarios.Resiliency_ServiceDriven_addOperation = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -8,12 +8,6 @@ Scenarios.Serialization_EncodedName_Json_Property_send = passOnSuccess({
method: "post",
request: { body: { wireName: true } },
response: { status: 204 },
handler: (req: MockRequest) => {
req.expect.bodyEquals({ wireName: true });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Scenarios.Serialization_EncodedName_Json_Property_get = passOnSuccess({
@ -24,11 +18,5 @@ Scenarios.Serialization_EncodedName_Json_Property_get = passOnSuccess({
status: 200,
body: json({ wireName: true }),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json({ wireName: true }),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -10,8 +10,5 @@ Scenarios.Server_Endpoint_NotDefined_valid = passOnSuccess({
response: {
status: 200,
},
handler: (req: MockRequest) => {
return { status: 200 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -9,9 +9,6 @@ Scenarios.Server_Path_Multiple_noOperationParams = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -22,8 +19,5 @@ Scenarios.Server_Path_Multiple_withOperationPathParam = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
return { status: 204 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -10,8 +10,5 @@ Scenarios.Server_Path_Single_myOp = passOnSuccess({
response: {
status: 200,
},
handler: (req: MockRequest) => {
return { status: 200 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -50,9 +50,5 @@ Scenarios.Server_Versions_NotVersioned_withQueryApiVersion = passOnSuccess({
response: {
status: 200,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", "v1.0");
return { status: 200 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -33,10 +33,6 @@ function createAPIVersionTests(uri: string, requestData: any, serverData: string
response: {
status: 200,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("api-version", serverData);
return { status: 200 };
},
kind: "MockApiDefinition",
});
}

Просмотреть файл

@ -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> = {};
@ -14,12 +14,6 @@ Scenarios.SpecialHeaders_ConditionalRequest_postIfMatch = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("if-match", '"valid"');
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -34,12 +28,6 @@ Scenarios.SpecialHeaders_ConditionalRequest_postIfNoneMatch = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("if-none-match", '"invalid"');
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -54,12 +42,6 @@ Scenarios.SpecialHeaders_ConditionalRequest_headIfModifiedSince = passOnSuccess(
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("if-modified-since", "Fri, 26 Aug 2022 14:38:00 GMT");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
@ -74,11 +56,5 @@ Scenarios.SpecialHeaders_ConditionalRequest_postIfUnmodifiedSince = passOnSucces
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsHeader("if-unmodified-since", "Fri, 26 Aug 2022 14:38:00 GMT");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -13,11 +13,6 @@ function createOperationsTests(uri: string) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
}
@ -69,12 +64,6 @@ function createParametersTests(uri: string, data: any, paramName: string) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam(paramName, "ok");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
}
@ -334,12 +323,6 @@ function createModelsTests(uri: string) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ name: "ok" });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
}
@ -391,11 +374,5 @@ Scenarios.SpecialWords_ModelProperties_sameAsModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ ["SameAsModel"]: "ok" });
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -12,12 +12,6 @@ function createServerTests(uri: string, data: any) {
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(data),
};
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -29,12 +23,6 @@ function createServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals(data);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -12,12 +12,6 @@ function createServerTests(uri: string, data: any) {
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(data),
};
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -29,12 +23,6 @@ function createServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals(data);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -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> = {};
@ -13,9 +13,6 @@ function createMockServerTests(uri: string, data: any) {
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(data) };
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -30,10 +27,6 @@ function createMockServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(data);
return { status: 204 };
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, json, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -12,9 +12,6 @@ Scenarios.Type_Enum_Fixed_String_getKnownValue = passOnSuccess({
status: 200,
body: json("Monday"),
},
handler: (req: MockRequest) => {
return { status: 200, body: json("Monday") };
},
kind: "MockApiDefinition",
});
@ -30,15 +27,11 @@ Scenarios.Type_Enum_Fixed_String_putKnownValue = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("Monday");
return { status: 204 };
},
kind: "MockApiDefinition",
});
// Unknown values
Scenarios.Type_Enum_Fixed_String_putUnknownValue = passOnSuccess({
Scenarios.Type_Enum_Fixed_String_putUnknownValue = passOnCode(500, {
uri: "/type/enum/fixed/string/unknown-value",
method: "put",
request: {
@ -51,9 +44,5 @@ Scenarios.Type_Enum_Fixed_String_putUnknownValue = passOnSuccess({
response: {
status: 500,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("Weekend");
return { status: 500 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -14,10 +14,6 @@ Scenarios.Type_Model_Empty_putEmpty = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(body);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -29,9 +25,6 @@ Scenarios.Type_Model_Empty_getEmpty = passOnSuccess({
status: 200,
body: json(body),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(body) };
},
kind: "MockApiDefinition",
});
@ -45,9 +38,5 @@ Scenarios.Type_Model_Empty_postRoundTripEmpty = passOnSuccess({
status: 200,
body: json(body),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(body);
return { status: 200, body: json(body) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -20,9 +20,6 @@ function createGetServerTests(uri: string, data: any) {
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(data) };
},
kind: "MockApiDefinition",
});
}
@ -37,9 +34,6 @@ function createGetPutServerTests(uri: string, data: any) {
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(data) };
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -51,10 +45,6 @@ function createGetPutServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(data);
return { status: 204 };
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -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> = {};
@ -73,9 +73,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getModel = passOnSuccess({
status: 200,
body: json(validPolymorphicBody),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(validPolymorphicBody) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_NestedDiscriminator_putModel = passOnSuccess({
@ -87,10 +84,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_putModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(validPolymorphicBody);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -102,9 +95,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getRecursiveModel = passOnS
status: 200,
body: json(validRecursiveBody),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(validRecursiveBody) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_NestedDiscriminator_putRecursiveModel = passOnSuccess({
@ -116,10 +106,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_putRecursiveModel = passOnS
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(validRecursiveBody);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -131,9 +117,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getMissingDiscriminator = p
status: 200,
body: json({ age: 1 }),
},
handler: (req: MockRequest) => {
return { status: 200, body: json({ age: 1 }) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_NestedDiscriminator_getWrongDiscriminator = passOnSuccess({
@ -144,8 +127,5 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getWrongDiscriminator = pas
status: 200,
body: json({ age: 1, kind: "wrongKind" }),
},
handler: (req: MockRequest) => {
return { status: 200, body: json({ age: 1, kind: "wrongKind" }) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -14,10 +14,6 @@ Scenarios.Type_Model_Inheritance_NotDiscriminated_postValid = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(inheritanceValidBody);
return { status: 204 };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_NotDiscriminated_getValid = passOnSuccess({
@ -28,9 +24,6 @@ Scenarios.Type_Model_Inheritance_NotDiscriminated_getValid = passOnSuccess({
status: 200,
body: json(inheritanceValidBody),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(inheritanceValidBody) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_NotDiscriminated_putValid = passOnSuccess({
@ -43,8 +36,5 @@ Scenarios.Type_Model_Inheritance_NotDiscriminated_putValid = passOnSuccess({
status: 200,
body: json(inheritanceValidBody),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(req.body) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -28,10 +28,6 @@ Scenarios.Type_Model_Inheritance_Recursive_put = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(body);
return { status: 204 };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_Recursive_get = passOnSuccess({
@ -42,8 +38,5 @@ Scenarios.Type_Model_Inheritance_Recursive_get = passOnSuccess({
status: 200,
body: json(body),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(body) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -35,9 +35,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getModel = passOnSuccess({
status: 200,
body: json(validPolymorphicBody),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(validPolymorphicBody) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_SingleDiscriminator_putModel = passOnSuccess({
@ -49,10 +46,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_putModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(validPolymorphicBody);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -64,9 +57,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getRecursiveModel = passOnS
status: 200,
body: json(validRecursiveBody),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(validRecursiveBody) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_SingleDiscriminator_putRecursiveModel = passOnSuccess({
@ -78,10 +68,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_putRecursiveModel = passOnS
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(validRecursiveBody);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -93,9 +79,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getMissingDiscriminator = p
status: 200,
body: json({ wingspan: 1 }),
},
handler: (req: MockRequest) => {
return { status: 200, body: json({ wingspan: 1 }) };
},
kind: "MockApiDefinition",
});
@ -107,9 +90,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getWrongDiscriminator = pas
status: 200,
body: json({ wingspan: 1, kind: "wrongKind" }),
},
handler: (req: MockRequest) => {
return { status: 200, body: json({ wingspan: 1, kind: "wrongKind" }) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Inheritance_SingleDiscriminator_getLegacyModel = passOnSuccess({
@ -120,8 +100,5 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getLegacyModel = passOnSucc
status: 200,
body: json({ size: 20, kind: "t-rex" }),
},
handler: (req: MockRequest) => {
return { status: 200, body: json({ size: 20, kind: "t-rex" }) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -16,10 +16,6 @@ Scenarios.Type_Model_Usage_input = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(body);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -31,9 +27,6 @@ Scenarios.Type_Model_Usage_output = passOnSuccess({
status: 200,
body: json(body),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(body) };
},
kind: "MockApiDefinition",
});
@ -49,9 +42,5 @@ Scenarios.Type_Model_Usage_inputAndOutput = passOnSuccess({
status: 200,
body: json(body),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(body);
return { status: 200, body: json(body) };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -31,10 +31,6 @@ Scenarios.Type_Model_Visibility_putReadOnlyModel = passOnSuccess({
status: 200,
body: json(expectBody),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({});
return { status: 200, body: json(expectBody) };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Visibility_headModel = passOnSuccess({
@ -46,10 +42,6 @@ Scenarios.Type_Model_Visibility_headModel = passOnSuccess({
response: {
status: 200,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(genData(["queryProp"]));
return { status: 200 };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Visibility_getModel = passOnSuccess({
@ -62,13 +54,6 @@ Scenarios.Type_Model_Visibility_getModel = passOnSuccess({
status: 200,
body: json(genData(["readProp"])),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(genData(["queryProp"]));
return {
status: 200,
body: json(genData(["readProp"])),
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Visibility_putModel = passOnSuccess({
@ -83,10 +68,6 @@ Scenarios.Type_Model_Visibility_putModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(genData(["createProp", "updateProp"]));
return { status: 204 };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Visibility_patchModel = passOnSuccess({
@ -100,10 +81,6 @@ Scenarios.Type_Model_Visibility_patchModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(genData(["updateProp"]));
return { status: 204 };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Visibility_postModel = passOnSuccess({
@ -117,10 +94,6 @@ Scenarios.Type_Model_Visibility_postModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(genData(["createProp"]));
return { status: 204 };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Model_Visibility_deleteModel = passOnSuccess({
@ -132,9 +105,5 @@ Scenarios.Type_Model_Visibility_deleteModel = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(genData(["deleteProp"]));
return { status: 204 };
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -108,12 +108,6 @@ function createServerTests(url: string, value: any) {
status: 200,
body: json(value),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(value),
};
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -125,13 +119,6 @@ function createServerTests(url: string, value: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
const expectedBody = JSON.parse(JSON.stringify(value));
req.expect.coercedBodyEquals(expectedBody);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -12,12 +12,6 @@ function createServerTests(url: string, value: unknown, patchNullableProperty?:
status: 200,
body: json(value),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(value),
};
},
kind: "MockApiDefinition",
}),
patch: passOnSuccess({
@ -35,15 +29,6 @@ function createServerTests(url: string, value: unknown, patchNullableProperty?:
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals({
requiredProperty: "foo",
nullableProperty: patchNullableProperty || null,
});
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -12,12 +12,6 @@ function createServerTests(url: string, value: unknown) {
status: 200,
body: json(value),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(value),
};
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
@ -29,12 +23,6 @@ function createServerTests(url: string, value: unknown) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.coercedBodyEquals(value);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};

Просмотреть файл

@ -3,13 +3,6 @@ import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/
export const Scenarios: Record<string, ScenarioMockApi> = {};
function createServerTests(url: string, data: unknown, convertedToFn?: (_: any) => any) {
let property;
if (convertedToFn) {
property = convertedToFn(data);
} else {
property = data;
}
return {
get: passOnSuccess({
uri: url,
@ -19,30 +12,17 @@ function createServerTests(url: string, data: unknown, convertedToFn?: (_: any)
status: 200,
body: json(data),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(data),
};
},
kind: "MockApiDefinition",
}),
put: passOnSuccess({
uri: url,
method: `put`,
request: {
body: property,
body: data,
},
response: {
status: 204,
},
handler: (req: MockRequest) => {
const expectedBody = JSON.parse(JSON.stringify(property));
req.expect.coercedBodyEquals(expectedBody);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};
@ -148,7 +128,30 @@ const Type_Property_ValueTypes_Never = createServerTests(`/type/property/value-t
property: undefined,
});
Scenarios.Type_Property_ValueTypes_Never_get = Type_Property_ValueTypes_Never.get;
Scenarios.Type_Property_ValueTypes_Never_put = Type_Property_ValueTypes_Never.put;
Scenarios.Type_Property_ValueTypes_Never_put = passOnSuccess({
uri: `/type/property/value-types/never`,
method: `put`,
request: {
body: {
property: undefined,
},
},
response: {
status: 204,
},
handler: (req: MockRequest) => {
const expectedBody = JSON.parse(
JSON.stringify({
property: undefined,
}),
);
req.expect.coercedBodyEquals(expectedBody);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
const Type_Property_ValueTypes_Unknown_String = createServerTests(`/type/property/value-types/unknown/string`, {
property: "hello",

Просмотреть файл

@ -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> = {};
@ -11,9 +11,6 @@ Scenarios.Type_Scalar_String_get = passOnSuccess({
status: 200,
body: json("test"),
},
handler: (req: MockRequest) => {
return { status: 200, body: json("test") };
},
kind: "MockApiDefinition",
});
@ -29,10 +26,6 @@ Scenarios.Type_Scalar_String_put = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("test");
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -44,9 +37,6 @@ Scenarios.Type_Scalar_Boolean_get = passOnSuccess({
status: 200,
body: json(true),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(true) };
},
kind: "MockApiDefinition",
});
@ -62,10 +52,6 @@ Scenarios.Type_Scalar_Boolean_put = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(true);
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -77,9 +63,6 @@ Scenarios.Type_Scalar_Unknown_get = passOnSuccess({
status: 200,
body: json("test"),
},
handler: (req: MockRequest) => {
return { status: 200, body: json("test") };
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_Unknown_put = passOnSuccess({
@ -94,10 +77,6 @@ Scenarios.Type_Scalar_Unknown_put = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("test");
return { status: 204 };
},
kind: "MockApiDefinition",
});
@ -109,12 +88,6 @@ Scenarios.Type_Scalar_DecimalType_responseBody = passOnSuccess({
status: 200,
body: json(0.33333),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(0.33333),
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_Decimal128Type_responseBody = passOnSuccess({
@ -125,12 +98,6 @@ Scenarios.Type_Scalar_Decimal128Type_responseBody = passOnSuccess({
status: 200,
body: json(0.33333),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json(0.33333),
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_DecimalType_requestBody = passOnSuccess({
@ -145,12 +112,6 @@ Scenarios.Type_Scalar_DecimalType_requestBody = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(0.33333);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_Decimal128Type_requestBody = passOnSuccess({
@ -165,12 +126,6 @@ Scenarios.Type_Scalar_Decimal128Type_requestBody = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(0.33333);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_DecimalType_requestParameter = passOnSuccess({
@ -182,12 +137,6 @@ Scenarios.Type_Scalar_DecimalType_requestParameter = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("value", "0.33333");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_Decimal128Type_requestParameter = passOnSuccess({
@ -199,12 +148,6 @@ Scenarios.Type_Scalar_Decimal128Type_requestParameter = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.containsQueryParam("value", "0.33333");
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_DecimalVerify_prepareVerify = passOnSuccess({
@ -215,12 +158,6 @@ Scenarios.Type_Scalar_DecimalVerify_prepareVerify = passOnSuccess({
status: 200,
body: json([0.1, 0.1, 0.1]),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json([0.1, 0.1, 0.1]),
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_Decimal128Verify_prepareVerify = passOnSuccess({
@ -231,12 +168,6 @@ Scenarios.Type_Scalar_Decimal128Verify_prepareVerify = passOnSuccess({
status: 200,
body: json([0.1, 0.1, 0.1]),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json([0.1, 0.1, 0.1]),
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_DecimalVerify_verify = passOnSuccess({
@ -251,12 +182,6 @@ Scenarios.Type_Scalar_DecimalVerify_verify = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(0.3);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});
Scenarios.Type_Scalar_Decimal128Verify_verify = passOnSuccess({
@ -271,11 +196,5 @@ Scenarios.Type_Scalar_Decimal128Verify_verify = passOnSuccess({
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals(0.3);
return {
status: 204,
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -12,9 +12,6 @@ function createGetServerTests(url: string, value: unknown) {
status: 200,
body: json({ prop: value }),
},
handler: (req: MockRequest) => {
return { status: 200, body: json({ prop: value }) };
},
kind: "MockApiDefinition",
});
}
@ -31,10 +28,6 @@ function createPostServerTests(url: string, value: unknown) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: value });
return { status: 204 };
},
kind: "MockApiDefinition",
});
}

Просмотреть файл

@ -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> = {};
@ -20,14 +20,6 @@ Scenarios.Versioning_Added_v1 = passOnSuccess({
status: 200,
body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: 10 }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: "foo", enumProp: "enumMemberV2", unionProp: 10 });
req.expect.containsHeader("header-v2", "bar");
return {
status: 200,
body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: 10 }),
};
},
kind: "MockApiDefinition",
});
@ -45,13 +37,6 @@ Scenarios.Versioning_Added_v2 = passOnSuccess({
status: 200,
body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: "foo", enumProp: "enumMember", unionProp: "bar" });
return {
status: 200,
body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }),
};
},
kind: "MockApiDefinition",
});
@ -69,12 +54,5 @@ Scenarios.Versioning_Added_InterfaceV2 = passOnSuccess({
status: 200,
body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: "foo", enumProp: "enumMember", unionProp: "bar" });
return {
status: 200,
body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -15,12 +15,5 @@ Scenarios.Versioning_MadeOptional_test = passOnSuccess({
status: 200,
body: json({ prop: "foo" }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: "foo" });
return {
status: 200,
body: json({ prop: "foo" }),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -17,12 +17,5 @@ Scenarios.Versioning_Removed_v2 = passOnSuccess({
status: 200,
body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" });
return {
status: 200,
body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" }),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -20,14 +20,6 @@ Scenarios.Versioning_RenamedFrom_newOp = passOnSuccess({
status: 200,
body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 });
req.expect.containsQueryParam("newQuery", "bar");
return {
status: 200,
body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }),
};
},
kind: "MockApiDefinition",
});
@ -45,12 +37,5 @@ Scenarios.Versioning_RenamedFrom_NewInterface = passOnSuccess({
status: 200,
body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 });
return {
status: 200,
body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -16,12 +16,5 @@ Scenarios.Versioning_ReturnTypeChangedFrom_test = passOnSuccess({
status: 200,
body: json("test"),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals("test");
return {
status: 200,
body: json("test"),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -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> = {};
@ -19,13 +19,5 @@ Scenarios.Versioning_TypeChangedFrom_test = passOnSuccess({
status: 200,
body: json({ prop: "foo", changedProp: "bar" }),
},
handler: (req: MockRequest) => {
req.expect.bodyEquals({ prop: "foo", changedProp: "bar" });
req.expect.containsQueryParam("param", "baz");
return {
status: 200,
body: json({ prop: "foo", changedProp: "bar" }),
};
},
kind: "MockApiDefinition",
});

Просмотреть файл

@ -1,4 +1,4 @@
import { RequestExt, ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { MockApiDefinition, MockRequest, RequestExt, ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { Response, Router } from "express";
import { getScenarioMetadata } from "../coverage/common.js";
import { CoverageTracker } from "../coverage/coverage-tracker.js";
@ -46,7 +46,7 @@ export class MockApiApp {
});
} else {
if (!endpoint.handler) {
continue;
endpoint.handler = createHandler(endpoint);
}
this.router.route(endpoint.uri)[endpoint.method]((req: RequestExt, res: Response) => {
processRequest(this.coverageTracker, name, endpoint.uri, req, res, endpoint.handler!).catch((e) => {
@ -58,3 +58,67 @@ export class MockApiApp {
}
}
}
function isObject(value: any): boolean {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function createHandler(apiDefinition: MockApiDefinition) {
return (req: MockRequest) => {
// Validate body if present in the request
if (apiDefinition.request.body) {
if (apiDefinition.request.headers && apiDefinition.request.headers["Content-Type"] === "application/xml") {
req.expect.xmlBodyEquals(
apiDefinition.request.body.rawContent.replace(`<?xml version='1.0' encoding='UTF-8'?>`, ""),
);
} else {
if (isObject(apiDefinition.request.body)) {
Object.entries(apiDefinition.request.body).forEach(([key, value]) => {
req.expect.deepEqual(req.body[key], value);
});
} else {
req.expect.coercedBodyEquals(apiDefinition.request.body);
}
}
}
// Validate headers if present in the request
if (apiDefinition.request.headers) {
Object.entries(apiDefinition.request.headers).forEach(([key, value]) => {
if (key.toLowerCase() !== "content-type") {
if (Array.isArray(value)) {
req.expect.deepEqual(req.headers[key], value);
} else {
req.expect.containsHeader(key.toLowerCase(), String(value));
}
}
});
}
// Validate query params if present in the request
if (apiDefinition.request.params) {
Object.entries(apiDefinition.request.params).forEach(([key, value]) => {
if (!req.query[key]) {
if (Array.isArray(value)) {
req.expect.deepEqual(req.params[key], value);
} else {
req.expect.deepEqual(req.params[key], String(value));
}
} else {
if (Array.isArray(value)) {
req.expect.deepEqual(req.query[key], value);
} else {
req.expect.containsQueryParam(key, String(value));
}
}
});
}
// Validations are done. Now return the response
return {
status: apiDefinition.response.status,
body: apiDefinition.response.body,
headers: apiDefinition.response.headers,
};
};
}