Last active
October 5, 2018 02:51
-
-
Save RobertWSaunders/884f3d2b05ca21f1c0cefec56b3440f2 to your computer and use it in GitHub Desktop.
Revisions
-
RobertWSaunders renamed this gist
Oct 5, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
RobertWSaunders revised this gist
Jun 22, 2018 . No changes.There are no files selected for viewing
-
RobertWSaunders revised this gist
Jun 22, 2018 . 1 changed file with 78 additions and 78 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,112 +2,112 @@ require 'pry' module GraphQLTestHelper def on_mutation(args: {}, &mutation_tests_block) mutation, response = mutation_query(args: args, &mutation_tests_block) puts mutation.selections # [{:script_tag=>[:src, :display_scope]}] MutationEvaluator.new(self, response) do @mutation = mutation instance_exec(&mutation_tests_block) end end private def mutation_query(args: {}, &mutation_tests_block) mutation = MutationGenerator.new(args, &mutation_tests_block) response = Requestor.new(mutation).response [mutation, response] end end class ScriptTagCreateTest include GraphQLTestHelper def test on_mutation args: { input: { src: "https://hello.com/bar.js" }} do assert_no_errors assert_no_user_errors on_return_field :script_tag do assert_field "https://hello.com/bar.js", :src assert_field "ONLINE_STORE", :display_scope end end end end class MutationGenerator attr_accessor :selections def initialize(args, &mutation_tests_block) @args = args @selections = [] instance_exec(&mutation_tests_block) # continue to create the mutation like normal using selections and passed in args end def assert_field(expected, field_name) @current_selection[@current_field_name].push(field_name.to_sym) end def on_return_field(field_name, &field_assertions) @current_selection = Hash.new @current_field_name = field_name @current_selection[@current_field_name] = [] instance_exec(&field_assertions) @selections.push(@current_selection) end def assert_no_user_errors # no op end def assert_no_errors # no op end end class MutationEvaluator def initialize(execution_context, response, &block) @execution_context = execution_context @response = response #... instance_exec(&block) end def assert_no_errors #... end def assert_no_user_errors #... end def on_return_field(field_name, &block) #... end def assert_field(field_name, expected = nil, &block) #... end end class Requestor attr_accessor :response def initialize(mutation) @query = mutation @response = "my response" #... end end script_tag_test = ScriptTagCreateTest.new -
RobertWSaunders revised this gist
Jun 22, 2018 . No changes.There are no files selected for viewing
-
RobertWSaunders revised this gist
Jun 22, 2018 . No changes.There are no files selected for viewing
-
RobertWSaunders created this gist
Jun 22, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ require 'pry' module GraphQLTestHelper def on_mutation(args: {}, &mutation_tests_block) mutation, response = mutation_query(args: args, &mutation_tests_block) puts mutation.selections # [{:script_tag=>[:src, :display_scope]}] MutationEvaluator.new(self, response) do @mutation = mutation instance_exec(&mutation_tests_block) end end private def mutation_query(args: {}, &mutation_tests_block) mutation = MutationGenerator.new(args, &mutation_tests_block) response = Requestor.new(mutation).response [mutation, response] end end class ScriptTagCreateTest include GraphQLTestHelper def test on_mutation args: { input: { src: "https://hello.com/bar.js" }} do assert_no_errors assert_no_user_errors on_return_field :script_tag do assert_field "https://hello.com/bar.js", :src assert_field "ONLINE_STORE", :display_scope end end end end class MutationGenerator attr_accessor :selections def initialize(args, &mutation_tests_block) @args = args @selections = [] instance_exec(&mutation_tests_block) # continue to create the mutation like normal using selections and passed in args end def assert_field(expected, field_name) @current_selection[@current_field_name].push(field_name.to_sym) end def on_return_field(field_name, &field_assertions) @current_selection = Hash.new @current_field_name = field_name @current_selection[@current_field_name] = [] instance_exec(&field_assertions) @selections.push(@current_selection) end def assert_no_user_errors # no op end def assert_no_errors # no op end end class MutationEvaluator def initialize(execution_context, response, &block) @execution_context = execution_context @response = response #... instance_exec(&block) end def assert_no_errors #... end def assert_no_user_errors #... end def on_return_field(field_name, &block) #... end def assert_field(field_name, expected = nil, &block) #... end end class Requestor attr_accessor :response def initialize(mutation) @query = mutation @response = "my response" #... end end script_tag_test = ScriptTagCreateTest.new script_tag_test.test