Skip to content

Commit

Permalink
Merge pull request #5 from airrobe/eli/fraudStatusOnConfirmationView
Browse files Browse the repository at this point in the history
add fraud status handling case on confirmation widget initialization
  • Loading branch information
creative-dev-lab authored Jan 13, 2022
2 parents 2ea8389 + df48ebe commit 423fd73
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ You are going to need `AppId` from the Provider which will be used to get the Ca
```swift
AirRobeWidget.initialize(
config: AirRobeWidgetConfig(
appId: "APP_ID", // required
color: String, // optional - color HexCode without "#"
mode: enum // optional - (.production or .sandbox) Default value is .production
appId: "APP_ID", // required
privacyPolicyURL: String, // required - privacy policy url of The Iconic
color: String, // optional - color HexCode without "#", default value is "42abc8"
mode: enum // optional - (.production or .sandbox), default value is .production
)
)
```
Expand All @@ -86,12 +87,12 @@ AirRobeWidget.initialize(
var airRobeOptIn = AirRobeOptIn()
...
airRobeOptIn.initialize(
brand: String?, // optional - e.g. "Chanel"
material: String?, // optional - e.g. "Leather"
brand: String?, // optional - e.g. "Chanel", can be nil
material: String?, // optional - e.g. "Leather", can be nil
category: String, // required - e.g. "Hats/fancy-hats"
priceCents: Double, // required - e.g. 100.95
originalFullPriceCents: Double?, // optional - e.g. 62.00
rrpCents: Double?, // optional - e.g. 62.00
originalFullPriceCents: Double?, // optional - e.g. 62.00, can be nil
rrpCents: Double?, // optional - e.g. 62.00, can be nil
currency: String, // optional - default is "AUD"
locale: String // optional - default is "en-AU"
)
Expand All @@ -115,8 +116,9 @@ airRobeMultiOptIn.initialize(
var airRobeConfirmation = AirRobeConfirmation()
...
airRobeConfirmation.initialize(
orderId: String // required - e.g. "123456" - the order id you got from the checkout.
email: String // required
orderId: String, // required - e.g. "123456" - the order id you got from the checkout.
email: String, // required
fraudRisk: Bool // optional - fraud status for the confirmation widget, default value is false.
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ final class OrderConfirmationViewModel {
var orderId: String = ""
/// Describes the email of the logged in account.
var email: String = ""
/// Describes the fraud status of the widget.
var fraudRisk: Bool = false

private lazy var apiService = AirRobeApiService()
private var cancellable: AnyCancellable?
Expand All @@ -26,7 +28,7 @@ final class OrderConfirmationViewModel {
isAllSet = .paramIssue
return
}
isAllSet = UserDefaults.standard.OrderOptedIn ? .eligible : .notEligible
isAllSet = UserDefaults.standard.OrderOptedIn && !fraudRisk ? .eligible : .notEligible
if isAllSet == .eligible {
emailCheck(email: email)
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/AirRobeWidget/Widgets/AirRobeConfirmation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ open class AirRobeConfirmation: UIView {
/// - Parameters:
/// - orderId: string value of order Id generated from purchase
/// - email: email address that used for the purchase
/// - fraudRisk: fraud status for the confirmation widget
public func initialize(
orderId: String,
email: String
email: String,
fraudRisk: Bool = false
) {
translatesAutoresizingMaskIntoConstraints = false
orderConfirmationView.viewModel.orderId = orderId
orderConfirmationView.viewModel.email = email
orderConfirmationView.viewModel.fraudRisk = fraudRisk
orderConfirmationView.superView = self

orderConfirmationView.viewModel.initializeConfirmationWidget()
Expand Down
30 changes: 15 additions & 15 deletions Tests/AirRobeWidgetTests/AirRobeWidgetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ final class AirRobeWidgetTests: XCTestCase {
try testJSONMapping()
CategoryModelInstance.shared.categoryModel = categoryModel

let widgetInputs = [("Chanel", "Leather", "Accessories/Belts", 100.0, 80.0, 80.0)] + self.otpInInputs
let expectedResults = [true] + self.otpInExpectedResults
let widgetInputs = [("Chanel", "Leather", "Accessories/Belts", 100.0, 80.0, 80.0)] + self.optInInputs
let expectedResults = [true] + self.optInExpectedResults

XCTAssertEqual(widgetInputs.count, expectedResults.count)
zip(widgetInputs, expectedResults).forEach { input, exp in
Expand All @@ -36,7 +36,7 @@ final class AirRobeWidgetTests: XCTestCase {
}
}

let otpInInputs: [(brand: String?, material: String?, category: String, priceCents: Double, originalFullPriceCents: Double?, rrpCents: Double?)] = [
let optInInputs: [(brand: String?, material: String?, category: String, priceCents: Double, originalFullPriceCents: Double?, rrpCents: Double?)] = [
("", "", "Accessories/Belts", 100.0, 80.0, 80.0), // empty brand, material
(nil, nil, "Accessories", 100.0, 80.0, 80.0), //nil brand, material
(nil, nil, "Accessories", 100.0, nil, nil), //nil originalPrice, rrp
Expand All @@ -57,7 +57,7 @@ final class AirRobeWidgetTests: XCTestCase {
(nil, nil, "Accessories/Underwear & Socks/Test Category", 100.0, 80.0, 80.0), // applied for best category mapping logic - should be false
]

lazy var otpInExpectedResults: [Bool] = [
lazy var optInExpectedResults: [Bool] = [
true,
true,
true,
Expand All @@ -82,8 +82,8 @@ final class AirRobeWidgetTests: XCTestCase {
try testJSONMapping()
CategoryModelInstance.shared.categoryModel = categoryModel

let widgetInputs = [["Accessories"]] + self.multiOtpInInputs
let expectedResults = [true] + self.multiOtpInExpectedResults
let widgetInputs = [["Accessories"]] + self.multiOptInInputs
let expectedResults = [true] + self.multiOptInExpectedResults

XCTAssertEqual(widgetInputs.count, expectedResults.count)
zip(widgetInputs, expectedResults).forEach { input, exp in
Expand All @@ -94,7 +94,7 @@ final class AirRobeWidgetTests: XCTestCase {
}
}

let multiOtpInInputs: [([String])] = [
let multiOptInInputs: [([String])] = [
(["Accessories"]), // Contain a category that meets condition
(["Accessories", "Accessories/Belts", ]), // Contain multiple categories that meets condition
(["Accessories", "RandomCategory"]), // Contain 1 category that is in Mapping info that meets condition
Expand All @@ -107,7 +107,7 @@ final class AirRobeWidgetTests: XCTestCase {
(["Accessories/Underwear & Socks", "RandomCategory"]) // Contain a category that excluded equals true, and with random category
]

lazy var multiOtpInExpectedResults: [Bool] = [
lazy var multiOptInExpectedResults: [Bool] = [
true,
true,
true,
Expand All @@ -131,24 +131,24 @@ final class AirRobeWidgetTests: XCTestCase {
XCTAssertEqual(widgetInputs.count, expectedResults.count)
zip(widgetInputs, expectedResults).forEach { input, exp in
let vm = AirRobeConfirmation()
UserDefaults.standard.OptedIn = input.otpIn
UserDefaults.standard.OptedIn = input.optIn
UserDefaults.standard.OrderOptedIn = input.eligibility
vm.initialize(orderId: input.orderId, email: input.email)
let results = vm.orderConfirmationView.viewModel.isAllSet == .eligible ? true : false
XCTAssertEqual(results, exp)
}
}

let confirmationInputs: [(orderId: String, email: String, eligibility: Bool, otpIn: Bool)] = [
("123456", "[email protected]", true, true), // otpInfo in cache is set to true
let confirmationInputs: [(orderId: String, email: String, eligibility: Bool, optIn: Bool)] = [
("123456", "[email protected]", true, true), // optInfo in cache is set to true
("123456", "[email protected]", true, true), // with not available email

("", "", true, true), // order id and email is empty
("", "", true, false), // order id and email are empty and otpInfo is false
("", "", true, false), // order id and email are empty and otpInfo is false
("", "", true, false), // order id and email are empty and optInfo is false
("", "", true, false), // order id and email are empty and optInfo is false
("123456", "", true, true), // email is empty
("123456", "", true, false), // email is empty, otpInfo in cache is set to false
("", "[email protected]", true, false), // orderId is empty, otpInfo in cache is set to false
("123456", "", true, false), // email is empty, optInfo in cache is set to false
("", "[email protected]", true, false), // orderId is empty, optInfo in cache is set to false
("", "[email protected]", true, true), // orderId is empty

("123456", "[email protected]", true, false), // with available email
Expand Down

0 comments on commit 423fd73

Please sign in to comment.