Skip to content

Commit

Permalink
Merge pull request #19 from alphagov/test-repo
Browse files Browse the repository at this point in the history
Add a basic integration test
  • Loading branch information
csutter authored Sep 26, 2023
2 parents 6a4735c + f8e464b commit 377aee4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
36 changes: 36 additions & 0 deletions spec/integration/publishing_event_pipeline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "govuk_message_queue_consumer"

RSpec.describe "Publishing event pipeline" do
let(:repository) { PublishingEventPipeline::Repositories::TestRepository.new(documents) }
let(:message) { GovukMessageQueueConsumer::MockMessage.new(payload) }

before do
PublishingEventPipeline.configure do |config|
config.repository = repository
end

PublishingEventPipeline::MessageProcessor.new.process(message)
end

describe "when a message is received that a document is published" do
let(:documents) { {} }
let(:payload) { json_fixture_as_hash("message_queue/republish_message.json") }

it "is added to the repository" do
result = repository.get("f75d26a3-25a4-4c31-beea-a77cada4ce12")
# TODO: Flesh out the document model and test that it is as expected
expect(result).to be_present
end
end

describe "when a message is received that a document is unpublished" do
let(:documents) { { "966bae6d-223e-4102-a6e5-e874012390e5" => double } }
let(:payload) { json_fixture_as_hash("message_queue/gone_message.json") }

it "is removed from the repository" do
result = repository.get("966bae6d-223e-4102-a6e5-e874012390e5")
# TODO: Flesh out the document model and test that it is as expected
expect(result).to be_nil
end
end
end
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# TODO: If the write side of this application is extracted to a separate unit, we will need to
# remove this, otherwise it can be made permanent.
require "publishing_event_pipeline"
PublishingEventPipeline.configure do |config|
config.repository = PublishingEventPipeline::Repositories::NullRepository.new
end

# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module PublishingEventPipeline
module Repositories
# A fake repository for end-to-end testing purposes
class TestRepository
attr_reader :documents

def initialize(documents = {})
@documents = documents
end

def exists?(content_id)
documents.key?(content_id)
end

def get(content_id)
documents[content_id]
end

# rubocop:disable Lint/UnusedMethodArgument
def put(content_id, document, payload_version: nil)
documents[content_id] = document
end

def delete(content_id, payload_version: nil)
documents.delete(content_id)
end
# rubocop:enable Lint/UnusedMethodArgument
end
end
end

0 comments on commit 377aee4

Please sign in to comment.