Skip to content

Commit

Permalink
Test order of linked-to editions in dataloader
Browse files Browse the repository at this point in the history
We removed an implicit assertion on this from other tests which had
broken following the introduction of a UNION, so we're testing the
impact of the ORDER more explicitly here

Co-authored-by: Mike Patrick <mike.patrick2@digital.cabinet-office.gov.uk>
  • Loading branch information
yndajas and mike3985 committed Mar 6, 2025
1 parent f9eea7a commit e5cf81b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/graphql/sources/linked_to_editions_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,32 @@
expect(request.load).to match_array([target_edition_3, target_edition_4])
end
end

it "returns editions in order of their associated link's `position`" do
target_edition_0 = create(:edition)
target_edition_1 = create(:edition)
target_edition_2 = create(:edition)
target_edition_3 = create(:edition)

source_edition = create(:edition, content_store: "draft")
create(:link, edition: source_edition, target_content_id: target_edition_1.content_id, position: 1, link_type: "test_link")
create(:link, edition: source_edition, target_content_id: target_edition_3.content_id, position: 3, link_type: "test_link")

link_set = create(:link_set, content_id: source_edition.content_id)
create(:link, link_set:, target_content_id: target_edition_0.content_id, position: 0, link_type: "test_link")
create(:link, link_set:, target_content_id: target_edition_2.content_id, position: 2, link_type: "test_link")

GraphQL::Dataloader.with_dataloading do |dataloader|
request = dataloader.with(
described_class,
content_store: source_edition.content_store,
).request([
source_edition,
"test_link",
%i[id base_path title document_id],
])

expect(request.load).to eq([target_edition_0, target_edition_1, target_edition_2, target_edition_3])
end
end
end

0 comments on commit e5cf81b

Please sign in to comment.