Skip to content

Commit

Permalink
Add shared workflow_base specs
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Oct 25, 2024
1 parent b5bea48 commit 5c48568
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
25 changes: 25 additions & 0 deletions spec/shared/workflow_base_shared.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
shared_examples_for "WorkflowBase" do
it "raises an exception for missing States field" do
payload = {"StartAt" => "Missing"}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"States\"")
end

it "raises an exception for missing StartAt field" do
payload = {"States" => {"First" => {"Type" => "Succeed"}}}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"StartAt\"")
end

it "raises an exception if StartAt isn't in States" do
payload = {"StartAt" => "First", "States" => {"Second" => {"Type" => "Succeed"}}}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "Map field \"StartAt\" value \"First\" is not found in \"States\"")
end

it "raises an exception if a Next state isn't in States" do
payload = {"StartAt" => "First", "States" => {"First" => {"Type" => "Pass", "Next" => "Last"}}}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "States.First field \"Next\" value \"Last\" is not found in \"States\"")
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
end

Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
Dir['./spec/shared/**/*.rb'].sort.each { |f| require f }

# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
Expand Down
3 changes: 3 additions & 0 deletions spec/workflow/branch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.describe Floe::Workflow::Branch do
include_examples "WorkflowBase"
end
24 changes: 1 addition & 23 deletions spec/workflow/item_processor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
RSpec.describe Floe::Workflow::ItemProcessor do
it "raises an exception for missing States field" do
payload = {"StartAt" => "Missing"}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"States\"")
end

it "raises an exception for missing StartAt field" do
payload = {"States" => {"First" => {"Type" => "Succeed"}}}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"StartAt\"")
end

it "raises an exception if StartAt isn't in States" do
payload = {"StartAt" => "First", "States" => {"Second" => {"Type" => "Succeed"}}}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "Map field \"StartAt\" value \"First\" is not found in \"States\"")
end

it "raises an exception if a Next state isn't in States" do
payload = {"StartAt" => "First", "States" => {"First" => {"Type" => "Pass", "Next" => "Last"}}}
expect { described_class.new(payload, ["Map"]) }
.to raise_error(Floe::InvalidWorkflowError, "States.First field \"Next\" value \"Last\" is not found in \"States\"")
end
include_examples "WorkflowBase"
end

0 comments on commit 5c48568

Please sign in to comment.