Skip to content

Commit

Permalink
fix: result type of sanity_client is now dynamic instead of Map<Strin…
Browse files Browse the repository at this point in the history
…g, dynamic>
  • Loading branch information
pavanpodila committed Jul 5, 2024
1 parent 8f264fa commit 040615b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/sanity/sanity_client/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.0"
version: "1.2.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/sanity_client/lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Without a valid token you will not be able to fetch data from Sanity.''');
}

/// The client for fetching data from Sanity
class SanityClient {
final class SanityClient {
/// The configuration for the client
final SanityConfig config;

Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/sanity_client/lib/response_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SanityDataset {
@JsonSerializable()
class ServerResponse {
/// The result of the query, which can be a null, object or array.
final Map<String, dynamic>? result;
final dynamic result;

/// The time it took for the server to respond to the query.
final int ms;
Expand Down
4 changes: 2 additions & 2 deletions packages/sanity/sanity_client/lib/response_types.g.dart

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

6 changes: 3 additions & 3 deletions packages/sanity/sanity_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ environment:
dependencies:
flutter:
sdk: flutter
json_annotation: ^4.8.1
json_annotation: ^4.9.0
http: ^1.1.0

dev_dependencies:
flutter_test:
sdk: flutter
lints: ^3.0.0
json_serializable: ^6.7.1
lints: ^4.0.0
json_serializable: ^6.8.0
build_runner: ^2.4.6

flutter:
31 changes: 28 additions & 3 deletions packages/sanity/sanity_client/test/query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ void main() {
);
});

test('Parses results for valid query', () async {
test('Parses results for valid query, with results as a Map', () async {
final httpClient = MockClient(
(final request) async => http.Response(
'''
{
"ms": 20,
"query": "",
"result": {}
"result": {"_type": "someType"}
}
''',
200,
Expand All @@ -184,7 +184,32 @@ void main() {
final client = getClient(httpClient: httpClient);

final response = await client.fetch('valid query');
expect(response.result, equals({}));
expect(response.result, equals({'_type': 'someType'}));
expect(response.info.serverTimeMs, equals(20));
});

test('Parses results for valid query, with results as a List', () async {
final httpClient = MockClient(
(final request) async => http.Response(
'''
{
"ms": 20,
"query": "",
"result": [{"_type": "someType"}]
}
''',
200,
),
);

final client = getClient(httpClient: httpClient);

final response = await client.fetch('valid query');
expect(
response.result,
equals([
{'_type': 'someType'}
]));
expect(response.info.serverTimeMs, equals(20));
});
}

0 comments on commit 040615b

Please sign in to comment.