Permalink
Browse files

Added delete meeting mutation.

  • Loading branch information...
dblock committed Jul 9, 2018
1 parent 2a70b7e commit 11c324a5be457edcfc3b09a94d3f326633b22c16
@@ -1,6 +1,6 @@
# This configuration was generated by
# `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
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -11,14 +11,15 @@ Style/DateTime:
Exclude:
- 'spec/graphql/mutations/create_meeting_mutation_spec.rb'

# Offense count: 6
# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: line_count_dependent, lambda, literal
Style/Lambda:
Exclude:
- 'app/graphql/mutations/create_meeting_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/logout_mutation.rb'
- 'app/graphql/types/query_type.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
@@ -6,4 +6,5 @@
field :logout, field: Mutations::LogoutMutation.field

field :createMeeting, field: Mutations::CreateMeetingMutation.field
field :deleteMeeting, field: Mutations::DeleteMeetingMutation.field
end
@@ -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.