-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Events to GraphQL endpoint (#934)
* event and allEvents * can include the address on an event * Tests covering Event GraphQL endpoints * Can ask for `allAddressLines` or `fullStreetAddress` Co-authored-by: Dr Kim Foale <[email protected]>
- Loading branch information
1 parent
dedf9ed
commit 373d0e6
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Types | ||
class AddressType < Types::BaseObject | ||
|
||
description 'An address representing a physical location' | ||
|
||
# field :id, ID, null: false | ||
field :street_address, String | ||
field :street_address2, String | ||
field :street_address3, String | ||
field :city, String | ||
field :postcode, String | ||
field :country_code, String | ||
field :full_street_address, String | ||
field :all_address_lines, [String] | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Types | ||
class EventType < Types::BaseObject | ||
|
||
description 'An Event that is run by a Parter' | ||
|
||
field :id, ID, null: false | ||
field :description, String | ||
field :summary, String | ||
|
||
field :address, AddressType | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class GraphQLEventTest < ActionDispatch::IntegrationTest | ||
|
||
setup do | ||
@partner = FactoryBot.create(:partner) | ||
|
||
@address = @partner.address | ||
assert @address, 'Failed to create Address from partner' | ||
|
||
@calendar = FactoryBot.create( | ||
:calendar, | ||
partner: @partner, | ||
name: 'Partner Calendar', | ||
source: 'http://example.com' | ||
) | ||
assert @calendar, 'Failed to create calendar from partner' | ||
end | ||
|
||
test 'can show partners' do | ||
|
||
(0...5).collect do |n| | ||
@partner.events.create!( | ||
dtstart: Time.now, | ||
summary: "An event summary #{n}", | ||
description: 'Longer text covering the event in more detail', | ||
address: @address | ||
) | ||
end | ||
|
||
query_string = <<-GRAPHQL | ||
query { | ||
allEvents { | ||
id | ||
summary | ||
description | ||
} | ||
} | ||
GRAPHQL | ||
|
||
result = PlaceCalSchema.execute(query_string) | ||
data = result['data'] | ||
assert data.has_key?('allEvents'), 'result is missing key `allEvents`' | ||
|
||
events = data['allEvents'] | ||
assert events.length == 5 | ||
end | ||
|
||
test 'can show specific event' do | ||
event = @partner.events.create!( | ||
dtstart: Time.now, | ||
summary: "An event summary", | ||
description: 'Longer text covering the event in more detail', | ||
address: @address | ||
) | ||
|
||
query_string = <<-GRAPHQL | ||
query { | ||
event(id: #{event.id}) { | ||
id | ||
summary | ||
description | ||
address { | ||
streetAddress | ||
city | ||
postcode | ||
} | ||
} | ||
} | ||
GRAPHQL | ||
|
||
result = PlaceCalSchema.execute(query_string) | ||
|
||
data = result['data'] | ||
assert data.has_key?('event'), 'Data structure does not contain event key' | ||
|
||
data_event = data['event'] | ||
assert data_event['summary'] == event.summary | ||
end | ||
end |