[MOB-21131] Display Proposition api to support multiple propositions.#112
[MOB-21131] Display Proposition api to support multiple propositions.#112akhiljain1907 merged 25 commits intoadobe:dev-v5.3.1from
Conversation
…ired for multiple propositions moved generateInteractionXDM and trackWithData method from Offers class to public Optimize extension added relevant OptimizePuiblicApiTests to validate code functioning for multiple propositions
…changed default value of aepError to unexpected
…sition]? instead of [DecisionScope]? in callback and code review changes
…ve AEPOptimizeError as argument and minor changes
…ty and code optimization
…upport tracking based on Offers.
| OptimizeConstants.JsonKeys.EXPERIENCE_EVENT_TYPE: eventType, | ||
| OptimizeConstants.JsonKeys.EXPERIENCE: [ | ||
| OptimizeConstants.JsonKeys.EXPERIENCE_DECISIONING: [ | ||
| OptimizeConstants.JsonKeys.DECISIONING_PROPOSITION_EVENT_TYPE: propositionEventType, |
There was a problem hiding this comment.
@siddique-adobe this seems to be missing in the Android implementation. Could you check if it needs to be added?
|
Hi @spoorthipujariadobe, I have addressed your comments and made few changes. Can you please review again? |
| wait(for: [expectation], timeout: 2) | ||
| } | ||
|
|
||
| func testGenerateInteractionXdm_multiplePropositions() throws { |
There was a problem hiding this comment.
nit: can we move this test to a separate OptimizeTrackingUtilsTests file?
There was a problem hiding this comment.
Would be good to add a few more tests here to cover cases like empty propositions and all offers belonging to the same proposition. You can check the Android PR for more cases
https://github.com/adobe/aepsdk-optimize-android/pull/92/files#diff-710393a6e27a3c8cd7cb485acc24b9df4631442f2c7efc5a5aa7b7ed24686b38
There was a problem hiding this comment.
I have moved testGenerateInteractionXdm_multiplePropositions() in OptimizePropositionTests as that's were relevant generate xdm tests were present.
Also i have added a new test file OptimizeTrackingTests which contains test for new displayed api.
spoorthipujariadobe
left a comment
There was a problem hiding this comment.
Logic looks good. Would be nice to have someone more familiar with iOS review it as well, maybe @ishwetansh ?
| try container.encode(scope, forKey: .scope) | ||
| try container.encode(AnyCodable.from(dictionary: scopeDetails), forKey: .scopeDetails) | ||
| try container.encode(offers, forKey: .items) | ||
| try container.encode(items, forKey: .items) |
There was a problem hiding this comment.
Please confirm if we need items or offers to be encoded here
There was a problem hiding this comment.
Yes, we need to encode offers itself. Removed this.
| import Foundation | ||
|
|
||
| /// Internal helper enum for tracking functionality | ||
| enum OptimizeTrackingUtils { |
There was a problem hiding this comment.
I don't see the use case of using an enum here, it is generally used to define and handle finite cases.
can we please use a struct here.
There was a problem hiding this comment.
since we are using only static methods here, it';s recommended to use enum.
FYI when i use struct, i get this warning - Convenience Type Violation: Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation (convenience_type)
| var propositionDetailsData: [[String: Any]] = [] | ||
|
|
||
| for proposition in propositions { | ||
| let propositionMap: [String: Any] = [ | ||
| OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ID: proposition.id, | ||
| OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPE: proposition.scope, | ||
| OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPEDETAILS: proposition.scopeDetails, | ||
| OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ITEMS: proposition.offers.map { offer in | ||
| [ | ||
| OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ITEMS_ID: offer.id | ||
| ] | ||
| } | ||
| ] | ||
| propositionDetailsData.append(propositionMap) | ||
| } |
There was a problem hiding this comment.
We can use a transformable map function here to build the dictionary instead of traditional loop.
let propositionDetailsData: [[String: Any]] = propositions.map { proposition in return [ OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ID: proposition.id, OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPE: proposition.scope, OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_SCOPEDETAILS: proposition.scopeDetails, OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ITEMS: proposition.offers.map { offer in return [ OptimizeConstants.JsonKeys.DECISIONING_PROPOSITIONS_ITEMS_ID: offer.id ] } ] }
|
|
||
| import Foundation | ||
|
|
||
| class Propositions_OptimizeTests { |
There was a problem hiding this comment.
I guess, we don't usually use an _ in class names,
can we use PropositionsOptimizeTests
There was a problem hiding this comment.
I previously kept this file in Utils folder of Unit test where this naming convention was followed. But now i have moved these test data in a new file PropositionsTestData which is kept in TestHelpers folder.
| XCTAssertEqual(propositions.count, 1) | ||
| XCTAssertEqual(propositions.first?.id, proposition.id) | ||
| XCTAssertEqual(propositions.first?.scope, proposition.scope) | ||
|
|
There was a problem hiding this comment.
nit: please remove the blank line.
|
Hi @spoorthipujariadobe, @ishwetansh can you please review and approve this PR |
Description
This PR adds an api "trackDisplayedOffers" which takes list of offers as an argument and sends display interaction event to Experience Edge.
Through this additional api, we now support display event to be called on multiple propositions which can be send in batches and not per offer (read: proposition) and so we've moved generateInteractionXDM and trackWithData methods from Offer class to public class.This api supports calling display interaction event on multiple offers. Since a proposition could contain more than one offers and our generateInteractionXDM method takes list of propositions, we first extract list of unique propositions from passed offers and create new proposition with relevant offer ids to be tracked. We have also moved generateInteractionXDM and trackWithData methods to OptimizeTrackingUtils from Offer+Tracking extension to reuse them within the module.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: