Skip to content

Commit

Permalink
[http-spec] add link case of server driven pagination test (#5211)
Browse files Browse the repository at this point in the history
only cover next link scenario for pagination. more complex case could be
added later.
  • Loading branch information
tadelesh authored Nov 28, 2024
1 parent a939c14 commit b6dcb04
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
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: "/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",
},
]);

0 comments on commit b6dcb04

Please sign in to comment.