Skip to content

Test coverage for JSONCondition getHistoricalEventCount (search type any or ordered)#1142

Merged
timkimadobe merged 2 commits intoadobe:feature/historical-consequencefrom
timkimadobe:json-condition-historical-count-tests
Jun 11, 2025
Merged

Test coverage for JSONCondition getHistoricalEventCount (search type any or ordered)#1142
timkimadobe merged 2 commits intoadobe:feature/historical-consequencefrom
timkimadobe:json-condition-historical-count-tests

Conversation

@timkimadobe
Copy link
Copy Markdown
Contributor

Important

This PR is based on the implementation of mostRecent in (and this diff currently also contains its changes):

Once #1138 is merged, this PR should reflect the actual scope of changes.

Questions for reviewers

  1. For getHistoricalEventCount why do missing input values return 0? Isn't this an error case? 0 is a meaningful return for both search types, but I wonder if changing this to -1 is a breaking change?
    func getHistoricalEventCount(parameters: [Any]?) -> Int {
    guard let params = parameters,
    let runtime = params[0] as? ExtensionRuntime,
    let requestEvents = params[1] as? [EventHistoryRequest],
    let searchType = params[2] as? EventHistorySearchType else {
    return 0
    }

Description

This PR adds unit test coverage for JSONCondition's getHistoricalEventCount method:

Test case Scenario Expected
parametersNil / TooFew / TypeMismatch Invalid parameter array Returns 0 (input error)
SearchTypeMostRecent Guard rejects unsupported .mostRecent Returns -1
.any – DB error Any count == -1 in results Returns -1
.any – accumulate Sums positive counts Returns total
.ordered – DB error Any count == -1 in results Returns -1
.ordered – missing event Any count == 0 Returns 0
.ordered – all present All counts > 0 Returns 1

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Copy Markdown

@spoorthipujariadobe spoorthipujariadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some other PR merge created some conflicts for this PR 😶

@timkimadobe timkimadobe force-pushed the json-condition-historical-count-tests branch from 9a59730 to 3d2e5bf Compare June 10, 2025 22:54
@timkimadobe timkimadobe merged commit b5965b5 into adobe:feature/historical-consequence Jun 11, 2025
17 checks passed
@timkimadobe timkimadobe deleted the json-condition-historical-count-tests branch June 11, 2025 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants