Feat ordering by associated models now works #32
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user