Skip to content

Commit

Permalink
Add interactor concern test
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Sep 13, 2024
1 parent 4bd9c4a commit f15a1a9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/interactors/audit_logging_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "test_helper"

class AuditLoggingTest < ActiveSupport::TestCase
def setup
@domain = domains(:owner_match)
@identity = Identity.new(subject: @domain.users_array.first)
@cr = CertIssueRequest.new(common_name: @domain.fqdn)
@log = Tempfile.new("log-test")
Rails.configuration.astral[:audit_log_file] = @log.path
end

def teardown
@log.close
@log.unlink
end

test ".call will be logged as success" do
Object.const_set("SuccessAction", Class.new do
include Interactor
include AuditLogging

def call
end
end)
rslt = SuccessAction.call(identity: @identity, request: @cr)
assert rslt.success?
assert_match %Q("action":"SuccessAction","result":"success","error":null,"subject":"[email protected]","cert_common_name":"example.com"), @log.readlines.last
end

test ".call will be logged as failure" do
Object.const_set("FailAction", Class.new do
include Interactor
include AuditLogging

def call
context.fail!
end
end)
rslt = FailAction.call(identity: @identity, request: @cr)
assert_not rslt.success?
assert_match %Q("action":"FailAction","result":"failure","error":null,"subject":"[email protected]","cert_common_name":"example.com"), @log.readlines.last
end
end
4 changes: 4 additions & 0 deletions test/lib/audit_log_formatter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require "test_helper"

class AuditLogFormatterTest < ActiveSupport::TestCase
setup do
Thread.current[:request_id] = nil
end

test "#call formats logformatter inputs as json" do
t = Time.now
result = AuditLogFormatter.new.call("info", t, nil, "some message")
Expand Down

0 comments on commit f15a1a9

Please sign in to comment.