forked from zino-hofmann/graphql-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zino-hofmann#348 from truongsinh/fix/crashed-uploa…
…d-file fix(client): crashed upload file
- Loading branch information
Showing
8 changed files
with
137 additions
and
19 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
tags: | ||
integration: | ||
|
||
define_platforms: | ||
chromium: | ||
name: Chromium | ||
|
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
@TestOn("vm") | ||
|
||
import 'package:test/test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'dart:io' as io; | ||
|
||
import 'package:graphql/client.dart'; | ||
|
||
import 'helpers.dart'; | ||
|
||
class MockHttpClient extends Mock implements http.Client {} | ||
|
||
void main() { | ||
HttpLink httpLink; | ||
AuthLink authLink; | ||
Link link; | ||
GraphQLClient graphQLClientClient; | ||
MockHttpClient mockHttpClient; | ||
|
||
group( | ||
'upload', | ||
() { | ||
const String uploadMutation = r''' | ||
mutation($files: [Upload!]!) { | ||
multipleUpload(files: $files) { | ||
id | ||
filename | ||
mimetype | ||
path | ||
} | ||
} | ||
'''; | ||
|
||
setUp(() { | ||
mockHttpClient = MockHttpClient(); | ||
|
||
when(mockHttpClient.send(any)).thenAnswer((Invocation a) async { | ||
return simpleResponse(body: '{"data": {}}'); | ||
}); | ||
|
||
httpLink = HttpLink( | ||
uri: 'http://localhost:3001/graphql', httpClient: mockHttpClient); | ||
|
||
authLink = AuthLink( | ||
getToken: () async => 'Bearer my-special-bearer-token', | ||
); | ||
|
||
link = authLink.concat(httpLink); | ||
|
||
graphQLClientClient = GraphQLClient( | ||
cache: getTestCache(), | ||
link: link, | ||
); | ||
}); | ||
|
||
test( | ||
'upload with io.File instance deprecation warning', | ||
overridePrint((log) async { | ||
final MutationOptions _options = MutationOptions( | ||
document: uploadMutation, | ||
variables: <String, dynamic>{ | ||
'files': [ | ||
io.File('pubspec.yaml'), | ||
], | ||
}, | ||
); | ||
final QueryResult r = await graphQLClientClient.mutate(_options); | ||
|
||
expect(r.errors, isNull); | ||
expect(r.data, isNotNull); | ||
expect(log, hasLength(5)); | ||
final warningMessage = r''' | ||
⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️ DEPRECATION WARNING ⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️ | ||
Please do not use `File` direcly anymore. Instead, use | ||
`MultipartFile`. There's also a utitlity method to help you | ||
`import 'package:graphql/utilities.dart' show multipartFileFrom;` | ||
⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️ DEPRECATION WARNING ⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️⚠️️️️️️️️ | ||
'''; | ||
expect(log[0], warningMessage); | ||
expect(log[1], warningMessage); | ||
expect(log[2], warningMessage); | ||
expect(log[3], warningMessage); | ||
expect(log[4], warningMessage); | ||
}), | ||
); | ||
}, | ||
onPlatform: { | ||
"!vm": Skip("This test is only for VM"), | ||
}, | ||
); | ||
} |
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
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