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

[Spector] update cases for continuation token paging #6140

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

all parameters including headers and queries shall be passed when next call for continuation token paging
1 change: 1 addition & 0 deletions packages/http-specs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"clean": "rimraf dist/ temp/",
"test:e2e": "pnpm validate-scenarios && pnpm validate-mock-apis && pnpm validate-client-server",
"validate:all": "pnpm build && pnpm regen-docs && pnpm test:e2e",
"ci": "prettier specs --write && pnpm validate:all",
"validate-scenarios": "tsp-spector validate-scenarios ./specs",
"generate-scenarios-summary": "tsp-spector generate-scenarios-summary ./specs",
"regen-docs": "pnpm generate-scenarios-summary",
Expand Down
50 changes: 37 additions & 13 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,10 @@ Test case for using continuation token as pagination. Continuation token is pass
Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar

Expected request header:
foo=foo

Expected response body:

Expand All @@ -1685,10 +1688,11 @@ Expected response body:
```

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar

Expected header:
Expected request header:
token=page2
foo=foo

Expected response body:

Expand All @@ -1710,8 +1714,12 @@ Test case for using continuation token as pagination. Continuation token is pass
Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
Expected response body:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar

Expected request header:
foo=foo

Expected response body:

```json
{
Expand All @@ -1726,10 +1734,11 @@ Expected response header:
next-token=page2

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar

Expected request header:
token=page2
foo=foo

Expected response body:

Expand All @@ -1751,8 +1760,12 @@ Test case for using continuation token as pagination. Continuation token is pass
Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body
Expected response body:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar

Expected request header:
foo=foo

Expected response body:

```json
{
Expand All @@ -1765,7 +1778,10 @@ Two requests need to be tested.
```

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?token=page2
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar&token=page2

Expected request header:
foo=foo

Expected response body:

Expand All @@ -1787,8 +1803,12 @@ Test case for using continuation token as pagination. Continuation token is pass
Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header
Expected response body:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar

Expected request header:
foo=foo

Expected response body:

```json
{
Expand All @@ -1803,8 +1823,12 @@ Expected response header:
next-token=page2

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?token=page2
Expected response body:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar&token=page2

Expected request header:
foo=foo

Expected response body:

```json
{
Expand Down
59 changes: 46 additions & 13 deletions packages/http-specs/specs/payload/pageable/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ model Pet {
name: string;
}

alias HeaderAndQuery = {
@header foo?: string;
@query bar?: string;
};

@route("/server-driven-pagination")
namespace ServerDrivenPagination {
@scenario
Expand Down Expand Up @@ -60,8 +65,13 @@ namespace ServerDrivenPagination {
Test case for using continuation token as pagination. Continuation token is passed in the request query and response body.

Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar

Expected request header:
foo=foo

Expected response body:
```json
{ "pets": [
Expand All @@ -73,7 +83,10 @@ namespace ServerDrivenPagination {
```

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?token=page2
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-body?bar=bar&token=page2

Expected request header:
foo=foo

Expected response body:
```json
Expand All @@ -86,7 +99,7 @@ namespace ServerDrivenPagination {
""")
@route("/request-query-response-body")
@list
op requestQueryResponseBody(@continuationToken @query token?: string): {
op requestQueryResponseBody(@continuationToken @query token?: string, ...HeaderAndQuery): {
@pageItems
pets: Pet[];

Expand All @@ -98,8 +111,12 @@ namespace ServerDrivenPagination {
Test case for using continuation token as pagination. Continuation token is passed in the request header and response body.

Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar

Expected request header:
foo=foo

Expected response body:
```json
Expand All @@ -110,11 +127,13 @@ namespace ServerDrivenPagination {
"nextToken": "page2"
}
```

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-body?bar=bar

Expected header:
Expected request header:
token=page2
foo=foo

Expected response body:
```json
Expand All @@ -127,7 +146,7 @@ namespace ServerDrivenPagination {
""")
@route("/request-header-response-body")
@list
op requestHeaderResponseBody(@continuationToken @header token?: string): {
op requestHeaderResponseBody(@continuationToken @header token?: string, ...HeaderAndQuery): {
@pageItems
pets: Pet[];

Expand All @@ -139,8 +158,13 @@ namespace ServerDrivenPagination {
Test case for using continuation token as pagination. Continuation token is passed in the request query and response header.

Two requests need to be tested.

1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar

Expected request header:
foo=foo

Expected response body:
```json
{ "pets": [
Expand All @@ -154,7 +178,11 @@ namespace ServerDrivenPagination {
next-token=page2

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?token=page2
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-query-response-header?bar=bar&token=page2

Expected request header:
foo=foo

Expected response body:
```json
{ "pets": [
Expand All @@ -166,7 +194,7 @@ namespace ServerDrivenPagination {
""")
@route("/request-query-response-header")
@list
op requestQueryResponseHeader(@continuationToken @query token?: string): {
op requestQueryResponseHeader(@continuationToken @query token?: string, ...HeaderAndQuery): {
@pageItems
pets: Pet[];

Expand All @@ -179,7 +207,11 @@ namespace ServerDrivenPagination {

Two requests need to be tested.
1. Initial request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar

Expected request header:
foo=foo

Expected response body:
```json
{ "pets": [
Expand All @@ -193,10 +225,11 @@ namespace ServerDrivenPagination {
next-token=page2

2. Next page request:
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header
Expected route: /payload/pageable/server-driven-pagination/continuationtoken/request-header-response-header?bar=bar

Expected request header:
token=page2
foo=foo

Expected response body:
```json
Expand All @@ -209,7 +242,7 @@ namespace ServerDrivenPagination {
""")
@route("/request-header-response-header")
@list
op requestHeaderResponseHeader(@continuationToken @header token?: string): {
op requestHeaderResponseHeader(@continuationToken @header token?: string, ...HeaderAndQuery): {
@pageItems
pets: Pet[];

Expand Down
10 changes: 7 additions & 3 deletions packages/http-specs/specs/payload/pageable/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ const FirstResponseTokenInHeader = {
}),
headers: {
"next-token": "page2",
foo: "foo",
},
};

const RequestTokenInQuery = {
params: { token: "page2" },
params: { token: "page2", bar: "bar" },
headers: { foo: "foo" },
};

const RequestTokenInHeader = { headers: { token: "page2" } };
const RequestTokenInHeader = { headers: { token: "page2", foo: "foo" }, params: { bar: "bar" } };

function createTests(reqInfo: "query" | "header", resInfo: "body" | "header") {
const uri = `/payload/pageable/server-driven-pagination/continuationtoken/request-${reqInfo}-response-${resInfo}`;
function createHandler() {
return (req: MockRequest) => {
req.expect.containsHeader("foo", "foo");
req.expect.containsQueryParam("bar", "bar");
const token = reqInfo === "header" ? req.headers?.token : req.query?.token;
switch (token) {
case undefined:
Expand All @@ -73,7 +77,7 @@ function createTests(reqInfo: "query" | "header", resInfo: "body" | "header") {
{
uri: uri,
method: "get",
request: {},
request: { headers: { foo: "foo" }, params: { bar: "bar" } },
response: resInfo === "header" ? FirstResponseTokenInHeader : FirstResponseTokenInBody,
handler: createHandler(),
kind: "MockApiDefinition",
Expand Down
Loading