Skip to content

Commit

Permalink
simulate a failing service in test app
Browse files Browse the repository at this point in the history
  • Loading branch information
swiknaba committed May 15, 2024
1 parent ba4f7ec commit 06ca7bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions spec/test_app/app/services/airports/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Filter
).returns(Kirei::Services::Result[T::Array[Airport]])
end
def self.call(search)
return test_errors if test_failure? # simulate a failure for testing purposes
return Kirei::Services::Result.new(result: Airport.all) if search.nil?

#
Expand All @@ -23,5 +24,20 @@ def self.call(search)

Kirei::Services::Result.new(result: Airport.resolve(query))
end

sig { returns(T::Boolean) }
def self.test_failure?
Kernel.rand < 0.3 ? true : false
end

sig { returns(Kirei::Services::Result[T::Array[Airport]]) }
def self.test_errors
err = Kirei::Errors::JsonApiError.new(
code: "500",
detail: "Service failed",
)

Kirei::Services::Result.new(errors: [err])
end
end
end
4 changes: 2 additions & 2 deletions spec/test_app/sorbet/rbi/gems/kirei@0.3.0.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 06ca7bd

Please sign in to comment.