Test: add a second mock team

So that we can test complex sorts
This commit is contained in:
Joey Baker 2016-10-31 12:41:34 -07:00
parent 34e37217f1
commit e1b851f932
2 changed files with 19 additions and 11 deletions

View File

@ -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);
});

View File

@ -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