-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from alphagov/test-repo
Add a basic integration test
- Loading branch information
Showing
3 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
spec/support/publishing_event_pipeline/repositories/test_repository.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |