Skip to content

Commit

Permalink
Add publishing smoke test
Browse files Browse the repository at this point in the history
This commit adds a smoke test for Publisher to test the entire journey from creating a new piece of content through to unpublishing. Specifically, three separate scenarios create a new draft `Place` on the draft stack, publish this draft to the live stack, before finally proceeding to unpublish the content.

One of the requirements this smoke test needs to fulfil is to ensure that multiple runs of Smokey can operate in parallel, which is important as it means that we need to dynamically generate the slug we're specifying for the content we're creating (done using `SecureRandom.hex`).

Another complication has been that because we're using separate scenarios to encapsulate the main steps of the test (create draft, publish to live, unpublish), we have had to introduce state which can be shared across these scenarios. Specifically, the state being shared is the unique piece of content that we have created in any one test run (`Smokey test draft place #{SecureRandom.hex}`), so that each scenario of the test can work from where the previous scenario left off. This can be seen by the global variable `$smokey_run_id` in the new `Given` block `I have the smokey run identifier`. I'm aware that [chaining scenarios together can make them difficult to maintain](https://specflow.org/challenges/chain-of-dependent-scenarios), however having each of these steps as a separate scenarios feels to me to be the most sensible approach, whilst the single global variable could also be of use to future tests which need to satisfy a similar requirement.

This test will not run on existing production and will not run on the new replatformed production when it's ready, as it has been given the tag `@replatformingnotproduction` (where the Smokey run for each environment by Concourse will exclude tags matching `@replatformingnot<environment>`).
  • Loading branch information
karlbaker02 committed Jun 10, 2021
1 parent 3c51ad0 commit fd0e410
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
34 changes: 34 additions & 0 deletions features/publisher.feature
Expand Up @@ -7,3 +7,37 @@ Feature: (Mainstream) Publisher
When I request "/healthcheck/ready"
Then JSON is returned
And I should see ""status":"ok""

@notproduction
Scenario: Can create a draft place
Given I have the smokey run identifier
When I try to login as a user
And I go to the "publisher" landing page
And I go to add an artefact
And I create a draft place
And I preview the draft place
Then I should see that the content has been published

@notproduction
Scenario: Can publish a draft place to live
Given I have the smokey run identifier
When I try to login as a user
And I go to the "publisher" landing page
And I search for the content in category "Drafts"
And I go to the content from the search results
And I request 2nd pair of eyes
And I skip the review
And I publish the draft
And I view the published content on live
Then I should see that the content has been published

@notproduction
Scenario: Can unpublish a live place
Given I have the smokey run identifier
When I try to login as a user
And I go to the "publisher" landing page
And I search for the content in category "Published"
And I go to the content from the search results
And I go to the "Unpublish" section
And I unpublish the edition
Then I should see that the content has been unpublished
113 changes: 113 additions & 0 deletions features/step_definitions/publisher_steps.rb
@@ -0,0 +1,113 @@
When "I go to add an artefact" do
click_on "Add artefact"
expect(page).to have_content("New artefact")
end

When "I create a draft place" do
fill_in "Title", with: publication_title
fill_in "Slug", with: parameterize(publication_title)
select "Place", from: "Format"
click_button "Save and go to item"
end

When "I preview the draft place" do
click_on "Preview"

wait_until do
visit page.current_url
page.has_no_text?(:all, /not found/i)
end
end

When "I should see that the content has been published" do
expect(page).to have_content(publication_title)
expect(page.current_path).to eq(publication_path)
expect(page).to_not have_content("GOV.UK Publisher")
end

When /I search for the content in category "([^"]*)"/ do |status|
select "Nobody", from: "Assignee"
fill_in "Keyword", with: publication_title
select "Place", from: "Format"
click_button "Filter publications"
click_link status
end

When "I go to the content from the search results" do
click_link publication_title
end

When "I request 2nd pair of eyes" do
click_on "2nd pair of eyes"
click_on "Send to 2nd pair of eyes"
end

When "I skip the review" do
click_on "Skip review"

within "#skip_review_form" do
click_on "Skip review"
end

wait_until { find('span[title="Status"]').text == "Ready" }
end

When "I publish the draft" do
click_on "Publish"
click_on "Send to publish"
end

When "I view the published content on live" do
click_on "View this on the GOV.UK website"

wait_until do
visit_path publication_url
page.has_no_text?(:all, /not found/i)
end
end

When /I go to the "([^"]*)" section/ do |section|
click_link section
end

When "I unpublish the edition" do
accept_alert do
click_button "Unpublish"
end
end

When "I should see that the content has been unpublished" do
expect(page).to have_content("Content unpublished")

wait_until do
visit_path publication_url
page.has_text?(:all, /gone/i)
end
end

def parameterize(str)
str.downcase.gsub(/\s/,'-')
end

def publication_title
@publication_title ||= "Smokey test draft place #{$smokey_run_id}"
@publication_title
end

def publication_path
@publication_path ||= "/#{parameterize(publication_title)}"
@publication_path
end

def publication_url
@publication_url ||= "#{ENV['GOVUK_WEBSITE_ROOT']}#{publication_path}"
@publication_url
end

def page_contains_no_error?(error)
visit page.current_url

if page.has_no_content?(error)
return true
end
end
4 changes: 4 additions & 0 deletions features/step_definitions/smokey_steps.rb
Expand Up @@ -39,6 +39,10 @@
@authenticated_as_client = true
end

Given /^I have the smokey run identifier$/ do
$smokey_run_id ||= SecureRandom.hex
end

And /^I consent to cookies$/ do
visit_path "/"
click_button "Accept"
Expand Down

0 comments on commit fd0e410

Please sign in to comment.