From 3370919cbc8d60cfe37238e3495a03566d9050ae Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 29 Nov 2017 22:00:52 -0500 Subject: [PATCH] Add page mutations specs Fix page update mutation --- .../api/mutations/pages/page_mutations.rb | 2 +- .../pages/create_page_mutation_spec.rb | 58 +++++++++++++++++ ...s_spec.rb => delete_page_mutation_spec.rb} | 0 .../pages/update_page_mutation_spec.rb | 63 +++++++++++++++++++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb rename api/spec/graph/refinery/api/mutations/pages/{page_mutations_spec.rb => delete_page_mutation_spec.rb} (100%) create mode 100644 api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb diff --git a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb index 42d2e3d8f2..8d9565ff18 100644 --- a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb +++ b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb @@ -34,7 +34,7 @@ module PageMutations resolve -> (obj, inputs, ctx) { inputs = inputs.to_h.deep_symbolize_keys - Refinery::Page.update(inputs[:id], inputs[:page]) + page = Refinery::Page.update(inputs[:id], inputs[:page]) { page: page } } diff --git a/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb new file mode 100644 index 0000000000..53d5723233 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'CreatePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: CreatePageInput!) { + create_page(input: $page) { + page { + title + } + } +} + QUERY + end + + subject { result } + + context 'as an admin' do + context 'create a page' do + let(:variables) do + { + 'page' => { + 'page' => { + 'title' => 'Test page' + } + } + } + end + + it 'returns the page title of the newly created page' do + subject + expect(result['data']['create_page']['page']['title']).to eq('Test page') + end + end + end + end + end + end + end +end diff --git a/api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb similarity index 100% rename from api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb rename to api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb diff --git a/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb new file mode 100644 index 0000000000..cb6ea0b5b2 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'UpdatePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: UpdatePageInput!) { + update_page(input: $page) { + page { + id + title + } + } +} + QUERY + end + + subject { result } + + context 'as an admin' do + context 'update a page' do + let(:variables) do + { + 'page' => { + 'id' => page.id, + 'page' => { + 'title' => 'Updated Test page' + } + } + } + end + + it 'returns the page id and title of the newly created page' do + subject + expect(result['data']['update_page']['page']['id']).to eq(page.id.to_s) + expect(result['data']['update_page']['page']['title']).to eq('Updated Test page') + end + end + end + end + end + end + end +end