-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New test for RefreshDomain interactor
- Loading branch information
Showing
5 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,13 @@ | |
"ownerDelegatedRequestsToTeam": true, | ||
"autoApprovedGroups": "group1", | ||
"autoApprovedServiceAccounts": "[email protected]" | ||
}, | ||
{ | ||
"id": "example2.com", | ||
"fullyQualifiedDomainName": "example2.com", | ||
"ownerDelegatedRequestsToTeam": true, | ||
"autoApprovedGroups": "group1", | ||
"autoApprovedServiceAccounts": "[email protected]" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "test_helper" | ||
|
||
class RefreshDomainTest < ActiveSupport::TestCase | ||
def setup | ||
@domain = domains(:owner_match) | ||
@identity = Identity.new(subject: @domain.users_array.first) | ||
@cr = CertIssueRequest.new(common_name: @domain.fqdn) | ||
@interactor = RefreshDomain | ||
end | ||
|
||
test ".call updates db record with service response when 200" do | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert rslt.success? | ||
reloaded = Domain.where(fqdn: @domain.fqdn).first! | ||
assert_not_equal @domain.users, reloaded.users | ||
assert_not_equal @domain.groups, reloaded.groups | ||
assert_not_equal @domain.group_delegation, reloaded.group_delegation | ||
end | ||
|
||
test ".call deletes db record when service 404" do | ||
@domain = domains(:no_match) # this fixture should have no match | ||
@cr = CertIssueRequest.new(common_name: @domain.fqdn) | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert rslt.success? | ||
reloaded = Domain.where(fqdn: @domain.fqdn).first | ||
assert_nil reloaded | ||
end | ||
|
||
test ".call leaves db record as-is when service has error" do | ||
mock = Services::DomainOwnershipService.new | ||
err = ->(_){ raise Faraday::TimeoutError.new } | ||
mock.stub(:get_domain_info, err) do | ||
Services::DomainOwnershipService.stub :new, mock do | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert rslt.success? | ||
reloaded = Domain.where(fqdn: @domain.fqdn).first! | ||
assert_equal @domain.users, reloaded.users | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
class DomainOwnershipServiceTest < ActiveSupport::TestCase | ||
setup do | ||
@subject = Services::DomainOwnershipService.new | ||
@service = Services::DomainOwnershipService.new | ||
end | ||
|
||
test "#get_domain_info fetches from configured api server" do | ||
domain_info = @subject.get_domain_info(domains(:owner_match).fqdn) | ||
domain_info = @service.get_domain_info(domains(:owner_match).fqdn) | ||
assert_not_nil domain_info | ||
assert_equal "group1", domain_info.groups | ||
assert_equal "[email protected]", domain_info.users | ||
|
@@ -15,7 +15,7 @@ class DomainOwnershipServiceTest < ActiveSupport::TestCase | |
end | ||
|
||
test "#get_domain_info returns nil for unmatched fqdn" do | ||
domain_info = @subject.get_domain_info(domains(:group_match).fqdn) | ||
domain_info = @service.get_domain_info(domains(:no_match).fqdn) | ||
assert_nil domain_info | ||
end | ||
end |