Add integration tests #30

Merged
joeybaker merged 3 commits from code-coverage into master 2016-10-27 20:20:18 +00:00
Showing only changes of commit f49e4daf79 - Show all commits

View File

@ -2,6 +2,8 @@ import test from 'ava';
import 'sinon-bluebird'; import 'sinon-bluebird';
import setup from '../test/integration-setup.js'; import setup from '../test/integration-setup.js';
const STATUS_OK = 200;
setup(test); setup(test);
test('belongsTo /team?include=city', async (t) => { test('belongsTo /team?include=city', async (t) => {
@ -9,8 +11,8 @@ test('belongsTo /team?include=city', async (t) => {
const { team1, city1 } = instances; const { team1, city1 } = instances;
const path = `/team/${team1.id}?include=city`; const path = `/team/${team1.id}?include=city`;
const { result, response } = await server.inject(path); const { result, statusCode } = await server.inject(path);
t.falsy(response instanceof Error); t.is(statusCode, STATUS_OK);
t.is(result.id, team1.id); t.is(result.id, team1.id);
t.is(result.City.id, city1.id); t.is(result.City.id, city1.id);
}); });
@ -20,8 +22,8 @@ test('belongsTo /team?include=cities', async (t) => {
const { team1, city1 } = instances; const { team1, city1 } = instances;
const path = `/team/${team1.id}?include=cities`; const path = `/team/${team1.id}?include=cities`;
const { result, response } = await server.inject(path); const { result, statusCode } = await server.inject(path);
t.falsy(response instanceof Error); t.is(statusCode, STATUS_OK);
t.is(result.id, team1.id); t.is(result.id, team1.id);
t.is(result.City.id, city1.id); t.is(result.City.id, city1.id);
}); });
@ -31,8 +33,8 @@ test('hasMany /team?include=player', async (t) => {
const { team1, player1, player2 } = instances; const { team1, player1, player2 } = instances;
const path = `/team/${team1.id}?include=player`; const path = `/team/${team1.id}?include=player`;
const { result, response } = await server.inject(path); const { result, statusCode } = await server.inject(path);
t.falsy(response instanceof Error); t.is(statusCode, STATUS_OK);
t.is(result.id, team1.id); t.is(result.id, team1.id);
const playerIds = result.Players.map(({ id }) => id); const playerIds = result.Players.map(({ id }) => id);
@ -45,8 +47,8 @@ test('hasMany /team?include=players', async (t) => {
const { team1, player1, player2 } = instances; const { team1, player1, player2 } = instances;
const path = `/team/${team1.id}?include=players`; const path = `/team/${team1.id}?include=players`;
const { result, response } = await server.inject(path); const { result, statusCode } = await server.inject(path);
t.falsy(response instanceof Error); t.is(statusCode, STATUS_OK);
t.is(result.id, team1.id); t.is(result.id, team1.id);
const playerIds = result.Players.map(({ id }) => id); const playerIds = result.Players.map(({ id }) => id);
@ -59,8 +61,8 @@ test('multiple includes /team?include=players&include=city', async (t) => {
const { team1, player1, player2, city1 } = instances; const { team1, player1, player2, city1 } = instances;
const path = `/team/${team1.id}?include=players&include=city`; const path = `/team/${team1.id}?include=players&include=city`;
const { result, response } = await server.inject(path); const { result, statusCode } = await server.inject(path);
t.falsy(response instanceof Error); t.is(statusCode, STATUS_OK);
t.is(result.id, team1.id); t.is(result.id, team1.id);
const playerIds = result.Players.map(({ id }) => id); const playerIds = result.Players.map(({ id }) => id);
@ -74,8 +76,8 @@ test('multiple includes /team?include[]=players&include[]=city', async (t) => {
const { team1, player1, player2, city1 } = instances; const { team1, player1, player2, city1 } = instances;
const path = `/team/${team1.id}?include[]=players&include[]=city`; const path = `/team/${team1.id}?include[]=players&include[]=city`;
const { result, response } = await server.inject(path); const { result, statusCode } = await server.inject(path);
t.falsy(response instanceof Error); t.is(statusCode, STATUS_OK);
t.is(result.id, team1.id); t.is(result.id, team1.id);
const playerIds = result.Players.map(({ id }) => id); const playerIds = result.Players.map(({ id }) => id);