-
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.
Allow client to request only current role appointments
The prime minister page does not need the former role appointments to render, so there is no need to retrieve them. By adding an argument to the `role_appointments` link field, we can reduce the number of documents whose links need to be further expanded. An index for editions with a current value in the details was added in e1b1955.
- Loading branch information
Showing
4 changed files
with
115 additions
and
44 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
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
119 changes: 86 additions & 33 deletions
119
spec/graphql/sources/reverse_linked_to_editions_source_spec.rb
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 |
---|---|---|
@@ -1,45 +1,98 @@ | ||
RSpec.describe Sources::ReverseLinkedToEditionsSource do | ||
it "returns the specified reverse link set links" do | ||
target_edition = create(:edition) | ||
source_edition_1 = create(:edition) | ||
source_edition_2 = create(:edition) | ||
source_edition_3 = create(:edition) | ||
link_set_1 = create(:link_set, content_id: source_edition_1.content_id) | ||
link_set_2 = create(:link_set, content_id: source_edition_2.content_id) | ||
link_set_3 = create(:link_set, content_id: source_edition_3.content_id) | ||
create(:link, link_set: link_set_1, target_content_id: target_edition.content_id, link_type: "test_link") | ||
create(:link, link_set: link_set_2, target_content_id: target_edition.content_id, link_type: "another_link_type") | ||
create(:link, link_set: link_set_3, target_content_id: target_edition.content_id, link_type: "test_link") | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: target_edition).request("test_link") | ||
|
||
expect(request.load).to eq([source_edition_1, source_edition_3]) | ||
context "when only_current is not set" do | ||
it "returns the specified reverse link set links" do | ||
target_edition = create(:edition) | ||
source_edition_1 = create(:edition) | ||
source_edition_2 = create(:edition) | ||
source_edition_3 = create(:edition) | ||
link_set_1 = create(:link_set, content_id: source_edition_1.content_id) | ||
link_set_2 = create(:link_set, content_id: source_edition_2.content_id) | ||
link_set_3 = create(:link_set, content_id: source_edition_3.content_id) | ||
create(:link, link_set: link_set_1, target_content_id: target_edition.content_id, link_type: "test_link") | ||
create(:link, link_set: link_set_2, target_content_id: target_edition.content_id, link_type: "another_link_type") | ||
create(:link, link_set: link_set_3, target_content_id: target_edition.content_id, link_type: "test_link") | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: target_edition).request("test_link") | ||
|
||
expect(request.load).to eq([source_edition_1, source_edition_3]) | ||
end | ||
end | ||
|
||
it "returns the specified reverse edition links" do | ||
target_edition = create(:edition) | ||
|
||
source_edition_1 = create(:edition, | ||
links_hash: { | ||
"test_link" => [target_edition.content_id], | ||
}) | ||
|
||
source_edition_2 = create(:edition, | ||
links_hash: { | ||
"test_link" => [target_edition.content_id], | ||
}) | ||
|
||
create(:edition, | ||
links_hash: { | ||
"another_link_type" => [target_edition.content_id], | ||
}) | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: target_edition).request("test_link") | ||
|
||
expect(request.load).to eq([source_edition_1, source_edition_2]) | ||
end | ||
end | ||
end | ||
|
||
it "returns the specified reverse edition links" do | ||
target_edition = create(:edition) | ||
context "when only_current is set" do | ||
it "returns the specified reverse link set links for current role appointments only" do | ||
target_edition = create(:edition) | ||
source_edition_1 = create(:edition, details: { current: true }) | ||
source_edition_2 = create(:edition, details: { current: true }) | ||
source_edition_3 = create(:edition, details: { current: false }) | ||
link_set_1 = create(:link_set, content_id: source_edition_1.content_id) | ||
link_set_2 = create(:link_set, content_id: source_edition_2.content_id) | ||
link_set_3 = create(:link_set, content_id: source_edition_3.content_id) | ||
create(:link, link_set: link_set_1, target_content_id: target_edition.content_id, link_type: "test_link") | ||
create(:link, link_set: link_set_2, target_content_id: target_edition.content_id, link_type: "another_link_type") | ||
create(:link, link_set: link_set_3, target_content_id: target_edition.content_id, link_type: "test_link") | ||
|
||
source_edition_1 = create(:edition, | ||
links_hash: { | ||
"test_link" => [target_edition.content_id], | ||
}) | ||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: target_edition, only_current: true).request("test_link") | ||
|
||
expect(request.load).to eq([source_edition_1]) | ||
end | ||
end | ||
|
||
source_edition_2 = create(:edition, | ||
links_hash: { | ||
"test_link" => [target_edition.content_id], | ||
}) | ||
it "returns the specified reverse edition links for current role appointments only" do | ||
target_edition = create(:edition) | ||
|
||
create(:edition, | ||
links_hash: { | ||
"another_link_type" => [target_edition.content_id], | ||
}) | ||
source_edition_1 = create(:edition, | ||
details: { current: true }, | ||
links_hash: { | ||
"test_link" => [target_edition.content_id], | ||
}) | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: target_edition).request("test_link") | ||
create(:edition, | ||
details: { current: false }, | ||
links_hash: { | ||
"test_link" => [target_edition.content_id], | ||
}) | ||
|
||
expect(request.load).to eq([source_edition_1, source_edition_2]) | ||
create(:edition, | ||
details: { current: true }, | ||
links_hash: { | ||
"another_link_type" => [target_edition.content_id], | ||
}) | ||
|
||
GraphQL::Dataloader.with_dataloading do |dataloader| | ||
request = dataloader.with(described_class, parent_object: target_edition, only_current: true).request("test_link") | ||
|
||
expect(request.load).to eq([source_edition_1]) | ||
end | ||
end | ||
|
||
## TODO: add a test for retrieving from the right content store | ||
end | ||
end |