diff --git a/Count.http b/Count.http new file mode 100644 index 0000000..412bcaf --- /dev/null +++ b/Count.http @@ -0,0 +1,24 @@ +# @import ./PreScript.http +### +GET /products +Prefer: count=exact +?? status == 200 +{{ + const { expect } = require('chai'); + let responseItems = JSON. parse(response.body); + let itemsCount = responseItems.length; + test('OK content-range', () => { + expect(response.headers['content-range']).to.equal(`0-${itemsCount - 1}/${itemsCount}`); + }); +}} + +GET /products +?? status == 200 +{{ + const { expect } = require('chai'); + let responseItems = JSON. parse(response.body); + let itemsCount = responseItems.length; + test('OK content-range', () => { + expect(response.headers['content-range']).to.equal(`0-${itemsCount - 1}/*`); + }); +}} \ No newline at end of file diff --git a/Pagination.http b/Pagination.http new file mode 100644 index 0000000..1007ba1 --- /dev/null +++ b/Pagination.http @@ -0,0 +1,31 @@ +# @import ./PreScript.http +### +GET /products?limit=20 +?? status == 200 +{{ + const { expect } = require('chai'); + let responseItems = JSON. parse(response.body); + let itemsCount = responseItems.length; + test('OK content-range', () => { + expect(response.headers['content-range']).to.equal(`0-${itemsCount - 1}/*`); + }); +}} + +GET /products?limit=40&offset=7 +?? status == 200 +{{ + const { expect } = require('chai'); + test('OK content-range', () => { + expect(response.headers['content-range']).to.equal('7-46/*'); + }); +}} + +GET /products?limit=20&offset=40 +Prefer: count=exact +?? status == 206 +{{ + const { expect } = require('chai'); + test('OK content-range', () => { + expect(response.headers['content-range']).to.equal('40-59/77'); + }); +}}