Skip to content

Commit

Permalink
🔖 release chopper v7.0.8 (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored Oct 11, 2023
1 parent 294e27a commit 961bdce
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 6 deletions.
4 changes: 4 additions & 0 deletions chopper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.0.8

- Encode DateTime query parameters in ISO8601 format ([#516](https://github.com/lejard-h/chopper/pull/516))

## 7.0.7+1

- Fix Github release workflow permissions ([#512](https://github.com/lejard-h/chopper/pull/512))
Expand Down
6 changes: 5 additions & 1 deletion chopper/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ Iterable<_Pair<String, String>> _iterableToQuery(
),
);

String _normalizeValue(value) => Uri.encodeComponent(value?.toString() ?? '');
String _normalizeValue(value) => Uri.encodeComponent(
value is DateTime
? value.toUtc().toIso8601String()
: value?.toString() ?? '',
);

final class _Pair<A, B> with EquatableMixin {
final A first;
Expand Down
2 changes: 1 addition & 1 deletion chopper/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chopper
description: Chopper is an http client generator using source_gen, inspired by Retrofit
version: 7.0.7+1
version: 7.0.8
documentation: https://hadrien-lejard.gitbook.io/chopper
repository: https://github.com/lejard-h/chopper

Expand Down
78 changes: 74 additions & 4 deletions chopper/test/base_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,8 @@ void main() {
});

test('Map query param using default dot QueryMapSeparator', () async {
final DateTime now = DateTime.now();

final httpClient = MockClient((request) async {
expect(
request.url.toString(),
Expand All @@ -1304,7 +1306,8 @@ void main() {
'&value.etc.mno.uvw=xyz'
'&value.etc.mno.list=a'
'&value.etc.mno.list=123'
'&value.etc.mno.list=false'),
'&value.etc.mno.list=false'
'&value.etc.dt=${Uri.encodeComponent(now.toUtc().toIso8601String())}'),
);
expect(request.method, equals('GET'));

Expand All @@ -1325,6 +1328,7 @@ void main() {
'uvw': 'xyz',
'list': ['a', 123, false],
},
'dt': now,
},
});

Expand All @@ -1335,6 +1339,8 @@ void main() {
});

test('Map query param with brackets QueryMapSeparator', () async {
final DateTime now = DateTime.now();

final httpClient = MockClient((request) async {
expect(
request.url.toString(),
Expand All @@ -1347,7 +1353,8 @@ void main() {
'&value%5Betc%5D%5Bmno%5D%5Buvw%5D=xyz'
'&value%5Betc%5D%5Bmno%5D%5Blist%5D%5B%5D=a'
'&value%5Betc%5D%5Bmno%5D%5Blist%5D%5B%5D=123'
'&value%5Betc%5D%5Bmno%5D%5Blist%5D%5B%5D=false'),
'&value%5Betc%5D%5Bmno%5D%5Blist%5D%5B%5D=false'
'&value%5Betc%5D%5Bdt%5D=${Uri.encodeComponent(now.toUtc().toIso8601String())}'),
);
expect(request.method, equals('GET'));

Expand All @@ -1369,6 +1376,7 @@ void main() {
'uvw': 'xyz',
'list': ['a', 123, false],
},
'dt': now,
},
});

Expand All @@ -1379,6 +1387,8 @@ void main() {
});

test('Map query param without including null query vars', () async {
final DateTime now = DateTime.now();

final httpClient = MockClient((request) async {
expect(
request.url.toString(),
Expand All @@ -1388,7 +1398,8 @@ void main() {
'&value.etc.mno.opq=rst'
'&value.etc.mno.list=a'
'&value.etc.mno.list=123'
'&value.etc.mno.list=false'),
'&value.etc.mno.list=false'
'&value.etc.dt=${Uri.encodeComponent(now.toUtc().toIso8601String())}'),
);
expect(request.method, equals('GET'));

Expand All @@ -1409,6 +1420,7 @@ void main() {
'uvw': null,
'list': ['a', 123, false],
},
'dt': now,
},
});

Expand All @@ -1419,6 +1431,8 @@ void main() {
});

test('Map query param including null query vars', () async {
final DateTime now = DateTime.now();

final httpClient = MockClient((request) async {
expect(
request.url.toString(),
Expand All @@ -1431,7 +1445,8 @@ void main() {
'&value.etc.mno.uvw='
'&value.etc.mno.list=a'
'&value.etc.mno.list=123'
'&value.etc.mno.list=false'),
'&value.etc.mno.list=false'
'&value.etc.dt=${Uri.encodeComponent(now.toUtc().toIso8601String())}'),
);
expect(request.method, equals('GET'));

Expand All @@ -1453,6 +1468,7 @@ void main() {
'uvw': null,
'list': ['a', 123, false],
},
'dt': now,
},
});

Expand Down Expand Up @@ -1510,4 +1526,58 @@ void main() {
),
);
});

<DateTime, String>{
DateTime.utc(2023, 1, 1): '2023-01-01T00%3A00%3A00.000Z',
DateTime.utc(2023, 1, 1, 12, 34, 56): '2023-01-01T12%3A34%3A56.000Z',
DateTime.utc(2023, 1, 1, 12, 34, 56, 789): '2023-01-01T12%3A34%3A56.789Z',
}.forEach((DateTime dateTime, String expected) {
test('DateTime is encoded as ISO8601', () async {
final httpClient = MockClient((request) async {
expect(
request.url.toString(),
equals('$baseUrl/test/date_time?value=$expected'),
);
expect(request.method, equals('GET'));

return http.Response('get response', 200);
});

final chopper = buildClient(httpClient, JsonConverter());
final service = chopper.getService<HttpTestService>();

final response = await service.getDateTime(dateTime);

expect(response.body, equals('get response'));
expect(response.statusCode, equals(200));

httpClient.close();
});
});

test('Local DateTime is encoded as UTC ISO8601', () async {
final DateTime dateTime = DateTime.now();
final String expected =
Uri.encodeComponent(dateTime.toUtc().toIso8601String());

final httpClient = MockClient((request) async {
expect(
request.url.toString(),
equals('$baseUrl/test/date_time?value=$expected'),
);
expect(request.method, equals('GET'));

return http.Response('get response', 200);
});

final chopper = buildClient(httpClient, JsonConverter());
final service = chopper.getService<HttpTestService>();

final response = await service.getDateTime(dateTime);

expect(response.body, equals('get response'));
expect(response.statusCode, equals(200));

httpClient.close();
});
}
13 changes: 13 additions & 0 deletions chopper/test/test_service.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions chopper/test/test_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ abstract class HttpTestService extends ChopperService {
Future<Response<String>> getUsingMapQueryParamWithBrackets(
@Query('value') Map<String, dynamic> value,
);

@Get(path: '/date_time')
Future<Response<String>> getDateTime(
@Query('value') DateTime value,
);
}

Request customConvertRequest(Request req) {
Expand Down

0 comments on commit 961bdce

Please sign in to comment.