Add Custom Operation Test in azure/core/basic (#625)

This commit is contained in:
mcgallan 2024-08-16 15:13:18 +08:00 коммит произвёл GitHub
Родитель 5fe6e2b1b9
Коммит e9cf998128
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 88 добавлений и 1 удалений

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

@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---
Add ResourceCollectionAction operation and mockapi in azure/core/basic.

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

@ -285,6 +285,34 @@ Expected response body:
}
```
### Azure_Core_Basic_exportAllUsers
- Endpoint: `post /azure/core/basic`
Should generate a model named User.
Expected query parameter: format=json
Expected query parameter: api-version=2022-12-01-preview
Expected response body:
```json
{
"users": [
{
"id": 1,
"name": "Madge",
"etag": "11bdc430-65e8-45ad-81d9-8ffa60d55b59"
},
{
"id": 2,
"name": "John",
"etag": "22bdc430-65e8-45ad-81d9-8ffa60d55b59"
}
]
}
```
### Azure_Core_Basic_get
- Endpoint: `get /azure/core/basic`

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

@ -1,11 +1,13 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/cadl-ranch-expect";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-client-generator-core";
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
using Azure.Core;
using global.Azure.Core.Traits;
using global.Azure.Core.Foundations;
using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
@ -214,3 +216,45 @@ op delete is ResourceOperations.ResourceDelete<User>;
```
""")
op export is ResourceOperations.ResourceAction<User, UserExportParams, User>;
model UserList {
users: User[];
}
@scenario
@doc("Exports all users")
@summary("Exports all users.")
@scenarioDoc("""
Should generate a model named User.
Expected query parameter: format=json
Expected query parameter: api-version=2022-12-01-preview
Expected response body:
```json
{
"users":[
{
"id": 1,
"name": "Madge",
"etag": "11bdc430-65e8-45ad-81d9-8ffa60d55b59"
},
{
"id": 2,
"name": "John",
"etag": "22bdc430-65e8-45ad-81d9-8ffa60d55b59"
}
]
}
```
""")
@collectionAction(User, "exportallusers")
@post
op exportAllUsers is ResourceOperations.ResourceCollectionAction<
User,
UserExportParams,
UserList,
{
apiVersion: "2022-12-01-preview";
}
>;

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

@ -3,6 +3,7 @@ import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
const validUser = { id: 1, name: "Madge", etag: "11bdc430-65e8-45ad-81d9-8ffa60d55b59" };
const validUser2 = { id: 2, name: "John", etag: "22bdc430-65e8-45ad-81d9-8ffa60d55b59" };
Scenarios.Azure_Core_Basic_createOrUpdate = passOnSuccess(
mockapi.patch("/azure/core/basic/users/:id", (req) => {
if (req.params.id !== "1") {
@ -94,3 +95,12 @@ Scenarios.Azure_Core_Basic_export = passOnSuccess(
return { status: 200, body: json(validUser) };
}),
);
const expectBody = { users: [validUser, validUser2] };
Scenarios.Azure_Core_Basic_exportAllUsers = passOnSuccess(
mockapi.post("/azure/core/basic/users:exportallusers", (req) => {
req.expect.containsQueryParam("api-version", "2022-12-01-preview");
req.expect.containsQueryParam("format", "json");
return { status: 200, body: json(expectBody) };
}),
);