Skip to content

Commit 3370919

Browse files
committed
Add page mutations specs
Fix page update mutation
1 parent 7b3d86e commit 3370919

4 files changed

Lines changed: 122 additions & 1 deletion

File tree

api/app/graph/refinery/api/mutations/pages/page_mutations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module PageMutations
3434
resolve -> (obj, inputs, ctx) {
3535
inputs = inputs.to_h.deep_symbolize_keys
3636

37-
Refinery::Page.update(inputs[:id], inputs[:page])
37+
page = Refinery::Page.update(inputs[:id], inputs[:page])
3838

3939
{ page: page }
4040
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
module Refinery
6+
module Api
7+
module Mutations
8+
module Pages
9+
describe 'CreatePageMutation' do
10+
let(:logged_in_user) { Refinery::Core::NilUser.new }
11+
12+
let(:context) { {current_user: logged_in_user} }
13+
14+
let(:result) do
15+
GraphqlSchema.execute(
16+
query_string,
17+
context: context,
18+
variables: variables
19+
)
20+
end
21+
22+
let(:query_string) do
23+
<<-QUERY
24+
mutation($page: CreatePageInput!) {
25+
create_page(input: $page) {
26+
page {
27+
title
28+
}
29+
}
30+
}
31+
QUERY
32+
end
33+
34+
subject { result }
35+
36+
context 'as an admin' do
37+
context 'create a page' do
38+
let(:variables) do
39+
{
40+
'page' => {
41+
'page' => {
42+
'title' => 'Test page'
43+
}
44+
}
45+
}
46+
end
47+
48+
it 'returns the page title of the newly created page' do
49+
subject
50+
expect(result['data']['create_page']['page']['title']).to eq('Test page')
51+
end
52+
end
53+
end
54+
end
55+
end
56+
end
57+
end
58+
end

api/spec/graph/refinery/api/mutations/pages/page_mutations_spec.rb renamed to api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb

File renamed without changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
module Refinery
6+
module Api
7+
module Mutations
8+
module Pages
9+
describe 'UpdatePageMutation' do
10+
let(:logged_in_user) { Refinery::Core::NilUser.new }
11+
12+
let!(:page) { FactoryBot.create(:page) }
13+
14+
let(:context) { {current_user: logged_in_user} }
15+
16+
let(:result) do
17+
GraphqlSchema.execute(
18+
query_string,
19+
context: context,
20+
variables: variables
21+
)
22+
end
23+
24+
let(:query_string) do
25+
<<-QUERY
26+
mutation($page: UpdatePageInput!) {
27+
update_page(input: $page) {
28+
page {
29+
id
30+
title
31+
}
32+
}
33+
}
34+
QUERY
35+
end
36+
37+
subject { result }
38+
39+
context 'as an admin' do
40+
context 'update a page' do
41+
let(:variables) do
42+
{
43+
'page' => {
44+
'id' => page.id,
45+
'page' => {
46+
'title' => 'Updated Test page'
47+
}
48+
}
49+
}
50+
end
51+
52+
it 'returns the page id and title of the newly created page' do
53+
subject
54+
expect(result['data']['update_page']['page']['id']).to eq(page.id.to_s)
55+
expect(result['data']['update_page']['page']['title']).to eq('Updated Test page')
56+
end
57+
end
58+
end
59+
end
60+
end
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)