Skip to content

Commit

Permalink
Add integration test for news article using GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
brucebolt committed Dec 2, 2024
1 parent fcaf496 commit 82c4a18
Showing 1 changed file with 212 additions and 0 deletions.
212 changes: 212 additions & 0 deletions spec/integration/graphql/news_article_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
RSpec.describe "GraphQL" do
describe "news article" do
before do
@edition = create(
:live_edition,
title: "Generic news article",
base_path: "/government/news/announcement",
document_type: "news_story",
details: {
body: "Some text",
},
)

@government = create(
:live_edition,
document_type: "government",
)

@organisation = create(
:live_edition,
document_type: "organisation",
)

@person = create(
:live_edition,
document_type: "person",
)

@topical_event = create(
:live_edition,
document_type: "topical_event",
)

@world_location = create(
:live_edition,
document_type: "world_location",
)

@parent_taxon = create(
:live_edition,
document_type: "taxon",
)

@child_taxon = create(
:live_edition,
document_type: "taxon",
)

create(:link_set,
content_id: @child_taxon.document.content_id,
links_hash: {
parent_taxons: [
@parent_taxon.document.content_id,
],
})

create(:link_set,
content_id: @edition.document.content_id,
links_hash: {
government: [
@government.document.content_id,
],
organisations: [
@organisation.document.content_id,
],
people: [
@person.document.content_id,
],
taxons: [
@child_taxon.document.content_id,
],
topical_events: [
@topical_event.document.content_id,
],
world_locations: [
@world_location.document.content_id,
],
})
end

it "exposes news article specific fields in addition to generic edition fields" do
post "/graphql", params: {
query: <<~QUERY,
{
edition(
basePath: "/government/news/announcement",
contentStore: "live",
) {
... on Edition {
}
... on NewsArticle {
links {
availableTranslations {
basePath
locale
}
government {
details {
current
}
title
}
organisations {
basePath
title
}
people {
basePath
title
}
taxons {
basePath
contentId
title
links {
parentTaxons {
basePath
contentId
title
}
}
}
topicalEvents {
basePath
title
}
worldLocations {
basePath
title
}
}
basePath
title
details
}
}
}
QUERY
}

expected = {
data: {
edition: {
basePath: @edition.base_path,
details: {
body: @edition.details[:body],
},
links: {
availableTranslations: [
{
basePath: @edition.base_path,
locale: @edition.locale,
},
],
government: [
{
details: {
current: @government.details["current"],
},
title: @government.title,
},
],
organisations: [
{
basePath: @organisation.base_path,
title: @organisation.title,
},
],
people: [
{
basePath: @person.base_path,
title: @person.title,
},
],
taxons: [
{
basePath: @child_taxon.base_path,
contentId: @child_taxon.content_id,
title: @child_taxon.title,
links: {
parentTaxons: [
{
basePath: @parent_taxon.base_path,
contentId: @parent_taxon.content_id,
title: @parent_taxon.title,
},
],
},
},
],
topicalEvents: [
{
basePath: @topical_event.base_path,
title: @topical_event.title,
},
],
worldLocations: [
{
basePath: @world_location.base_path,
title: @world_location.title,
},
],
},
title: @edition.title,
},
},
}

expect(JSON.parse(response.body).deep_symbolize_keys).to eq(expected)
end
end
end

0 comments on commit 82c4a18

Please sign in to comment.