@@ -55,4 +55,133 @@ class FBSDKAppEventsConfigurationTests: XCTestCase {
5555 config = Fixtures . config ( with: [ " event_collection_enabled " : true ] )
5656 XCTAssertTrue ( config. eventCollectionEnabled, " Event collection enabled should be settable " )
5757 }
58+
59+ func testCodingSecurity( ) {
60+ XCTAssertTrue ( AppEventsConfiguration . supportsSecureCoding, " Should support secure coding " )
61+ }
62+
63+ func testCreatingWithMissingDictionary( ) {
64+ config = AppEventsConfiguration ( json: nil )
65+ XCTAssertEqual (
66+ config,
67+ AppEventsConfiguration . default ( ) ,
68+ " Should use the default config when creating with a missing dictionary "
69+ )
70+ }
71+
72+ func testCreatingWithEmptyDictionary( ) {
73+ config = AppEventsConfiguration ( json: [ : ] )
74+ XCTAssertEqual (
75+ config,
76+ AppEventsConfiguration . default ( ) ,
77+ " Should use the default config when creating with an empty dictionary "
78+ )
79+ }
80+
81+ func testCreatingWithMissingTopLevelKey( ) {
82+ config = AppEventsConfiguration (
83+ json: RawAppEventsConfigurationResponseFixtures . validMissingTopLevelKey
84+ )
85+ XCTAssertEqual (
86+ config,
87+ AppEventsConfiguration . default ( ) ,
88+ " Should use the default config when creating with a missing top level key "
89+ )
90+ }
91+
92+ func testCreatingWithInvalidValues( ) {
93+ config = AppEventsConfiguration (
94+ json: RawAppEventsConfigurationResponseFixtures . invalidValues
95+ )
96+ XCTAssertEqual (
97+ config. defaultATEStatus,
98+ . unspecified,
99+ " Should use the correct default for ate status "
100+ )
101+ XCTAssertTrue (
102+ config. advertiserIDCollectionEnabled,
103+ " Should use the correct default for ad ID collection "
104+ )
105+ XCTAssertFalse (
106+ config. eventCollectionEnabled,
107+ " Should use the correct default for event collection "
108+ )
109+ }
110+
111+ func testCreatingWithValidValues( ) {
112+ config = AppEventsConfiguration ( json: RawAppEventsConfigurationResponseFixtures . valid)
113+ XCTAssertEqual (
114+ config. defaultATEStatus,
115+ . disallowed,
116+ " Should use the provided value for the default ate status "
117+ )
118+ XCTAssertFalse (
119+ config. advertiserIDCollectionEnabled,
120+ " Should use the provided value for ad ID collection "
121+ )
122+ XCTAssertTrue (
123+ config. eventCollectionEnabled,
124+ " Should use the provided value for event collection "
125+ )
126+ }
127+
128+ // MARK: Coding
129+
130+ func testEncoding( ) {
131+ let coder = TestCoder ( )
132+ config = AppEventsConfiguration . default ( )
133+ config. encode ( with: coder)
134+
135+ XCTAssertEqual (
136+ coder. encodedObject [ " default_ate_status " ] as? Int ,
137+ Int ( config. defaultATEStatus. rawValue) ,
138+ " Should encode the expected default ate status value as an integer "
139+ )
140+ XCTAssertEqual (
141+ coder. encodedObject [ " advertiser_id_collection_enabled " ] as? Bool ,
142+ config. advertiserIDCollectionEnabled,
143+ " Should encode the expected advertiser ID collection enabled value "
144+ )
145+ XCTAssertEqual (
146+ coder. encodedObject [ " event_collection_enabled " ] as? Bool ,
147+ config. eventCollectionEnabled,
148+ " Should encode the expected eventCollectionEnabled value "
149+ )
150+ }
151+
152+ func testDecoding( ) {
153+ let coder = TestCoder ( )
154+ _ = AppEventsConfiguration ( coder: coder)
155+
156+ config. encode ( with: coder)
157+
158+ XCTAssertEqual (
159+ coder. decodedObject [ " default_ate_status " ] as? String ,
160+ " decodeIntegerForKey " ,
161+ " Initializing from a decoder should attempt to decode an int for the ate status key "
162+ )
163+ XCTAssertEqual (
164+ coder. decodedObject [ " advertiser_id_collection_enabled " ] as? String ,
165+ " decodeBoolForKey " ,
166+ " Initializing from a decoder should attempt to decode an int for the advertiser ID collection enabled key "
167+ )
168+ XCTAssertEqual (
169+ coder. decodedObject [ " event_collection_enabled " ] as? String ,
170+ " decodeBoolForKey " ,
171+ " Initializing from a decoder should attempt to decode an int for the event collection enabled key "
172+ )
173+ }
174+ }
175+
176+ extension AppEventsConfiguration {
177+ // swiftlint:disable:next override_in_extension
178+ open override func isEqual( _ object: Any ? ) -> Bool {
179+ if let other = object as? AppEventsConfiguration {
180+ return advertiserIDCollectionEnabled == other. advertiserIDCollectionEnabled &&
181+ eventCollectionEnabled == other. eventCollectionEnabled &&
182+ defaultATEStatus == other. defaultATEStatus
183+ } else {
184+ return super. isEqual ( object)
185+ }
186+ }
58187}
0 commit comments