-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eng(rest): migrate RestProvider to use query v2 (#498)
- Loading branch information
Showing
29 changed files
with
1,158 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,178 +6,174 @@ import 'package:test/test.dart'; | |
|
||
void main() { | ||
group('Query', () { | ||
group('properties', () { | ||
test('#action', () { | ||
const q = Query(action: QueryAction.delete); | ||
expect(q.action, QueryAction.delete); | ||
}); | ||
test('#action', () { | ||
const q = Query(action: QueryAction.delete); | ||
expect(q.action, QueryAction.delete); | ||
}); | ||
|
||
group('#providerArgs', () { | ||
test('#providerArgs.page and #providerArgs.sort', () { | ||
const q = Query(providerArgs: {'page': 1, 'sort': 'by_user_asc'}); | ||
group('#providerArgs', () { | ||
test('#providerArgs.page and #providerArgs.sort', () { | ||
const q = Query(providerArgs: {'page': 1, 'sort': 'by_user_asc'}); | ||
|
||
expect(q.providerArgs['page'], 1); | ||
expect(q.providerArgs['sort'], 'by_user_asc'); | ||
}); | ||
expect(q.providerArgs['page'], 1); | ||
expect(q.providerArgs['sort'], 'by_user_asc'); | ||
}); | ||
}); | ||
|
||
test('#providerArgs.limit', () { | ||
const q0 = Query(limit: 0); | ||
expect(q0.limit, 0); | ||
test('#limit', () { | ||
const q0 = Query(limit: 0); | ||
expect(q0.limit, 0); | ||
|
||
const q10 = Query(limit: 10); | ||
expect(q10.limit, 10); | ||
const q10 = Query(limit: 10); | ||
expect(q10.limit, 10); | ||
|
||
const q18 = Query(limit: 18); | ||
expect(q18.limit, 18); | ||
}); | ||
const q18 = Query(limit: 18); | ||
expect(q18.limit, 18); | ||
}); | ||
|
||
test('#providerArgs.offset', () { | ||
const q0 = Query(limit: 10, offset: 0); | ||
expect(q0.offset, 0); | ||
test('#offset', () { | ||
const q0 = Query(limit: 10, offset: 0); | ||
expect(q0.offset, 0); | ||
|
||
const q10 = Query(limit: 10, offset: 10); | ||
expect(q10.offset, 10); | ||
const q10 = Query(limit: 10, offset: 10); | ||
expect(q10.offset, 10); | ||
|
||
const q18 = Query(limit: 10, offset: 18); | ||
expect(q18.offset, 18); | ||
}); | ||
}); | ||
const q18 = Query(limit: 10, offset: 18); | ||
expect(q18.offset, 18); | ||
}); | ||
|
||
test('#where', () { | ||
const q = Query( | ||
where: [ | ||
Where('name', value: 'Thomas'), | ||
], | ||
); | ||
test('#where', () { | ||
const q = Query( | ||
where: [ | ||
Where('name', value: 'Thomas'), | ||
], | ||
); | ||
|
||
expect(q.where!.first.evaluatedField, 'name'); | ||
expect(q.where!.first.value, 'Thomas'); | ||
}); | ||
expect(q.where!.first.evaluatedField, 'name'); | ||
expect(q.where!.first.value, 'Thomas'); | ||
}); | ||
}); | ||
|
||
group('==', () { | ||
test('properties are the same', () { | ||
const q1 = Query( | ||
action: QueryAction.delete, | ||
limit: 3, | ||
offset: 3, | ||
); | ||
const q2 = Query( | ||
action: QueryAction.delete, | ||
limit: 3, | ||
offset: 3, | ||
); | ||
|
||
expect(q1, q2); | ||
}); | ||
group('==', () { | ||
test('properties are the same', () { | ||
const q1 = Query( | ||
action: QueryAction.delete, | ||
limit: 3, | ||
offset: 3, | ||
); | ||
const q2 = Query( | ||
action: QueryAction.delete, | ||
limit: 3, | ||
offset: 3, | ||
); | ||
|
||
test('providerArgs are the same', () { | ||
const q1 = Query(providerArgs: {'name': 'Guy'}); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
expect(q1, q2); | ||
}); | ||
|
||
expect(q1, q2); | ||
}); | ||
test('providerArgs are the same', () { | ||
const q1 = Query(providerArgs: {'name': 'Guy'}); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
|
||
test('providerArgs have different values', () { | ||
const q1 = Query(providerArgs: {'name': 'Thomas'}); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
expect(q1, q2); | ||
}); | ||
|
||
expect(q1, isNot(q2)); | ||
}); | ||
test('providerArgs have different values', () { | ||
const q1 = Query(providerArgs: {'name': 'Thomas'}); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
|
||
test('providerArgs have different keys', () { | ||
const q1 = Query(providerArgs: {'email': '[email protected]'}); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
expect(q1, isNot(q2)); | ||
}); | ||
|
||
expect(q1, isNot(q2)); | ||
}); | ||
test('providerArgs have different keys', () { | ||
const q1 = Query(providerArgs: {'email': '[email protected]'}); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
|
||
test('providerArgs are null', () { | ||
const q1 = Query(); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
expect(q1, isNot(q2)); | ||
expect(q1, isNot(q2)); | ||
}); | ||
|
||
const q3 = Query(); | ||
expect(q1, q3); | ||
}); | ||
test('providerArgs are null', () { | ||
const q1 = Query(); | ||
const q2 = Query(providerArgs: {'name': 'Guy'}); | ||
expect(q1, isNot(q2)); | ||
|
||
const q3 = Query(); | ||
expect(q1, q3); | ||
}); | ||
}); | ||
|
||
group('#copyWith', () { | ||
test('overrides', () { | ||
const q1 = Query(action: QueryAction.insert, limit: 10); | ||
final q2 = q1.copyWith(limit: 20); | ||
expect(q2.action, QueryAction.insert); | ||
expect(q2.limit, 20); | ||
expect(q2.offset, null); | ||
|
||
final q3 = q1.copyWith(limit: 50, offset: 20); | ||
expect(q3.action, QueryAction.insert); | ||
expect(q3.limit, 50); | ||
expect(q3.offset, 20); | ||
}); | ||
group('#copyWith', () { | ||
test('overrides', () { | ||
const q1 = Query(action: QueryAction.insert, limit: 10); | ||
final q2 = q1.copyWith(limit: 20); | ||
expect(q2.action, QueryAction.insert); | ||
expect(q2.limit, 20); | ||
expect(q2.offset, null); | ||
|
||
final q3 = q1.copyWith(limit: 50, offset: 20); | ||
expect(q3.action, QueryAction.insert); | ||
expect(q3.limit, 50); | ||
expect(q3.offset, 20); | ||
}); | ||
|
||
test('appends', () { | ||
const q1 = Query(action: QueryAction.insert); | ||
final q2 = q1.copyWith(limit: 20); | ||
test('appends', () { | ||
const q1 = Query(action: QueryAction.insert); | ||
final q2 = q1.copyWith(limit: 20); | ||
|
||
expect(q1.limit, null); | ||
expect(q2.action, QueryAction.insert); | ||
expect(q2.limit, 20); | ||
}); | ||
expect(q1.limit, null); | ||
expect(q2.action, QueryAction.insert); | ||
expect(q2.limit, 20); | ||
}); | ||
}); | ||
|
||
test('#toJson', () { | ||
const source = Query( | ||
action: QueryAction.update, | ||
limit: 3, | ||
offset: 3, | ||
); | ||
|
||
expect( | ||
source.toJson(), | ||
{ | ||
'action': 2, | ||
'limit': 3, | ||
'offset': 3, | ||
}, | ||
); | ||
}); | ||
|
||
test('#toJson', () { | ||
const source = Query( | ||
test('.fromJson', () { | ||
final json = { | ||
'action': 2, | ||
'limit': 3, | ||
'offset': 3, | ||
}; | ||
|
||
final result = Query.fromJson(json); | ||
expect( | ||
result, | ||
const Query( | ||
action: QueryAction.update, | ||
limit: 3, | ||
offset: 3, | ||
); | ||
), | ||
); | ||
}); | ||
|
||
expect( | ||
source.toJson(), | ||
{ | ||
'action': 2, | ||
'limit': 3, | ||
'offset': 3, | ||
}, | ||
); | ||
group('.where', () { | ||
test('required arguments', () { | ||
const expandedQuery = Query(where: [Where('id', value: 2)]); | ||
final factoried = Query.where('id', 2); | ||
expect(factoried, expandedQuery); | ||
expect(Where.firstByField('id', factoried.where)!.value, 2); | ||
expect(factoried.unlimited, isTrue); | ||
}); | ||
|
||
group('factories', () { | ||
test('.fromJson', () { | ||
final json = { | ||
'action': 2, | ||
'limit': 3, | ||
'offset': 3, | ||
}; | ||
|
||
final result = Query.fromJson(json); | ||
expect( | ||
result, | ||
const Query( | ||
action: QueryAction.update, | ||
limit: 3, | ||
offset: 3, | ||
), | ||
); | ||
}); | ||
|
||
group('.where', () { | ||
test('required arguments', () { | ||
const expandedQuery = Query(where: [Where('id', value: 2)]); | ||
final factoried = Query.where('id', 2); | ||
expect(factoried, expandedQuery); | ||
expect(Where.firstByField('id', factoried.where)!.value, 2); | ||
expect(factoried.unlimited, isTrue); | ||
}); | ||
|
||
test('limit1:true', () { | ||
const expandedQuery = Query(where: [Where('id', value: 2)], limit: 1); | ||
final factoried = Query.where('id', 2, limit1: true); | ||
expect(factoried, expandedQuery); | ||
expect(factoried.unlimited, isFalse); | ||
}); | ||
}); | ||
test('limit1:true', () { | ||
const expandedQuery = Query(where: [Where('id', value: 2)], limit: 1); | ||
final factoried = Query.where('id', 2, limit1: true); | ||
expect(factoried, expandedQuery); | ||
expect(factoried.unlimited, isFalse); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.