Skip to content

Commit

Permalink
fix: switch test to AST from document string
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Nov 5, 2019
1 parent e9f9527 commit 894dc53
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 31 deletions.
6 changes: 4 additions & 2 deletions packages/graphql/test/anonymous_operations_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:gql/language.dart';
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -58,7 +59,7 @@ void main() {
group('query', () {
test('successful query', () async {
final WatchQueryOptions _options = WatchQueryOptions(
document: readRepositories,
documentNode: parseString(readRepositories),
variables: <String, dynamic>{},
);
when(
Expand Down Expand Up @@ -135,7 +136,8 @@ void main() {
});
group('mutation', () {
test('successful mutation', () async {
final MutationOptions _options = MutationOptions(document: addStar);
final MutationOptions _options =
MutationOptions(documentNode: parseString(addStar));
when(mockHttpClient.send(any)).thenAnswer((Invocation a) async =>
simpleResponse(
body:
Expand Down
27 changes: 14 additions & 13 deletions packages/graphql/test/core/raw_operation_data_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:gql/language.dart';
import 'package:graphql/src/core/raw_operation_data.dart';
import 'package:test/test.dart';

Expand All @@ -6,15 +7,15 @@ void main() {
group('single operation', () {
test('query without name', () {
final opData = RawOperationData(
document: 'query {}',
documentNode: parseString('query {}'),
);

expect(opData.operationName, null);
});

test('query with explicit name', () {
final opData = RawOperationData(
document: 'query Operation {}',
documentNode: parseString('query Operation {}'),
operationName: 'Operation',
);

Expand All @@ -23,7 +24,7 @@ void main() {

test('mutation with explicit name', () {
final opData = RawOperationData(
document: 'mutation Operation {}',
documentNode: parseString('mutation Operation {}'),
operationName: 'Operation',
);

Expand All @@ -32,7 +33,7 @@ void main() {

test('subscription with explicit name', () {
final opData = RawOperationData(
document: 'subscription Operation {}',
documentNode: parseString('subscription Operation {}'),
operationName: 'Operation',
);

Expand All @@ -41,23 +42,23 @@ void main() {

test('query with implicit name', () {
final opData = RawOperationData(
document: 'query Operation {}',
documentNode: parseString('query Operation {}'),
);

expect(opData.operationName, 'Operation');
});

test('mutation with implicit name', () {
final opData = RawOperationData(
document: 'mutation Operation {}',
documentNode: parseString('mutation Operation {}'),
);

expect(opData.operationName, 'Operation');
});

test('subscription with implicit name', () {
final opData = RawOperationData(
document: 'subscription Operation {}',
documentNode: parseString('subscription Operation {}'),
);

expect(opData.operationName, 'Operation');
Expand All @@ -73,7 +74,7 @@ void main() {

test('query with explicit name', () {
final opData = RawOperationData(
document: document,
documentNode: parseString(document),
operationName: 'OperationQ',
);

Expand All @@ -82,7 +83,7 @@ void main() {

test('mutation with explicit name', () {
final opData = RawOperationData(
document: document,
documentNode: parseString(document),
operationName: 'OperationM',
);

Expand All @@ -91,7 +92,7 @@ void main() {

test('subscription with explicit name', () {
final opData = RawOperationData(
document: document,
documentNode: parseString(document),
operationName: 'OperationS',
);

Expand All @@ -100,23 +101,23 @@ void main() {

test('query with implicit name', () {
final opData = RawOperationData(
document: document,
documentNode: parseString(document),
);

expect(opData.operationName, 'OperationS');
});

test('mutation with implicit name', () {
final opData = RawOperationData(
document: document,
documentNode: parseString(document),
);

expect(opData.operationName, 'OperationS');
});

test('subscription with implicit name', () {
final opData = RawOperationData(
document: document,
documentNode: parseString(document),
);

expect(opData.operationName, 'OperationS');
Expand Down
14 changes: 8 additions & 6 deletions packages/graphql/test/graphql_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:mockito/mockito.dart';
import 'package:http/http.dart' as http;

import 'package:graphql/client.dart';
import 'package:gql/language.dart';

import './helpers.dart';

Expand Down Expand Up @@ -60,7 +61,7 @@ void main() {
group('query', () {
test('successful query', () async {
final WatchQueryOptions _options = WatchQueryOptions(
document: readRepositories,
documentNode: parseString(readRepositories),
variables: <String, dynamic>{
'nRepositories': 42,
},
Expand Down Expand Up @@ -135,8 +136,8 @@ void main() {
throw e;
});

final QueryResult r = await graphQLClientClient
.query(WatchQueryOptions(document: readRepositories));
final QueryResult r = await graphQLClientClient.query(
WatchQueryOptions(documentNode: parseString(readRepositories)));

expect((r.exception.clientException as UnhandledFailureWrapper).failure,
e);
Expand All @@ -151,8 +152,8 @@ void main() {
throw e;
});

final QueryResult r = await graphQLClientClient
.query(WatchQueryOptions(document: readRepositories));
final QueryResult r = await graphQLClientClient.query(
WatchQueryOptions(documentNode: parseString(readRepositories)));

expect(
(r.exception.clientException as UnhandledFailureWrapper).failure,
Expand All @@ -171,7 +172,8 @@ void main() {
});
group('mutation', () {
test('successful mutation', () async {
final MutationOptions _options = MutationOptions(document: addStar);
final MutationOptions _options =
MutationOptions(documentNode: parseString(addStar));
when(mockHttpClient.send(any)).thenAnswer((Invocation a) async =>
simpleResponse(
body:
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/test/link/error/link_error_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "dart:async";
import "dart:convert";

import 'package:gql/language.dart';
import 'package:graphql/src/exceptions/exceptions.dart';
import 'package:graphql/src/link/error/link_error.dart';
import 'package:graphql/src/link/http/link_http.dart';
Expand All @@ -21,7 +22,7 @@ void main() {
setUp(() {
client = MockClient();
query = Operation(
document: 'query Operation {}',
documentNode: parseString('query Operation {}'),
operationName: 'Operation',
);
httpLink = HttpLink(
Expand Down
9 changes: 5 additions & 4 deletions packages/graphql/test/link/http/link_http_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "dart:async";
import "dart:convert";

import 'package:gql/language.dart';
import 'package:graphql/client.dart';
import 'package:graphql/internal.dart';
import 'package:graphql/src/link/http/link_http.dart';
Expand All @@ -23,11 +24,11 @@ void main() {
setUp(() {
client = MockClient();
query = Operation(
document: 'query Operation {}',
documentNode: parseString('query Operation {}'),
operationName: 'Operation',
);
subscription = Operation(
document: 'subscription Operation {}',
documentNode: parseString('subscription Operation {}'),
operationName: 'Operation',
);
link = HttpLink(
Expand Down Expand Up @@ -234,7 +235,7 @@ void main() {
);

final query = Operation(
document: '{}',
documentNode: parseString('{}'),
extensions: {'extension-1': 'extension-value-1'},
);
query.setContext({
Expand Down Expand Up @@ -476,7 +477,7 @@ void main() {
);

final query = Operation(
document: '{}',
documentNode: parseString('{}'),
variables: {
'files': [
http.MultipartFile.fromString(
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/test/multipart_upload_io_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:gql/language.dart';
@TestOn("vm")

import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -58,7 +58,7 @@ void main() {
'upload with io.File instance deprecation warning',
overridePrint((log) async {
final MutationOptions _options = MutationOptions(
document: uploadMutation,
documentNode: parseString(uploadMutation),
variables: <String, dynamic>{
'files': [
io.File('pubspec.yaml'),
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/test/multipart_upload_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:gql/language.dart';
import 'package:http_parser/http_parser.dart';
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
Expand Down Expand Up @@ -124,7 +125,7 @@ void main() {
});

final MutationOptions _options = MutationOptions(
document: uploadMutation,
documentNode: parseString(uploadMutation),
variables: <String, dynamic>{
'files': [
http.MultipartFile.fromBytes(
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/test/socket_client_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:gql/language.dart';
import 'package:graphql/src/link/operation.dart';
import 'package:graphql/src/websocket/messages.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -36,7 +37,7 @@ void main() {
});
test('subscription data', () async {
final payload = SubscriptionRequest(
Operation(document: 'subscription {}'),
Operation(documentNode: parseString('subscription {}')),
);
final waitForConnection = true;
final subscriptionDataStream =
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/test/websocket_legacy_io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:gql/language.dart';
import 'package:test/test.dart';

import 'package:graphql/src/link/operation.dart';
Expand Down Expand Up @@ -43,7 +44,7 @@ void main() {
});
test('subscription data', () async {
final payload = SubscriptionRequest(
Operation(document: 'subscription {}'),
Operation(documentNode: parseString('subscription {}')),
);
final waitForConnection = true;
final subscriptionDataStream =
Expand Down

0 comments on commit 894dc53

Please sign in to comment.