summaryrefslogtreecommitdiff
path: root/spec/graphql
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2019-08-26 17:43:38 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2019-08-26 17:43:38 +0000
commitbdd5b5b69533b8035d0a03a1d4c9de38ba3da189 (patch)
treeedd9d288399eb73d196e631e9be93d2f3de98670 /spec/graphql
parent783670c4cd980ee9394b8dd639e553cfaddf19d1 (diff)
downloadgitlab-ce-bdd5b5b69533b8035d0a03a1d4c9de38ba3da189.tar.gz
Replace echo function with a resolver
The `GraphQL::Function` has been deprecated in favor of resolvers.
Diffstat (limited to 'spec/graphql')
-rw-r--r--spec/graphql/resolvers/echo_resolver_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/echo_resolver_spec.rb b/spec/graphql/resolvers/echo_resolver_spec.rb
new file mode 100644
index 00000000000..466501a4227
--- /dev/null
+++ b/spec/graphql/resolvers/echo_resolver_spec.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::EchoResolver do
+ include GraphqlHelpers
+
+ let(:current_user) { create(:user) }
+ let(:text) { 'Message test' }
+
+ describe '#resolve' do
+ it 'echoes text and username' do
+ expect(resolve_echo(text)).to eq %Q("#{current_user.username}" says: #{text})
+ end
+
+ it 'echoes text and nil as username' do
+ expect(resolve_echo(text, { current_user: nil })).to eq "nil says: #{text}"
+ end
+ end
+
+ def resolve_echo(text, context = { current_user: current_user })
+ resolve(described_class, obj: nil, args: { text: text }, ctx: context)
+ end
+end