Skip to content

Commit

Permalink
test assert_fail with endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 12, 2024
1 parent 8b50cbd commit 8bfc4f6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ class AssertionActivitySuiteTest < Minitest::Spec
end
end

class EndpointTest < Minitest::Spec
require "trailblazer/endpoint"
class EndpointWithActivityTest < Minitest::Spec
Record = AssertionsTest::Record
Create = AssertionActivityTest::Create

Expand All @@ -413,13 +414,17 @@ class EndpointTest < Minitest::Spec

module Endpoint
def assert_pass(*args, **options, &block)
super(*args, **options, invoke: method(:__), &block)
super(*args, **options, invoke: EndpointWithActivityTest.method(:__), &block)
end

def assert_fail(*args, **options, &block)
super(*args, **options, invoke: EndpointWithActivityTest.method(:__), &block)
end
end
include Endpoint


def _flow_options
def self._flow_options
{
context_options: {
aliases: {"model": :object},
Expand All @@ -428,7 +433,7 @@ def _flow_options
}
end

def __(activity, options, &block) # TODO: move this to endpoint.
def self.__(activity, options, &block) # TODO: move this to endpoint.
signal, (ctx, flow_options) = Trailblazer::Endpoint::Runtime.(
activity, options,
flow_options: _flow_options(),
Expand All @@ -438,12 +443,15 @@ def __(activity, options, &block) # TODO: move this to endpoint.
return signal, ctx # DISCUSS: should we provide a Result object here?
end

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

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

ctx = assert_fail Create, {params: {}}, [:title]

assert_equal ctx.class, Trailblazer::Context::Container::WithAliases
end
end

0 comments on commit 8bfc4f6

Please sign in to comment.