debian-mirror-gitlab/spec/graphql/resolvers/echo_resolver_spec.rb

29 lines
744 B
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Resolvers::EchoResolver do
2019-12-04 20:38:33 +05:30
include GraphqlHelpers
let(:current_user) { create(:user) }
let(:text) { 'Message test' }
2021-01-29 00:20:46 +05:30
specify do
expect(described_class).to have_non_null_graphql_type(::GraphQL::STRING_TYPE)
end
2019-12-04 20:38:33 +05:30
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