From 25501bbb104cb0c6cf871fa391abd2384df5584f Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Tue, 1 Nov 2016 17:39:35 -0700 Subject: [PATCH] Test add integration tests for limit/offset #28 --- ...-list-limit-and-offset.integration.test.js | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/crud-list-limit-and-offset.integration.test.js diff --git a/src/crud-list-limit-and-offset.integration.test.js b/src/crud-list-limit-and-offset.integration.test.js new file mode 100644 index 0000000..1af3549 --- /dev/null +++ b/src/crud-list-limit-and-offset.integration.test.js @@ -0,0 +1,94 @@ +import test from 'ava'; +import 'sinon-bluebird'; +import setup from '../test/integration-setup.js'; + +const STATUS_OK = 200; +const STATUS_NOT_FOUND = 404; + +setup(test); + +test('/players?limit=2', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players?limit=${limit}`; + const method = 'GET'; + + const { result, statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_OK); + t.is(result.length, limit); +}); + +test('/players?limit=2&offset=1', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players?limit=${limit}&offset=1`; + const method = 'GET'; + + const { result, statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_OK); + t.is(result.length, limit); +}); + +test('/players?limit=2&offset=2', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players?limit=${limit}&offset=2`; + const method = 'GET'; + + const { result, statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_OK); + t.is(result.length, 1, 'with only 3 players, only get 1 back with an offset of 2'); +}); + +test('/players?limit=2&offset=20', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players?limit=${limit}&offset=20`; + const method = 'GET'; + + const { statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_NOT_FOUND, 'with a offset/limit greater than the data, returns a 404'); +}); + +test('scope /players/returnsAll?limit=2', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players/returnsAll?limit=${limit}`; + const method = 'GET'; + + const { result, statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_OK); + t.is(result.length, limit); +}); + +test('scope /players/returnsAll?limit=2&offset=1', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players/returnsAll?limit=${limit}&offset=1`; + const method = 'GET'; + + const { result, statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_OK); + t.is(result.length, limit); +}); + +test('scope /players/returnsAll?limit=2&offset=2', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players/returnsAll?limit=${limit}&offset=2`; + const method = 'GET'; + + const { result, statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_OK); + t.is(result.length, 1, 'with only 3 players, only get 1 back with an offset of 2'); +}); + +test('scope /players/returnsAll?limit=2&offset=20', async (t) => { + const { server } = t.context; + const limit = 2; + const url = `/players/returnsAll?limit=${limit}&offset=20`; + const method = 'GET'; + + const { statusCode } = await server.inject({ url, method }); + t.is(statusCode, STATUS_NOT_FOUND, 'with a offset/limit greater than the data, returns a 404'); +});