From e1b851f932443cd2e8bd8a40d48aefbd688bf812 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Mon, 31 Oct 2016 12:41:34 -0700 Subject: [PATCH] Test: add a second mock team So that we can test complex sorts --- src/crud-list-order.integration.test.js | 22 ++++++++++++++-------- test/integration-setup.js | 8 +++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/crud-list-order.integration.test.js b/src/crud-list-order.integration.test.js index daba5dc..4899382 100644 --- a/src/crud-list-order.integration.test.js +++ b/src/crud-list-order.integration.test.js @@ -9,7 +9,7 @@ setup(test); test('/players?order=name', async (t) => { const { server, instances } = t.context; - const { player1, player2 } = instances; + const { player1, player2, player3 } = instances; const url = '/players?order=name'; const method = 'GET'; @@ -18,11 +18,12 @@ test('/players?order=name', async (t) => { // this is the order we'd expect the names to be in t.is(result[0].name, player1.name); t.is(result[1].name, player2.name); + t.is(result[2].name, player3.name); }); test('/players?order=name%20ASC', async (t) => { const { server, instances } = t.context; - const { player1, player2 } = instances; + const { player1, player2, player3 } = instances; const url = '/players?order=name%20ASC'; const method = 'GET'; @@ -31,24 +32,26 @@ test('/players?order=name%20ASC', async (t) => { // this is the order we'd expect the names to be in t.is(result[0].name, player1.name); t.is(result[1].name, player2.name); + t.is(result[2].name, player3.name); }); test('/players?order=name%20DESC', async (t) => { const { server, instances } = t.context; - const { player1, player2 } = instances; + const { player1, player2, player3 } = instances; const url = '/players?order=name%20DESC'; const method = 'GET'; const { result, statusCode } = await server.inject({ url, method }); t.is(statusCode, STATUS_OK); // this is the order we'd expect the names to be in - t.is(result[0].name, player2.name); - t.is(result[1].name, player1.name); + t.is(result[0].name, player3.name); + t.is(result[1].name, player2.name); + t.is(result[2].name, player1.name); }); test('/players?order[]=name', async (t) => { const { server, instances } = t.context; - const { player1, player2 } = instances; + const { player1, player2, player3 } = instances; const url = '/players?order[]=name'; const method = 'GET'; @@ -57,18 +60,21 @@ test('/players?order[]=name', async (t) => { // this is the order we'd expect the names to be in t.is(result[0].name, player1.name); t.is(result[1].name, player2.name); + t.is(result[2].name, player3.name); }); test('/players?order[0]=name&order[0]=DESC', async (t) => { const { server, instances } = t.context; - const { player1, player2 } = instances; + const { player1, player2, player3 } = instances; const url = '/players?order[0]=name&order[0]=DESC'; const method = 'GET'; const { result, statusCode } = await server.inject({ url, method }); t.is(statusCode, STATUS_OK); // this is the order we'd expect the names to be in - t.is(result[0].name, player2.name); + t.is(result[0].name, player3.name); + t.is(result[1].name, player2.name); + t.is(result[2].name, player1.name); t.is(result[1].name, player1.name); }); diff --git a/test/integration-setup.js b/test/integration-setup.js index c895343..190f958 100644 --- a/test/integration-setup.js +++ b/test/integration-setup.js @@ -58,11 +58,13 @@ export default (test) => { const { Player, Team, City } = t.context.sequelize.models; const city1 = await City.create({ name: 'Healdsburg' }); const team1 = await Team.create({ name: 'Baseballs', cityId: city1.id }); + const team2 = await Team.create({ name: 'Footballs', cityId: city1.id }); const player1 = await Player.create({ - name: 'Pinot', teamId: team1.id, active: true, + name: 'Cat', teamId: team1.id, active: true, }); - const player2 = await Player.create({ name: 'Syrah', teamId: team1.id }); - t.context.instances = { city1, team1, player1, player2 }; + const player2 = await Player.create({ name: 'Pinot', teamId: team1.id }); + const player3 = await Player.create({ name: 'Syrah', teamId: team2.id }); + t.context.instances = { city1, team1, team2, player1, player2, player3 }; }); // kill the server so that we can exit and don't leak memory