Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 9e49727

Browse files
author
Dekel Barzilay
committed
- Fixed sorting tests to work in Postgres
- Added missing cleanup code
1 parent d9dd58c commit 9e49727

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

test/company.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export default class Company extends Model {
3434
}
3535

3636
static modifiers = {
37+
orderByName: builder => {
38+
builder.orderBy('name');
39+
},
3740
google: (builder, hasCeo) => {
3841
builder.where('name', 'Google');
3942

test/index.test.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,15 @@ describe('Feathers Objection Service', () => {
914914
$joinRelation: 'company',
915915
'company.name': {
916916
$like: 'Google'
917+
},
918+
$sort: {
919+
'employees.name': 1
917920
}
918921
}
919922
})
920923
.then(data => {
921924
expect(data.length).to.equal(2);
922-
expect(data[0].name).to.equal('D');
925+
expect(data[0].name).to.equal('C');
923926
});
924927
});
925928

@@ -941,44 +944,41 @@ describe('Feathers Objection Service', () => {
941944
});
942945

943946
it('allows joinRelation queries, eager with sort by relation', () => {
944-
return companies
947+
return employees
945948
.find({
946949
query: {
947-
$select: ['employees.name as employees.name'],
948-
$eager: '[employees, ceos]',
949-
$joinRelation: 'employees',
950+
$select: ['employees.*', 'company.name'],
951+
$eager: 'company',
952+
$joinRelation: 'company',
950953
$sort: {
951-
'employees.name': 1
954+
'employees.name': 1,
955+
'company.name': 1
952956
}
953957
}
954958
})
955959
.then(data => {
956960
expect(data.length).to.equal(4);
957-
expect(data[0].name).to.equal('Apple');
958-
expect(data[0].ceos.name).to.equal('Snoop');
959-
expect(data[0]['employees.name']).to.equal('A');
960-
expect(data[0].employees.length).to.equal(2);
961-
expect(data[0].employees[0].name).to.equal('B');
961+
expect(data[0].name).to.equal('A');
962+
expect(data[0].company.name).to.equal('Apple');
962963
});
963964
});
964965

965-
it('allows joinRelation queries, eager with sort by sorted relation', () => {
966-
return companies
966+
it('allows joinRelation queries, eager with sort and sorted relation', () => {
967+
return employees
967968
.find({
968969
query: {
969-
$eager: '[employees(orderByName), ceos]',
970-
$joinRelation: 'employees',
970+
$select: ['employees.*', 'company.name'],
971+
$eager: 'company(orderByName)',
972+
$joinRelation: 'company',
971973
$sort: {
972974
'employees.name': 1
973975
}
974976
}
975977
})
976978
.then(data => {
977-
expect(data.length).to.equal(2);
978-
expect(data[0].name).to.equal('Apple');
979-
expect(data[0].ceos.name).to.equal('Snoop');
980-
expect(data[0].employees.length).to.equal(2);
981-
expect(data[0].employees[0].name).to.equal('A');
979+
expect(data.length).to.equal(4);
980+
expect(data[0].name).to.equal('A');
981+
expect(data[0].company.name).to.equal('Apple');
982982
});
983983
});
984984
});
@@ -1088,6 +1088,7 @@ describe('Feathers Objection Service', () => {
10881088

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

1091+
await clients.remove(null);
10911092
await companies.remove(null);
10921093
});
10931094

@@ -1277,6 +1278,10 @@ describe('Feathers Objection Service', () => {
12771278
]);
12781279
});
12791280

1281+
after(async () => {
1282+
await companies.remove(null);
1283+
});
1284+
12801285
it('object', () => {
12811286
return companies.find({ query: { jsonObject: { $ne: null } } }).then(data => {
12821287
expect(data[0].jsonObject.numberField).to.equal(1.5);

0 commit comments

Comments
 (0)