forked from facebook/facebook-ios-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAEMAdvertiserMultiEntryRuleTests.swift
202 lines (188 loc) · 5.6 KB
/
AEMAdvertiserMultiEntryRuleTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
@testable import FBAEMKit
import TestTools
import XCTest
final class AEMAdvertiserMultiEntryRuleTests: XCTestCase {
enum Keys {
static let ruleOperator = "operator"
static let rules = "rules"
}
func testIsMatchedEventParametersForAnd() {
let rule = AEMAdvertiserMultiEntryRule(
with: .and,
rules: [SampleAEMSingleEntryRules.cardTypeRule1, SampleAEMSingleEntryRules.valueRule]
)
XCTAssertTrue(
rule.isMatchedEventParameters(
[
"card_type": "platium",
"amount": NSNumber(value: 100),
]
),
"Should expect the parameter matched with the rule"
)
XCTAssertFalse(
rule.isMatchedEventParameters(
[
"card_type": "platium",
"amount": NSNumber(value: 1),
]
),
"Should not expect the parameter matched with the rule if the amount is low"
)
XCTAssertFalse(
rule.isMatchedEventParameters(
[
"card_type": "gold",
"amount": NSNumber(value: 100),
]
),
"Should not expect the parameter matched with the rule if the card type is wrong"
)
}
func testIsMatchedEventParametersForOr() {
let rule = AEMAdvertiserMultiEntryRule(
with: .or,
rules: [SampleAEMSingleEntryRules.cardTypeRule1, SampleAEMSingleEntryRules.valueRule]
)
XCTAssertFalse(
rule.isMatchedEventParameters(
[
"card_type": "gold",
"amount": NSNumber(value: 1),
]
),
"Should not expect the parameter matched with the rule"
)
XCTAssertTrue(
rule.isMatchedEventParameters(
[
"card_type": "platium",
"amount": NSNumber(value: 1),
]
),
"Should expect the parameter matched with the rule if the card type is the same"
)
XCTAssertTrue(
rule.isMatchedEventParameters(
[
"card_type": "gold",
"amount": NSNumber(value: 100),
]
),
"Should expect the parameter matched with the rule if amount is high"
)
}
func testIsMatchedEventParametersForNot() {
let rule = AEMAdvertiserMultiEntryRule(
with: .not,
rules: [SampleAEMSingleEntryRules.cardTypeRule1, SampleAEMSingleEntryRules.valueRule]
)
XCTAssertTrue(
rule.isMatchedEventParameters(
[
"card_type": "gold",
"amount": NSNumber(value: 1),
]
),
"Should expect the parameter matched with the rule"
)
XCTAssertFalse(
rule.isMatchedEventParameters(
[
"card_type": "platium",
"amount": NSNumber(value: 1),
]
),
"Should not expect the parameter matched with the rule if the card type is the same"
)
XCTAssertFalse(
rule.isMatchedEventParameters(
[
"card_type": "gold",
"amount": NSNumber(value: 100),
]
),
"Should not expect the parameter matched with the rule if amount is high"
)
}
func testIsMatchedEventParametersForNestedRules() {
let andRule = AEMAdvertiserMultiEntryRule(
with: .and,
rules: [SampleAEMSingleEntryRules.cardTypeRule2, SampleAEMSingleEntryRules.valueRule]
)
let orRule = AEMAdvertiserMultiEntryRule(
with: .or,
rules: [SampleAEMSingleEntryRules.contentNameRule, SampleAEMSingleEntryRules.contentCategoryRule]
)
let nestedRule = AEMAdvertiserMultiEntryRule(
with: .and,
rules: [andRule, orRule, SampleAEMSingleEntryRules.urlRule]
)
XCTAssertTrue(
nestedRule.isMatchedEventParameters(
[
"URL": "thankyou.do.com",
"content_category": "demand",
"card_type": "blue_credit",
"amount": NSNumber(value: 100),
]
),
"Shoule expect the rule is matched"
)
XCTAssertFalse(
nestedRule.isMatchedEventParameters(
[
"URL": "thankyou.com",
"content_category": "demand",
"card_type": "blue_credit",
"amount": NSNumber(value: 100),
]
),
"Shoule not expect the rule is matched with wrong URL"
)
XCTAssertFalse(
nestedRule.isMatchedEventParameters(
[
"URL": "thankyou.do.com",
"content_category": "required",
"card_type": "blue_credit",
"amount": NSNumber(value: 100),
]
),
"Shoule not expect the rule is matched with wrong content_category"
)
}
func testSecureCoding() {
XCTAssertTrue(
AEMAdvertiserMultiEntryRule.supportsSecureCoding,
"AEM Advertiser Multi Entry Rule should support secure coding"
)
}
func testEncodingAndDecoding() throws {
let entryRule = SampleAEMData.validAdvertiserMultiEntryRule
let decodedObject = try CodabilityTesting.encodeAndDecode(entryRule)
// Test Objects
XCTAssertNotIdentical(decodedObject, entryRule, .isCodable)
XCTAssertNotEqual(decodedObject, entryRule, .isCodable) // isEqual Method hasn't been implemented
// Test Properties
XCTAssertEqual(decodedObject.operator.rawValue, entryRule.operator.rawValue)
let rules = try XCTUnwrap(
entryRule.rules as? [AEMAdvertiserSingleEntryRule]
)
let decodedRules = try XCTUnwrap(
decodedObject.rules as? [AEMAdvertiserSingleEntryRule]
)
XCTAssertEqual(decodedRules, rules)
}
}
// MARK: - Assumptions
extension String {
fileprivate static let isCodable = "AEMAdvertiserMultiEntryRule should be encodable and decodable"
}