Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[http-spec] add link case of server driven pagination test #5211

Merged
merged 8 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/list_operation_test-2024-10-27-18-41-40.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

add link case of server driven pagination test
60 changes: 60 additions & 0 deletions packages/http-specs/specs/operations/list/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import "@typespec/http";
import "@typespec/spector";

using Http;
using Spector;

/**
* Test for list operations.
*/
@scenarioService("/operations/list")
namespace Operations.List;

model Pet {
id: string;
name: string;
}

@route("/server-driven-pagination")
namespace ServerDrivenPagination {
@scenario
@scenarioDoc("""
Test case for using link as pagination.

Two requests need to be tested.
1. Initial request:
Expected route: /operations/list/server-driven-pagination/link
Expected response body:
```json
{ "pets": [
{ "id": "1", "name": "dog" },
{ "id": "2", "name": "cat" }
],
"links": {
"next": "/operations/list/server-driven-pagination/link/nextPage"
}
}
2. Next page request:
Expected route: /operations/list/server-driven-pagination/link/nextPage
Expected response body:
```json
{ "pets": [
{ "id": "3", "name": "bird" },
{ "id": "4", "name": "fish" }
]
}
```
""")
@route("/link")
op link(): {
@pageItems
pets: Pet[];

links: {
@nextLink next?: url;
@prevLink prev?: url;
@firstLink first?: url;
@lastLink last?: url;
};
};
}
39 changes: 39 additions & 0 deletions packages/http-specs/specs/operations/list/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

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

Scenarios.Operations_List_ServerDrivenPagination_link = passOnSuccess([
{
uri: "/operations/list/server-driven-pagination/link",
method: "get",
request: {},
response: {
status: 200,
body: json({
pets: [
{ id: "1", name: "dog" },
{ id: "2", name: "cat" },
],
links: {
next: "/operations/list/server-driven-pagination/link/nextPage",
},
}),
},
kind: "MockApiDefinition",
},
{
uri: "/operations/list/server-driven-pagination/link/nextPage",
method: "get",
request: {},
response: {
status: 200,
body: json({
pets: [
{ id: "3", name: "bird" },
{ id: "4", name: "fish" },
],
}),
},
kind: "MockApiDefinition",
},
]);
Loading