Skip to content

Commit

Permalink
Fix tests clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekel Barzilay committed Mar 6, 2020
1 parent d37617c commit 1dc0680
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const app = feathers()
'/clients',
service({
model: Client,
multi: ['remove'],
allowedEager: 'company',
events: ['testing']
})
Expand All @@ -179,6 +180,7 @@ const peopleRooms = app.service('people-rooms');
const peopleRoomsCustomIdSeparator = app.service('people-rooms-custom-id-separator');
const companies = app.service('companies');
const employees = app.service('employees');
const clients = app.service('clients');

function clean (done) {
db.schema
Expand Down Expand Up @@ -763,9 +765,9 @@ describe('Feathers Objection Service', () => {
after(async () => {
await people.remove(ids.ceo.id);

for (const company of ids.companies) { await companies.remove(company.id); }

for (const employee of ids.employees) { await employees.remove(employee.id); }

for (const company of ids.companies) { await companies.remove(company.id); }
});

it('allows eager queries', () => {
Expand Down Expand Up @@ -815,27 +817,30 @@ describe('Feathers Objection Service', () => {
});

describe('Join Eager/Relation queries', () => {
const ids = {};

before(async () => {
const ceo = await people
ids.ceo = await people
.create({
name: 'Snoop',
age: 20
});

const data = await companies
ids.companies = await companies
.create([
{
name: 'Google',
ceo: ceo.id
ceo: ids.ceo.id
},
{
name: 'Apple',
ceo: ceo.id
ceo: ids.ceo.id
}
]);

const [google, apple] = data;
await employees
const [google, apple] = ids.companies;

ids.employees = await employees
.create([
{
name: 'D',
Expand All @@ -856,6 +861,14 @@ describe('Feathers Objection Service', () => {
]);
});

after(async () => {
await people.remove(ids.ceo.id);

for (const employee of ids.employees) { await employees.remove(employee.id); }

for (const company of ids.companies) { await companies.remove(company.id); }
});

it('allows joinEager queries', () => {
return employees.find({ query: { $joinEager: 'company' } }).then(data => {
expect(data[0].company).to.be.ok;
Expand All @@ -869,7 +882,7 @@ describe('Feathers Objection Service', () => {
query: {
$joinEager: 'company',
'company.name': {
$like: 'google'
$like: 'Google'
}
}
})
Expand Down Expand Up @@ -899,7 +912,7 @@ describe('Feathers Objection Service', () => {
query: {
$joinRelation: 'company',
'company.name': {
$like: 'google'
$like: 'Google'
}
}
})
Expand All @@ -916,7 +929,7 @@ describe('Feathers Objection Service', () => {
$eager: 'company',
$joinRelation: 'company',
'company.name': {
$like: 'google'
$like: 'Google'
}
}
})
Expand Down Expand Up @@ -969,7 +982,6 @@ describe('Feathers Objection Service', () => {

describe('Graph Insert Queries', () => {
before(async () => {
await companies.remove(null);
await companies
.create([
{
Expand All @@ -989,6 +1001,11 @@ describe('Feathers Objection Service', () => {
]);
});

after(async () => {
await clients.remove(null);
await companies.remove(null);
});

it('allows insertGraph queries', () => {
return companies.find({ query: { $eager: 'clients' } }).then(data => {
expect(data[0].clients).to.be.an('array');
Expand Down Expand Up @@ -1040,8 +1057,6 @@ describe('Feathers Objection Service', () => {
let google;

beforeEach(async () => {
await companies.remove(null);

ceo = await people
.create({
name: 'Snoop',
Expand All @@ -1066,7 +1081,11 @@ describe('Feathers Objection Service', () => {
});

afterEach(async () => {
await people.remove(ceo.id);
const persons = await people.find();

for (const person of persons) { await people.remove(person.id); }

await companies.remove(null);
});

it('allows upsertGraph queries on update', () => {
Expand Down Expand Up @@ -1538,12 +1557,10 @@ describe('Feathers Objection Service', () => {
describe('$noSelect', () => {
beforeEach(async () => {
await companies
.create([
{
name: 'Google',
ceo: 1
}
]);
.create({
name: 'Google',
ceo: 1
});
});

afterEach(async () => {
Expand Down

0 comments on commit 1dc0680

Please sign in to comment.