Skip to content

Commit

Permalink
Add page mutations specs
Browse files Browse the repository at this point in the history
Fix page update mutation
  • Loading branch information
bricesanchez committed Nov 30, 2017
1 parent 7b3d86e commit 3370919
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3370919

Please sign in to comment.