From 53de348049545289f54851da9617b22a983310b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kl=C4=81vs=20Pried=C4=ABtis?= Date: Sun, 6 Oct 2019 14:25:33 +0300 Subject: [PATCH 1/2] test(client): add tests for `operationName` getter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Klāvs Priedītis --- .../test/core/raw_operation_data_test.dart | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 packages/graphql/test/core/raw_operation_data_test.dart diff --git a/packages/graphql/test/core/raw_operation_data_test.dart b/packages/graphql/test/core/raw_operation_data_test.dart new file mode 100644 index 000000000..402645605 --- /dev/null +++ b/packages/graphql/test/core/raw_operation_data_test.dart @@ -0,0 +1,125 @@ +import 'package:graphql/src/core/raw_operation_data.dart'; +import 'package:test/test.dart'; + +void main() { + group('operation name', () { + group('single operation', () { + test('query without name', () { + final opData = RawOperationData( + document: 'query {}', + ); + + expect(opData.operationName, null); + }); + + test('query with explicit name', () { + final opData = RawOperationData( + document: 'query Operation {}', + operationName: 'Operation', + ); + + expect(opData.operationName, 'Operation'); + }); + + test('mutation with explicit name', () { + final opData = RawOperationData( + document: 'mutation Operation {}', + operationName: 'Operation', + ); + + expect(opData.operationName, 'Operation'); + }); + + test('subscription with explicit name', () { + final opData = RawOperationData( + document: 'subscription Operation {}', + operationName: 'Operation', + ); + + expect(opData.operationName, 'Operation'); + }); + + test('query with implicit name', () { + final opData = RawOperationData( + document: 'query Operation {}', + ); + + expect(opData.operationName, 'Operation'); + }); + + test('mutation with implicit name', () { + final opData = RawOperationData( + document: 'mutation Operation {}', + ); + + expect(opData.operationName, 'Operation'); + }); + + test('subscription with implicit name', () { + final opData = RawOperationData( + document: 'subscription Operation {}', + ); + + expect(opData.operationName, 'Operation'); + }); + }); + group('multiple operations', () { + const document = r''' + query OperationQ {} + mutation OperationM {} + subscription OperationS {} + '''; + + test('query with explicit name', () { + final opData = RawOperationData( + document: document, + operationName: 'OperationQ', + ); + + expect(opData.operationName, 'OperationQ'); + }); + + test('mutation with explicit name', () { + final opData = RawOperationData( + document: document, + operationName: 'OperationM', + ); + + expect(opData.operationName, 'OperationM'); + }); + + test('subscription with explicit name', () { + final opData = RawOperationData( + document: document, + operationName: 'OperationS', + ); + + expect(opData.operationName, 'OperationS'); + }); + + test('query with implicit name', () { + final opData = RawOperationData( + document: document, + ); + + expect(opData.operationName, 'OperationS'); + }); + + test('mutation with implicit name', () { + final opData = RawOperationData( + document: document, + ); + + expect(opData.operationName, 'OperationS'); + }); + + test('subscription with implicit name', () { + final opData = RawOperationData( + document: document, + ); + + expect(opData.operationName, 'OperationS'); + }); + }); + }); +} From 8aa69ef697cc988573d4bf51b7dca63d5f26ccac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kl=C4=81vs=20Pried=C4=ABtis?= Date: Mon, 7 Oct 2019 22:32:44 +0300 Subject: [PATCH 2/2] style(client): newline between groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Klāvs Priedītis --- packages/graphql/test/core/raw_operation_data_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/graphql/test/core/raw_operation_data_test.dart b/packages/graphql/test/core/raw_operation_data_test.dart index 402645605..f0eba904d 100644 --- a/packages/graphql/test/core/raw_operation_data_test.dart +++ b/packages/graphql/test/core/raw_operation_data_test.dart @@ -63,6 +63,7 @@ void main() { expect(opData.operationName, 'Operation'); }); }); + group('multiple operations', () { const document = r''' query OperationQ {}