Skip to content

Commit

Permalink
Added delete meeting mutation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jul 9, 2018
1 parent 2a70b7e commit 11c324a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2018-07-09 16:29:54 -0400 using RuboCop version 0.57.2. # on 2018-07-09 17:47:57 -0400 using RuboCop version 0.57.2.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
Expand All @@ -11,14 +11,15 @@ Style/DateTime:
Exclude: Exclude:
- 'spec/graphql/mutations/create_meeting_mutation_spec.rb' - 'spec/graphql/mutations/create_meeting_mutation_spec.rb'


# Offense count: 6 # Offense count: 7
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.
# SupportedStyles: line_count_dependent, lambda, literal # SupportedStyles: line_count_dependent, lambda, literal
Style/Lambda: Style/Lambda:
Exclude: Exclude:
- 'app/graphql/mutations/create_meeting_mutation.rb' - 'app/graphql/mutations/create_meeting_mutation.rb'
- 'app/graphql/mutations/create_user_mutation.rb' - 'app/graphql/mutations/create_user_mutation.rb'
- 'app/graphql/mutations/delete_meeting_mutation.rb'
- 'app/graphql/mutations/login_mutation.rb' - 'app/graphql/mutations/login_mutation.rb'
- 'app/graphql/mutations/logout_mutation.rb' - 'app/graphql/mutations/logout_mutation.rb'
- 'app/graphql/types/query_type.rb' - 'app/graphql/types/query_type.rb'
Expand Down
22 changes: 22 additions & 0 deletions app/graphql/mutations/delete_meeting_mutation.rb
@@ -0,0 +1,22 @@
Mutations::DeleteMeetingMutation = GraphQL::Relay::Mutation.define do
name 'deleteMeeting'

input_field :id, !types.ID

return_field :deletedId, !types.ID

resolve ->(_object, inputs, ctx) {
user = ctx[:current_user]
if user
meeting = user.meetings.find(inputs[:id])
if meeting
meeting.destroy!
{
deletedId: meeting.id
}
end
else
GraphQL::ExecutionError.new('Not logged in.')
end
}
end
1 change: 1 addition & 0 deletions app/graphql/types/mutation_type.rb
Expand Up @@ -6,4 +6,5 @@
field :logout, field: Mutations::LogoutMutation.field field :logout, field: Mutations::LogoutMutation.field


field :createMeeting, field: Mutations::CreateMeetingMutation.field field :createMeeting, field: Mutations::CreateMeetingMutation.field
field :deleteMeeting, field: Mutations::DeleteMeetingMutation.field
end end
33 changes: 33 additions & 0 deletions spec/graphql/mutations/delete_meeting_mutation_spec.rb
@@ -0,0 +1,33 @@
require 'rails_helper'

describe 'Delete Meeting', type: :request do
include_context 'Authenticated Client'

let!(:meeting) { Fabricate(:meeting, user: current_user) }

let(:query) do
<<-GRAPHQL
mutation($input: deleteMeetingInput!) {
deleteMeeting(input: $input) {
deletedId
}
}
GRAPHQL
end

let(:title) { Faker::Company.buzzword }
let(:started_at) { Faker::Time.backward(1) }
let(:finished_at) { Time.now }

it 'returns an meeting' do
expect do
response = client.execute(
query, input: {
id: meeting.id.to_s
}
)
meeting_id = response.data.delete_meeting.deleted_id
expect(meeting_id).to eq meeting.id.to_s
end.to change(Meeting, :count).by(-1)
end
end

0 comments on commit 11c324a

Please sign in to comment.