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 7 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
37 changes: 37 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,43 @@ Content-Type: application/octet-stream
--abcde12345--
```

### Payload_Pageable_ServerDrivenPagination_link

- Endpoint: `get /payload/pageable/server-driven-pagination/link`

Test case for using link as pagination.

Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/link
Expected response body:

```json
{
"pets": [
{ "id": "1", "name": "dog" },
{ "id": "2", "name": "cat" }
],
"links": {
"next": "http://[host]:[port]/payload/pageable/server-driven-pagination/link/nextPage"
}
}
```

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/link/nextPage
Expected response body:

```json
{
"pets": [
{ "id": "3", "name": "bird" },
{ "id": "4", "name": "fish" }
]
}
```

### Payload_Xml_ModelWithArrayOfModelValue_get

- Endpoint: `get /payload/xml/modelWithArrayOfModel`
Expand Down
61 changes: 61 additions & 0 deletions packages/http-specs/specs/payload/pageable/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import "@typespec/http";
import "@typespec/spector";

using Http;
using Spector;

/**
* Test for pageable payload.
*/
@scenarioService("/payload/pageable")
namespace Payload.Pageable;

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: /payload/pageable/server-driven-pagination/link
Expected response body:
```json
{ "pets": [
{ "id": "1", "name": "dog" },
{ "id": "2", "name": "cat" }
],
"links": {
"next": "http://[host]:[port]/payload/pageable/server-driven-pagination/link/nextPage"
}
}
```
2. Next page request:
Expected route: /payload/pageable/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;
};
};
}
53 changes: 53 additions & 0 deletions packages/http-specs/specs/payload/pageable/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

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

Scenarios.Payload_Pageable_ServerDrivenPagination_link = passOnSuccess([
{
uri: "/payload/pageable/server-driven-pagination/link",
method: "get",
request: {},
response: {
status: 200,
body: json({
pets: [
{ id: "1", name: "dog" },
{ id: "2", name: "cat" },
],
links: {
next: "http://[host]:[port]/payload/pageable/server-driven-pagination/link/nextPage",
},
}),
},
handler: (req: MockRequest) => {
return {
status: 200,
body: json({
pets: [
{ id: "1", name: "dog" },
{ id: "2", name: "cat" },
],
links: {
next: `${req.baseUrl}/payload/pageable/server-driven-pagination/link/nextPage`,
},
}),
};
},
kind: "MockApiDefinition",
},
{
uri: "/payload/pageable/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