Skip to content

Commit

Permalink
test that we can use #assert_fail without a contract errors list.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 12, 2024
1 parent 8bfc4f6 commit 821a870
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ def model(ctx, params:, **)
result = assert_fail Update, {params: {title: nil}}, [:title]
assert_equal CU.inspect(result[:"contract.default"].errors.messages), %({:title=>[\"is missing\"]})
end

# test_0011_anonymous
# {#assert_fail} can be used without contract errors.
it do
operation = Class.new(Trailblazer::Operation) do
step ->(ctx, **) { false }
end

result = assert_fail operation, {params: {title: nil}}

assert_equal result.keys.inspect, %([:params])
end
end

test_1 = test.new(:test_0001_anonymous)
Expand Down Expand Up @@ -330,6 +342,10 @@ def model(ctx, params:, **)
test_10 = test.new(:test_0010_anonymous)
failures = test_10.()
assert_equal failures.size, 0

test_11 = test.new(:test_0011_anonymous)
failures = test_11.()
assert_equal failures.size, 0
end
end

Expand Down Expand Up @@ -443,12 +459,14 @@ def self.__(activity, options, &block) # TODO: move this to endpoint.
return signal, ctx # DISCUSS: should we provide a Result object here?
end

it "{Activity} invoked via endpoint" do
it "{#assert_pass} {Activity} invoked via endpoint" do
ctx = assert_pass Create, {params: {title: "Roxanne"}},
title: "Roxanne"

assert_equal ctx[:object].title, "Roxanne" # aliasing only works through endpoint.
end

it "{#assert_fail} with activity via endpoint" do
ctx = assert_fail Create, {params: {}}, [:title]

assert_equal ctx.class, Trailblazer::Context::Container::WithAliases
Expand Down

0 comments on commit 821a870

Please sign in to comment.