-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✅ Fix query unit tests + Bump package_info_plus package #803
base: master
Are you sure you want to change the base?
Changes from all commits
d99751a
c94d74b
7ac70c5
414e5f7
b920510
6953ec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; | ||
{% if 'dart' in language.params.packageName %} | ||
import 'package:test/test.dart'; | ||
{% else %} | ||
import 'package:flutter_test/flutter_test.dart'; | ||
{% endif %} | ||
|
||
class BasicFilterQueryTest { | ||
class BasicFilterQueryTest<V, E> { | ||
final String description; | ||
final dynamic value; | ||
final String expectedValues; | ||
final V value; | ||
final E expectedValues; | ||
|
||
BasicFilterQueryTest({ | ||
required this.description, | ||
|
@@ -20,42 +22,42 @@ class BasicFilterQueryTest { | |
void main() { | ||
group('basic filter tests', () { | ||
final tests = [ | ||
BasicFilterQueryTest( | ||
BasicFilterQueryTest<String, List<String>>( | ||
description: 'with a string', | ||
value: 's', | ||
expectedValues: ["s"], | ||
expectedValues: ['s'], | ||
), | ||
BasicFilterQueryTest( | ||
BasicFilterQueryTest<int, List<int>>( | ||
description: 'with an integer', | ||
value: 1, | ||
expectedValues: [1], | ||
), | ||
BasicFilterQueryTest( | ||
BasicFilterQueryTest<double, List<double>>( | ||
description: 'with a double', | ||
value: 1.2, | ||
expectedValues: [1.2], | ||
), | ||
BasicFilterQueryTest( | ||
BasicFilterQueryTest<double, List<double>>( | ||
description: 'with a whole number double', | ||
value: 1.0, | ||
expectedValues: [1.0], | ||
), | ||
BasicFilterQueryTest( | ||
BasicFilterQueryTest<bool, List<bool>>( | ||
description: 'with a bool', | ||
value: false, | ||
expectedValues: [false], | ||
), | ||
BasicFilterQueryTest( | ||
BasicFilterQueryTest<List<String>, List<String>>( | ||
description: 'with a list', | ||
value: ['a', 'b', 'c'], | ||
expectedValues: ["a","b","c"], | ||
expectedValues: ['a', 'b', 'c'], | ||
), | ||
]; | ||
|
||
group('equal()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
final query = Query.equal('attr', t.value).toJson(); | ||
final query = jsonDecode(Query.equal('attr', t.value)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], t.expectedValues); | ||
expect(query['method'], 'equal'); | ||
|
@@ -66,149 +68,189 @@ void main() { | |
group('notEqual()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
final query = Query.notEqual('attr', t.value).toJson(); | ||
final query = jsonDecode(Query.notEqual('attr', t.value)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], t.expectedValues); | ||
expect(query['method'], 'notEqual'); | ||
}); | ||
} | ||
|
||
test('with a list', () { | ||
final query = jsonDecode(Query.notEqual('attr', ['a', 'b', 'c'])); | ||
print(query); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], [['a', 'b', 'c']]); // Is there a bug here? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I think the idea with this was that you'd never pass a list to this because it just doesn't make sense.
would always be true. That said, the implementation makes the behavior weird... @lohanidamodar, what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's the database implementation, we don't support arrays for values in few methods. @abnegate might be able to shed some light. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not equal should only provide a single value, the problem is it's hard to represent in languages without union types. This should actually throw an exception There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
expect(query['method'], 'notEqual'); | ||
}); | ||
}); | ||
|
||
group('lessThan()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
final query = Query.lessThan('attr', t.value).toJson(); | ||
final query = jsonDecode(Query.lessThan('attr', t.value)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], t.expectedValues); | ||
expect(query['method'], 'lessThan'); | ||
}); | ||
} | ||
|
||
test('with a list', () { | ||
final query = jsonDecode(Query.lessThan('attr', ['a', 'b', 'c'])); | ||
print(query); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], ['a', 'b', 'c']); | ||
expect(query['method'], 'lessThan'); | ||
}); | ||
}); | ||
|
||
group('lessThanEqual()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
final query = Query.lessThanEqual('attr', t.value).toJson(); | ||
final query = jsonDecode(Query.lessThanEqual('attr', t.value)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], t.expectedValues); | ||
expect(query['method'], 'lessThanEqual'); | ||
}); | ||
} | ||
|
||
test('with a list', () { | ||
final query = jsonDecode(Query.lessThanEqual('attr', ['a', 'b', 'c'])); | ||
print(query); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], ['a', 'b', 'c']); | ||
expect(query['method'], 'lessThanEqual'); | ||
}); | ||
}); | ||
|
||
group('greaterThan()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
final query = Query.greaterThan('attr', t.value).toJson(); | ||
final query = jsonDecode(Query.greaterThan('attr', t.value)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], t.expectedValues); | ||
expect(query['method'], 'greaterThan'); | ||
}); | ||
} | ||
|
||
test('with a list', () { | ||
final query = jsonDecode(Query.greaterThan('attr', ['a', 'b', 'c'])); | ||
print(query); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], ['a', 'b', 'c']); | ||
expect(query['method'], 'greaterThan'); | ||
}); | ||
}); | ||
|
||
group('greaterThanEqual()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
final query = Query.greaterThanEqual('attr', t.value).toJson(); | ||
final query = jsonDecode(Query.greaterThanEqual('attr', t.value)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], t.expectedValues); | ||
expect(query['method'], 'greaterThanEqual'); | ||
}); | ||
} | ||
|
||
test('with a list', () { | ||
final query = jsonDecode(Query.greaterThanEqual('attr', ['a', 'b', 'c'])); | ||
print(query); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], ['a', 'b', 'c']); | ||
expect(query['method'], 'greaterThanEqual'); | ||
}); | ||
}); | ||
}); | ||
|
||
test('returns search', () { | ||
final query = Query.search('attr', 'keyword1 keyword2').toJson(); | ||
final query = jsonDecode(Query.search('attr', 'keyword1 keyword2')); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], ['keyword1 keyword2']); | ||
expect(query['method'], 'search'); | ||
}); | ||
|
||
test('returns isNull', () { | ||
final query = Query.isNull('attr').toJson(); | ||
final query = jsonDecode(Query.isNull('attr')); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], null); | ||
expect(query['method'], 'isNull'); | ||
}); | ||
|
||
test('returns isNotNull', () { | ||
final query = Query.isNotNull('attr', 'keyword1 keyword2').toJson(); | ||
final query = jsonDecode(Query.isNotNull('attr')); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], null); | ||
expect(query['method'], 'isNotNull'); | ||
}); | ||
|
||
group('between()', () { | ||
test('with integers', () { | ||
final query = Query.between('attr', 1, 2).toJson(); | ||
final query = jsonDecode(Query.between('attr', 1, 2)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], [1, 2]); | ||
expect(query['method'], 'between'); | ||
}); | ||
|
||
test('with doubles', () { | ||
final query = Query.between('attr', 1.0, 2.0).toJson(); | ||
final query = jsonDecode(Query.between('attr', 1.0, 2.0)); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], [1.0, 2.0]); | ||
expect(query['method'], 'between'); | ||
}); | ||
|
||
test('with strings', () { | ||
final query = Query.between('attr', 'a', 'z').toJson(); | ||
final query = jsonDecode(Query.between('attr', 'a', 'z')); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], ['a', 'z']); | ||
expect(query['method'], 'between'); | ||
}); | ||
}); | ||
|
||
test('returns select', () { | ||
final query = Query.select(['attr1', 'attr2']).toJson(); | ||
final query = jsonDecode(Query.select(['attr1', 'attr2'])); | ||
expect(query['attribute'], null); | ||
expect(query['values'], ['attr1', 'attr2']); | ||
expect(query['method'], 'select'); | ||
}); | ||
|
||
test('returns orderAsc', () { | ||
final query = Query.orderAsc('attr').toJson(); | ||
final query = jsonDecode(Query.orderAsc('attr')); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], null); | ||
expect(query['method'], 'orderAsc'); | ||
}); | ||
|
||
test('returns orderDesc', () { | ||
final query = Query.orderDesc('attr').toJson(); | ||
final query = jsonDecode(Query.orderDesc('attr')); | ||
expect(query['attribute'], 'attr'); | ||
expect(query['values'], null); | ||
expect(query['method'], 'orderDesc'); | ||
}); | ||
|
||
test('returns cursorBefore', () { | ||
final query = Query.cursorBefore('custom').toJson(); | ||
final query = jsonDecode(Query.cursorBefore('custom')); | ||
expect(query['attribute'], null); | ||
expect(query['values'], 'custom'); | ||
expect(query['values'], ['custom']); | ||
expect(query['method'], 'cursorBefore'); | ||
}); | ||
|
||
test('returns cursorAfter', () { | ||
final query = Query.cursorAfter('custom').toJson(); | ||
final query = jsonDecode(Query.cursorAfter('custom')); | ||
expect(query['attribute'], null); | ||
expect(query['values'], 'custom'); | ||
expect(query['values'], ['custom']); | ||
expect(query['method'], 'cursorAfter'); | ||
}); | ||
|
||
test('returns limit', () { | ||
final query = Query.limit(1).toJson(); | ||
final query = jsonDecode(Query.limit(1)); | ||
expect(query['attribute'], null); | ||
expect(query['values'], 1); | ||
expect(query['values'], [1]); | ||
expect(query['method'], 'limit'); | ||
}); | ||
|
||
test('returns offset', () { | ||
final query = Query.offset(1).toJson(); | ||
final query = jsonDecode(Query.offset(1)); | ||
expect(query['attribute'], null); | ||
expect(query['values'], 1); | ||
expect(query['values'], [1]); | ||
expect(query['method'], 'offset'); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure to delete all the print statement