Skip to content

Fix MerchantDomainService coverage gaps: production bugs + full test coverage#1507

Merged
StuartFerguson merged 6 commits intomasterfrom
copilot/update-test-coverage-merchant-domain-service
Feb 21, 2026
Merged

Fix MerchantDomainService coverage gaps: production bugs + full test coverage#1507
StuartFerguson merged 6 commits intomasterfrom
copilot/update-test-coverage-merchant-domain-service

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 20, 2026

MerchantDomainService had widespread copy-paste bugs causing merchant aggregate failures to be silently swallowed, a missing return in the balance check path, and large gaps in test coverage across all 15 service methods.

Production Bug Fixes

13 copy-paste guard bugs — every method that fetches both estate and merchant aggregates was checking estateResult.IsFailed twice instead of checking merchantResult.IsFailed on the second check. A failed merchant fetch would fall through with a null/invalid aggregate:

// Before (wrong in 13 methods)
Result<MerchantAggregate> merchantResult = await DomainServiceHelper.GetAggregateOrFailure(...);
if (estateResult.IsFailed)   // ← always false at this point
    return ResultHelpers.CreateFailure(merchantResult);

// After
if (merchantResult.IsFailed)
    return ResultHelpers.CreateFailure(merchantResult);

Missing return in MakeMerchantWithdrawal — balance fetch failure called Result.Invalid(...) without return, so execution continued into JsonConvert.DeserializeObject on a null string:

// Before
if (getBalanceResult.IsFailed) { Result.Invalid("..."); }  // result discarded

// After  
if (getBalanceResult.IsFailed) { return Result.Invalid("..."); }

Test Coverage

  • 15 exception-path tests — one per service method covering the catch (Exception ex) handler via ThrowsAsync
  • Previously skipped tests re-enabledRequireCustomMerchantNumber / RequireCustomTerminalNumber tests were skipped pending an OperatorAggregate; added the missing mock and enabled them
  • Switch arm coverage — added SettlementSchedule.NotSet and MerchantDepositSource.Automatic tests to cover the _ and Automatic branches
  • Fixed 4 existing withdrawal tests — corrected GetLatest<MerchantAggregate>Get<MerchantAggregate> to match the actual service call; added missing EventStoreContext mock for the NotEnoughFunds path
Original prompt

This section details on the original issue you should resolve

<issue_title>Update Test Coverage on Merchant Domain service</issue_title>
<issue_description>Each domain service method needs new tests added to cover all cases, include exception and failure cases please.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Update test coverage on Merchant Domain service Add missing failure-path tests for MerchantDomainService Feb 20, 2026
Copilot AI requested a review from StuartFerguson February 20, 2026 20:32
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot the following methods still have missing coverage lines all around the failure cases

AddContractToMerchant
AddDeviceToMerchant
AddMerchantAddress
AddMerchantContact
AssignOperatorToMerchant
CreateMerchantUser
MakeMerchantDeposit
MakeMerchantWithdrawal
RemoveContractFromMerchant
RemoveOperatorFromMerchant
SwapMerchantDevice
UpdateMerchant
UpdateMerchantAddress
UpdateMerchantContact

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot still have some missing coverage as mentiond aboce can you review this

@StuartFerguson StuartFerguson marked this pull request as ready for review February 21, 2026 08:00
@StuartFerguson StuartFerguson merged commit 108b0a9 into master Feb 21, 2026
10 checks passed
@github-actions github-actions Bot deleted the copilot/update-test-coverage-merchant-domain-service branch April 23, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Test Coverage on Merchant Domain service

2 participants