Skip to content

Commit

Permalink
[DOCS-3274] Fix race condition in pagination tests (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodewig authored Aug 20, 2024
1 parent 4e39ca6 commit 9e44a84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions __tests__/orders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,24 @@ describe("Orders", () => {
);
expect(firstResp.status).toEqual(200);
expect(firstResp.body.results.length).toEqual(1);
expect(firstResp.body.nextToken).toBeDefined();

// Get the second page of orders
const secondResp = await req(app).get(
`/customers/${customer.id}/orders?nextToken=${firstResp.body.nextToken}`
);
expect(secondResp.status).toEqual(200);
expect(secondResp.body.results.length).toEqual(1);

// Ensure the orders returned are different.
expect(firstResp.body.results[0].createdAt).not.toEqual(
secondResp.body.results[0].createdAt
);

// Verify that the second page's nextToken is defined.
if (secondResp.body.nextToken) {
expect(secondResp.body.nextToken).toBeDefined();
}
});

it("returns a 400 if 'pageSize' is invalid", async () => {
Expand Down
13 changes: 10 additions & 3 deletions __tests__/products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ describe("Products", () => {
});

it("can paginate the list of products", async () => {
// Get the first page of orders.
// Get the first page of products.
const firstResp = await req(app).get("/products?pageSize=1");
expect(firstResp.status).toEqual(200);
expect(firstResp.body.results.length).toEqual(1);
// Get the second page of orders
expect(firstResp.body.nextToken).toBeDefined();

// Get the second page of products
const secondResp = await req(app).get(
`/products?nextToken=${firstResp.body.nextToken}`
);
expect(secondResp.status).toEqual(200);
expect(secondResp.body.results.length).toEqual(1);
// Ensure the orders returned are different.
// Ensure the products returned are different.
expect(firstResp.body.results[0].name).not.toEqual(
secondResp.body.results[0].name
);

// Verify that the second page's nextToken is defined.
if (secondResp.body.nextToken) {
expect(secondResp.body.nextToken).toBeDefined();
}
});

it("returns a 400 if 'pageSize' is invalid", async () => {
Expand Down

0 comments on commit 9e44a84

Please sign in to comment.