Skip to content

Commit 60551d7

Browse files
Merge pull request #29 from piyush-jaiswal/feature/tests/improve-pagination-tests
add next prev pagination tests
2 parents efce7fc + 10ed26a commit 60551d7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/test_product.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def test_products_pagination(self, create_product):
220220
data1 = resp1.get_json()
221221
assert "products" in data1
222222
assert len(data1["products"]) == 10
223+
assert data1["cursor"]["prev"] is None
224+
assert isinstance(data1["cursor"]["next"], str)
223225

224226
# Page 2
225227
next_cursor = data1["cursor"]["next"]
@@ -228,3 +230,5 @@ def test_products_pagination(self, create_product):
228230
data2 = resp2.get_json()
229231
assert "products" in data2
230232
assert len(data2["products"]) == 5
233+
assert data2["cursor"]["next"] is None
234+
assert isinstance(data2["cursor"]["prev"], str)

tests/test_relationships.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,13 @@ def test_get_category_products_populated_with_pagination(self, create_category,
219219
product_ids.add(product_resp.get_json().get("id"))
220220

221221
page1 = self.client.get(f"/categories/{category['id']}/products").get_json()
222+
assert page1["cursor"]["prev"] is None
223+
assert type(page1["cursor"]["next"]) is str
224+
222225
next_cursor = page1["cursor"]["next"]
223226
page2 = self.client.get(f"/categories/{category['id']}/products?cursor={next_cursor}").get_json()
227+
assert page2["cursor"]["next"] is None
228+
assert isinstance(page2["cursor"]["prev"], str)
224229
assert len(page1["products"]) == 10
225230
assert len(page2["products"]) == 2
226231

@@ -254,8 +259,13 @@ def test_get_subcategory_products_populated_with_pagination(self, create_subcate
254259
product_ids.add(product_resp.get_json().get("id"))
255260

256261
page1 = self.client.get(f"/subcategories/{subcategory['id']}/products").get_json()
262+
assert page1["cursor"]["prev"] is None
263+
assert type(page1["cursor"]["next"]) is str
264+
257265
next_cursor = page1["cursor"]["next"]
258266
page2 = self.client.get(f"/subcategories/{subcategory['id']}/products?cursor={next_cursor}").get_json()
267+
assert page2["cursor"]["next"] is None
268+
assert isinstance(page2["cursor"]["prev"], str)
259269
assert len(page1["products"]) == 10
260270
assert len(page2["products"]) == 1
261271

0 commit comments

Comments
 (0)