Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test AEPTestUtils migration #158

Merged
merged 12 commits into from
Jun 18, 2024

Conversation

timkimadobe
Copy link
Contributor

Description

This PR updates the integration test classes:

  1. ConfigOverridesIntegrationTests.kt
  2. UpstreamIntegrationTests.kt

to use the AEPTestUtils library, with the following changes:

  1. Replace local test helper classes with AEPTestUtils versions
  2. Update usages of JSON comparison APIs to reflect:
    1. Automatic conversion of common types into JSONObject/JSONArray - removing manual conversion
    2. Migrating usage of legacy APIs typeMatchPaths and exactMatchPaths
  3. Code style updates
    2. JUnit assertEquals is imported directly
    3. assertExactMatch and assertTypeMatch from JSON comparison is imported directly
    4. Remove .trimIndent() from JSON strings
    5. Remove JSON suffix from var names
    6. Use "STRING_TYPE" convention in expected JSON strings to make value type match intent clearer

Specific changes:

  1. testSendEvent_withPriorState_receivesExpectedStateStoreEventHandle: Added event expectation to test setup to properly await event processing before beginning 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.

Copy link

codecov bot commented Jun 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (dev@a6ebbe7). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             dev     #158   +/-   ##
======================================
  Coverage       ?   84.69%           
  Complexity     ?      407           
======================================
  Files          ?       30           
  Lines          ?     1639           
  Branches       ?      237           
======================================
  Hits           ?     1388           
  Misses         ?      160           
  Partials       ?       91           
Flag Coverage Δ
-tests 84.69% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

expected = JSONObject(expectedLocationHintJSON),
actual = JSONObject(locationHintResult.eventData),
exactMatchPaths = listOf("payload[*].scope", "payload[*].hint")
assertTypeMatch(
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, we can do assertExactMatch here and typeMatch the "payload[*].ttlSeconds".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Updated

expected = JSONObject(expectedLocationHintJSON),
actual = JSONObject(locationHintResult.eventData),
exactMatchPaths = listOf("payload[*].scope")
assertTypeMatch(
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, we can do assertExactMatch here and typeMatch the "payload[*].ttlSeconds".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case we should be ok to keep typeMatch here since 2/3 properties use type match

Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine with this.

Copy link
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 @cacheung! Updated based on feedback

expected = JSONObject(expectedLocationHintJSON),
actual = JSONObject(locationHintResult.eventData),
exactMatchPaths = listOf("payload[*].scope")
assertTypeMatch(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case we should be ok to keep typeMatch here since 2/3 properties use type match

expected = JSONObject(expectedLocationHintJSON),
actual = JSONObject(locationHintResult.eventData),
exactMatchPaths = listOf("payload[*].scope", "payload[*].hint")
assertTypeMatch(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Updated

@emdobrin emdobrin linked an issue Jun 14, 2024 that may be closed by this pull request
}
]
}
""".trimIndent()
"""

// Unsafe access used since testSendEvent_receivesExpectedEventHandles guarantees existence
val stateStoreEvent = TestSetupHelper.getEdgeEventHandles(expectedHandleType = TestConstants.EventSource.STATE_STORE)
.last()

// Exact match used here to strictly validate `payload` array element count == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: update comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! I also updated the test case logic to actually apply the collection element count restriction on payload and also the elements under it, to better reflect the test case intent

realNetworkService.assertAllNetworkRequestExpectations()
val matchingResponses = realNetworkService.getResponsesFor(networkRequest = invalidNetworkRequest)

val matchingResponses = realNetworkService.getResponsesFor(invalidNetworkRequest)

Assert.assertEquals(1, matchingResponses?.size)
Copy link
Contributor

Choose a reason for hiding this comment

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

Follow similar usages everywhere.

Import all the required functions like the configOverrideIntegrationTests and update the usages.

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! Thank you

Copy link
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 reviews @cacheung and @addb! Updated based on feedback

}
]
}
""".trimIndent()
"""

// Unsafe access used since testSendEvent_receivesExpectedEventHandles guarantees existence
val stateStoreEvent = TestSetupHelper.getEdgeEventHandles(expectedHandleType = TestConstants.EventSource.STATE_STORE)
.last()

// Exact match used here to strictly validate `payload` array element count == 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! I also updated the test case logic to actually apply the collection element count restriction on payload and also the elements under it, to better reflect the test case intent

realNetworkService.assertAllNetworkRequestExpectations()
val matchingResponses = realNetworkService.getResponsesFor(networkRequest = invalidNetworkRequest)

val matchingResponses = realNetworkService.getResponsesFor(invalidNetworkRequest)

Assert.assertEquals(1, matchingResponses?.size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! Thank you

@timkimadobe timkimadobe merged commit 2b1c320 into adobe:dev Jun 18, 2024
8 checks passed
@timkimadobe timkimadobe deleted the testutils-integration-tests branch June 18, 2024 21:34
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
3 participants