Skip to content

Refactor functional tests to use JSON comparison (part 2)#438

Merged
emdobrin merged 28 commits intoadobe:devfrom
timkimadobe:refactor-functional-tests-aeptestutils3
Feb 7, 2024
Merged

Refactor functional tests to use JSON comparison (part 2)#438
emdobrin merged 28 commits intoadobe:devfrom
timkimadobe:refactor-functional-tests-aeptestutils3

Conversation

@timkimadobe
Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe commented Jan 10, 2024

Note

These changes are a continuation of #437

Description

This PR updates the next portion of Edge functional tests to use the JSON comparison system. Broadly, it replaces dictionary flattening with JSON comparison. Specific changes:

  1. If flattened dictionary count was applied, then strict collection count checks are applied throughout the JSON validation when using the extensible comparison methods assertExactMatch/assertTypeMatch - that is, the refactor should preserve the same level of strictness for the payload being tested
  2. Everywhere FileManager.default.clearCache() is used, FileManager.default.removeAdobeCacheDirectory() was also added (given Core's new persistence handling)

Questions for reviewers

func testProcessResponseOnSuccess_WhenOneEventHandle_emptyEventHandleType_dispatchesEvent()

  1. assertExactMatch with type validation mode for key type was used since in the original test case logic, only the presence of 5 keys was validated (implicitly requiring the type key's presence) - is this an acceptable change in the scope of the test logic?

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.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 10, 2024

Codecov Report

Merging #438 (e644475) into dev (a2b6fb5) will decrease coverage by 10.81%.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff             @@
##              dev     #438       +/-   ##
===========================================
- Coverage   96.47%   85.66%   -10.81%     
===========================================
  Files          27       27               
  Lines        1730     1730               
===========================================
- Hits         1669     1482      -187     
- Misses         61      248      +187     

@timkimadobe timkimadobe linked an issue Jan 10, 2024 that may be closed by this pull request
Copy link
Copy Markdown

@cdhoffmann cdhoffmann left a comment

Choose a reason for hiding this comment

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

LGTM!

@emdobrin
Copy link
Copy Markdown
Contributor

Rebase required for this PR to show the actual diff, @kevinlind can you help with a quick review afterwards?

# Conflicts:
#	Tests/FunctionalTests/AEPEdgeFunctionalTests.swift
#	Tests/FunctionalTests/CompletionHandlerFunctionalTests.swift
#	Tests/FunctionalTests/Edge+ConsentTests.swift
#	Tests/FunctionalTests/EdgeDatastreamConfigOverrideTests.swift
Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

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

Thanks for the review @kevinlind! Updated based on feedback - please note that the current implementation relies on the changes from: adobe/aepsdk-testutils-ios#27 being available (these changes have been merged into feature/latest already)

Copy link
Copy Markdown
Contributor

@emdobrin emdobrin left a comment

Choose a reason for hiding this comment

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

One small comment from me, looks great otherwise

}
}
let expectedJSON = "{}"
assertTypeMatch(expected: expectedJSON, actual: resultNetworkRequests[0], pathOptions: KeyMustBeAbsent(paths: "events.path"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test should check that the network request does not include the key "request" and its value under "events" since this is an internal key that Edge extension processes and removes from the event sent upstream. events.request.path must be absent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh I see, if I'm understanding correctly, the current validation path events.path is incorrect - and this was not the path validated by the original test logic either - the actual path should be events.request.path?

I've updated the path accordingly, please let me know what you think!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, the intention of the original test was to check that the internal key was not added in the network request. One small correction though, I think we need to check for this path instead events[0].request.path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok thank you! Updated path value

@timkimadobe
Copy link
Copy Markdown
Contributor Author

Important

The latest updates have changed the AEPTestUtils dependency from the feature/latest branch to the v5.0.0-beta tag, and there are some associated breaking changes that were addressed

This test should check that the network request does not include the key "request" and its value under "events" since this is an internal key that Edge extension processes and removes from the event sent upstream.
Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

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

Thanks for the review @emdobrin! Updated based on feedback

}
}
let expectedJSON = "{}"
assertTypeMatch(expected: expectedJSON, actual: resultNetworkRequests[0], pathOptions: KeyMustBeAbsent(paths: "events.path"))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh I see, if I'm understanding correctly, the current validation path events.path is incorrect - and this was not the path validated by the original test logic either - the actual path should be events.request.path?

I've updated the path accordingly, please let me know what you think!

@emdobrin emdobrin merged commit a216938 into adobe:dev Feb 7, 2024
@timkimadobe timkimadobe deleted the refactor-functional-tests-aeptestutils3 branch February 8, 2024 00:56
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.

Refactor functional and integration tests to use new test utils

4 participants