Skip to content

Commit

Permalink
test(can_have_steps): add specs for HasResult middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Jan 24, 2024
1 parent 4e64e8d commit 57b0154
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/convenient_service/service/configs/minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class self::Result
use ConvenientService::Plugins::Common::HasConstructorWithoutInitialize::Concern

use ConvenientService::Plugins::Result::HasJSendStatusAndAttributes::Concern

use ConvenientService::Plugins::Result::CanHaveStep::Concern
end

middlewares :initialize do
Expand Down
1 change: 0 additions & 1 deletion lib/convenient_service/service/configs/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class self::Result
use ConvenientService::Plugins::Common::HasJSendResultDuckShortSyntax::Concern
use ConvenientService::Plugins::Result::CanRecalculateResult::Concern

use ConvenientService::Plugins::Result::CanHaveStep::Concern
use ConvenientService::Plugins::Result::CanBeNegated::Concern
use ConvenientService::Plugins::Result::CanBeOwnResult::Concern
use ConvenientService::Plugins::Result::CanHaveFallbacks::Concern
Expand Down
1 change: 0 additions & 1 deletion lib/convenient_service/service/configs/standard/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class self::Result
use ConvenientService::Plugins::Common::HasJSendResultDuckShortSyntax::Concern
use ConvenientService::Plugins::Result::CanRecalculateResult::Concern

use ConvenientService::Plugins::Result::CanHaveStep::Concern
use ConvenientService::Plugins::Result::CanBeOwnResult::Concern
use ConvenientService::Plugins::Result::CanHaveParentResult::Concern
use ConvenientService::Plugins::Result::CanHaveCheckedStatus::Concern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Common::Plugins::HasJSendResultDuckShortSyntax::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanRecalculateResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeNegated::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveFallbacks::Concern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Common::Plugins::HasJSendResultDuckShortSyntax::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanRecalculateResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveParentResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveCheckedStatus::Concern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Common::Plugins::HasJSendResultDuckShortSyntax::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanRecalculateResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeNegated::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveFallbacks::Concern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Common::Plugins::HasJSendResultDuckShortSyntax::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanRecalculateResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveParentResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveCheckedStatus::Concern,
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/convenient_service/service/configs/minimal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasInspect::Concern,
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Common::Plugins::HasJSendResultDuckShortSyntax::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanRecalculateResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveParentResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveCheckedStatus::Concern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@
ConvenientService::Common::Plugins::HasConstructor::Concern,
ConvenientService::Common::Plugins::HasConstructorWithoutInitialize::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Common::Plugins::HasJSendResultDuckShortSyntax::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanRecalculateResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveStep::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeNegated::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeOwnResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveFallbacks::Concern,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,85 @@
##
# TODO: Specs.
##
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
RSpec.describe ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step::Plugins::HasResult::Middleware do
let(:middleware) { described_class }

example_group "inheritance" do
include ConvenientService::RSpec::PrimitiveMatchers::BeDescendantOf

subject { middleware }

it { is_expected.to be_descendant_of(ConvenientService::MethodChainMiddleware) }
end

example_group "class methods" do
describe ".intended_methods" do
let(:spec) do
Class.new(ConvenientService::MethodChainMiddleware) do
intended_for :result, entity: :step
end
end

it "returns intended methods" do
expect(middleware.intended_methods).to eq(spec.intended_methods)
end
end
end

example_group "instance methods" do
describe "#call" do
include ConvenientService::RSpec::Helpers::WrapMethod

include ConvenientService::RSpec::Matchers::CallChainNext
include ConvenientService::RSpec::Matchers::Results

subject(:method_value) { method.call }

let(:method) { wrap_method(step, :result, observe_middleware: middleware) }

let(:organizer) { container.new }
let(:step) { organizer.steps.first }

let(:container) do
Class.new.tap do |klass|
klass.class_exec(first_step, middleware) do |first_step, middleware|
include ConvenientService::Service::Configs::Minimal

self::Step.class_exec(middleware) do |middleware|
middlewares :result do
observe middleware
end
end

step first_step
end
end
end

let(:first_step) do
Class.new do
include ConvenientService::Service::Configs::Minimal

def result
success(data: {foo: :bar})
end
end
end

specify do
expect { method_value }
.to call_chain_next.on(method)
.without_arguments
end

it "returns service result with step and organizer" do
expect(step.result).to be_success.with_data(foo: :bar).of_step(first_step).of_service(container)
end
end
end
end
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers

0 comments on commit 57b0154

Please sign in to comment.