11. @bradwright - GOV.UKGOV.UKDavid Heath
Publisher Frontend
content_id currently optional (maybe
required in future)
Absent
routes Routes (must be within
base_path)
Absent
redirects Only for format==’redirect’ Absent
19. @bradwright - GOV.UKGOV.UKDavid Heath
Publishing
app
Frontend
Test that this
produces the
right output
Test that this works
with a variety of valid
inputs
28. @bradwright - GOV.UKGOV.UKDavid Heath
Publisher test
jenkins-schema.sh
# Clone govuk-content-schemas dependency for contract tests
rm -rf tmp/govuk-content-schemas
git clone git@github.com:alphagov/govuk-content-schemas.git
tmp/govuk-content-schemas
cd tmp/govuk-content-schemas
git checkout $SCHEMA_GIT_COMMIT
cd ../..
# Run tests
time bundle install --path "${HOME}/bundles/${JOB_NAME}" --deployment
RAILS_ENV=test GOVUK_CONTENT_SCHEMAS_PATH=tmp/govuk-content-schemas time bundle
exec rake test:publishing_schemas --trace
29. @bradwright - GOV.UKGOV.UKDavid Heath
Publisher test
test_publishing_schemas.rake
namespace :test do
Rake::TestTask.new(:publishing_schemas => "test:prepare") do |t|
t.libs << 'test'
t.test_files = FileList['test/unit/presenters/publishing_api_presenters/*_test.rb']
end
Rake::Task['test:publishing_schemas'].comment =
"Test publishing API presenters against external schemas"
end
30. @bradwright - GOV.UKGOV.UKDavid Heath
Publisher test
test/unit/presenters/publishing_api_presenters/case_study_test.rb
test "links hash includes world locations" do
location = create(:world_location)
case_study = create(:published_case_study,
world_locations: [location])
presented_hash = present(case_study)
assert_valid_against_schema(presented_hash, 'case_study')
assert_equal [location.content_id], presented_hash[:links][:world_locations]
end
31. @bradwright - GOV.UKGOV.UKDavid Heath
Publisher test
- use govuk-content-schema-test-helpers
- define jenkins-schema.sh
- contract tests should ideally be stand-
alone (separate test file)
33. Frontend test
test/contracts/govuk_content_schemas_test.sh
class GovukContentSchemasTest < ActionDispatch::IntegrationTest
include GovukContentSchemaExamples
all_examples_for_supported_formats.each do |content_item|
test "can successfully render #{content_item['base_path']} schema example" do
content_store_has_item(content_item['base_path'], content_item)
get content_item['base_path'].sub(/^//, '')
assert_response :success
end
end
end
@bradwright - GOV.UKGOV.UKDavid Heath
34. Adding a field to a format
1. Branch govuk-content-schemas
2. Add optional field
3. Push branch, all contract tests run
4. Merge!
@bradwright - GOV.UKGOV.UKDavid Heath
36. Adding a new format
1. Branch govuk-content-schemas
2. Add schema and examples
3. Make sure publisher and frontend
tests set up
4. Push branch
@bradwright - GOV.UKGOV.UKDavid Heath