-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for GraphQL dataloader
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
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,18 @@ | ||
RSpec.describe Sources::LinkedToEditionsSource do | ||
it "returns the specified link set links" do | ||
source_document = create(:edition) | ||
target_document_1 = create(:edition) | ||
target_document_2 = create(:edition) | ||
target_document_3 = create(:edition) | ||
link_set = create(:link_set, content_id: source_document.content_id) | ||
create(:link, link_set: link_set, target_content_id: target_document_1.content_id, link_type: "test_link") | ||
create(:link, link_set: link_set, target_content_id: target_document_2.content_id, link_type: "another_link_type") | ||
create(:link, link_set: link_set, target_content_id: target_document_3.content_id, link_type: "test_link") | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: source_document).request("test_link") | ||
|
||
expect(request.load).to eq([target_document_1, target_document_3]) | ||
end | ||
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,19 @@ | ||
RSpec.describe Sources::PersonCurrentRolesSource do | ||
include MinistersIndexHelpers | ||
|
||
it "returns the current roles for a person" do | ||
person_1 = create_person("Person 1") | ||
role_1 = create_role("Role 1") | ||
role_2 = create_role("Role 2") | ||
role_3 = create_role("Role 3") | ||
appoint_person_to_role(person_1, role_1) | ||
appoint_person_to_role(person_1, role_2, current: false) | ||
appoint_person_to_role(person_1, role_3) | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class).request(person_1.content_id) | ||
|
||
expect(request.load).to eq([role_1, role_3]) | ||
end | ||
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