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

-places tests #3

Merged
merged 4 commits into from
May 17, 2021
Merged

-places tests #3

merged 4 commits into from
May 17, 2021

Conversation

sbenedicadb
Copy link
Member

No description provided.

Copy link
Contributor

@PravinPK PravinPK left a comment

Choose a reason for hiding this comment

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

👍🏼 for some solid testing.
I have a few minor questions/changes, good to merge right afer

@@ -101,15 +113,17 @@ public class Places: NSObject, Extension {

// MARK: - Private Methods
private func processSharedStateChange(event: Event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For better clarity can we rename this method from processSharedStateChange to processConfigStateChange
Since handleSharedStateUpdate filters out all the other shared state changes

// onRegistered called in setUpWithError

// test
mockRuntime.startEvents()
Copy link
Contributor

Choose a reason for hiding this comment

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

any significance in calling startEvents ?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope!

func testClear() throws {
// setup
let expectation = XCTestExpectation(description: "clear should dispatch an event")
expectation.assertForOverFulfill = true
Copy link
Contributor

Choose a reason for hiding this comment

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

If I am not wrong I don't think it's necessary to explicitly mention
expectation.assertForOverFulfill = true

It's true by default. If so we can remove setting that property in all the tests

// MARK: - getCurrentPointsOfInterest
func testGetCurrentPointsOfInterest() throws {
// setup
let expectation = XCTestExpectation(description: "getCurrentPointsOfInterest should call its closure")
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the expectation of the test is to see if the API call dispatches the event?
In that case, can we rename the description to

getCurrentPointsOfInterest should dispatch places request content event

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, you're right on this

expectation.assertForOverFulfill = true
extensionContainer.registerListener(type: EventType.places, source: EventSource.requestContent) { (event) in
XCTAssertEqual(PlacesConstants.EventDataKey.Places.RequestType.GET_NEARBY_PLACES,
event.data?[PlacesConstants.EventDataKey.Places.REQUEST_TYPE] as? String)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assert with eventData on

"count" : 3,
"longitude" : 23.45
"latitude" : 12.34,
??

expectation.assertForOverFulfill = true
extensionContainer.registerListener(type: EventType.places, source: EventSource.requestContent) { (event) in
XCTAssertEqual(PlacesConstants.EventDataKey.Places.RequestType.PROCESS_REGION_EVENT,
event.data?[PlacesConstants.EventDataKey.Places.REQUEST_TYPE] as? String)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we assert on eventData for entrytype and regionID

  "regioneventtype" : "entry",
  "requesttype" : "requestprocessregionevent",
  "regionid" : "id"

And similar kind of assertions on eventData for other API tests in this class

// verify
XCTAssertNil(mockQueryService.invokedLat)
XCTAssertNil(mockQueryService.invokedLon)
XCTAssertNil(mockQueryService.invokedCount)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit : Instead of checking for nil on Lat, Lon, and count
A better way is to have a boolean isInvoked in mockQueryService that gets set when getNearByPOI method is called

And these 3 check can be replaced by just

XCTAssertFalse(mockQueryService.isInvoked)

This will to few more test cases below

XCTAssertEqual(EventSource.responseContent, responseEvent.source)
XCTAssertEqual(PlacesConstants.EventName.Response.GET_NEARBY_PLACES, responseEvent.name)
let dispatchedData = responseEvent.data!
XCTAssertEqual(0, dispatchedData.count)
Copy link
Contributor

Choose a reason for hiding this comment

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

In Android when privacy status is opted out... eventData contains "status" key with privacyoptOut response error

https://git.corp.adobe.com/dms-mobile/bourbon-core-java-places/blob/dev-v1.4.1/code/places/src/main/java/com/adobe/marketing/mobile/PlacesRequestError.java#L69

Can we add them here as well and not dispatch a empty eventData?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, i can do that

XCTAssertEqual(0, mockRuntime.dispatchedEvents.count)
}

func testHandleProcessRegionEventRequestPlacesConfigMissing() throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

technically handling a region entry/exit event doesn't need places configuration.

I like the fact that when no configuration we stop processing all the events. If this is correct, may be we should introduce the same changes to Android

Copy link
Member Author

Choose a reason for hiding this comment

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

we don't allow entry unless the region is in nearbyPois, and nearbyPois can't get populated without a proper places configuration, so i guess technically it does.

i think we could discuss if this is proper behavior though :)

Copy link
Contributor

@PravinPK PravinPK left a comment

Choose a reason for hiding this comment

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

Good to merge

@sbenedicadb sbenedicadb merged commit df46b5c into adobe:main May 17, 2021
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.

None yet

2 participants