Skip to content

Commit 64403da

Browse files
committed
CORE-1936 fix apple search ad tests
1 parent 2674dd5 commit 64403da

File tree

2 files changed

+104
-56
lines changed

2 files changed

+104
-56
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCAppleAdClientTests.m

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,29 @@ - (void)testRequestAttribution {
4646

4747
BNCAppleAdClient *adClient = [BNCAppleAdClient new];
4848
[adClient requestAttributionDetailsWithBlock:^(NSDictionary<NSString *,NSObject *> * _Nonnull attributionDetails, NSError * _Nonnull error) {
49-
XCTAssertNil(error);
50-
51-
id tmp = [attributionDetails objectForKey:@"Version3.1"];
52-
if ([tmp isKindOfClass:NSDictionary.class]) {
53-
NSDictionary *tmpDict = (NSDictionary *)tmp;
54-
XCTAssertNotNil(tmpDict);
55-
56-
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
57-
XCTAssertNotNil(tmpBool);
49+
50+
if (@available(iOS 14.5, *)) {
51+
// Need ATT permission to use get old Apple Search Ads info
52+
XCTAssertNotNil(error);
53+
XCTAssert([@"The app is not authorized for ad tracking" isEqualToString:error.localizedDescription]);
54+
[expectation fulfill];
55+
5856
} else {
59-
XCTFail(@"Did not find Search Ads attribution");
57+
XCTAssertNil(error);
58+
59+
id tmp = [attributionDetails objectForKey:@"Version3.1"];
60+
if ([tmp isKindOfClass:NSDictionary.class]) {
61+
NSDictionary *tmpDict = (NSDictionary *)tmp;
62+
XCTAssertNotNil(tmpDict);
63+
64+
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
65+
XCTAssertNotNil(tmpBool);
66+
} else {
67+
XCTFail(@"Did not find Search Ads attribution");
68+
}
69+
70+
[expectation fulfill];
6071
}
61-
62-
[expectation fulfill];
6372
}];
6473

6574
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {

Branch-TestBed/Branch-SDK-Tests/BNCAppleSearchAdsTests.m

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,24 @@ - (void)testRequestAppleSearchAds {
194194
__block XCTestExpectation *expectation = [self expectationWithDescription:@"AppleSearchAds"];
195195

196196
[self.appleSearchAds requestAttributionWithCompletion:^(NSDictionary * _Nullable attributionDetails, NSError * _Nullable error, NSTimeInterval elapsedSeconds) {
197-
XCTAssertNil(error);
198-
XCTAssertTrue(elapsedSeconds > 0);
199-
200-
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
201-
XCTAssertNotNil(tmpDict);
202-
203-
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
204-
XCTAssertNotNil(tmpBool);
205-
206-
[expectation fulfill];
197+
if (@available(iOS 14.5, *)) {
198+
// Need ATT permission to use get old Apple Search Ads info
199+
XCTAssertNotNil(error);
200+
XCTAssertTrue(elapsedSeconds > 0);
201+
[expectation fulfill];
202+
203+
} else {
204+
XCTAssertNil(error);
205+
XCTAssertTrue(elapsedSeconds > 0);
206+
207+
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
208+
XCTAssertNotNil(tmpDict);
209+
210+
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
211+
XCTAssertNotNil(tmpBool);
212+
213+
[expectation fulfill];
214+
}
207215
}];
208216

209217
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {
@@ -216,16 +224,25 @@ - (void)testRequestAppleSearchAdsWithRetry_0 {
216224
__block XCTestExpectation *expectation = [self expectationWithDescription:@"AppleSearchAds"];
217225

218226
[self.appleSearchAds requestAttributionWithMaxAttempts:0 completion:^(NSDictionary * _Nullable attributionDetails, NSError * _Nullable error, NSTimeInterval elapsedSeconds) {
219-
XCTAssertNil(error);
220-
XCTAssertTrue(elapsedSeconds > 0);
221-
222-
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
223-
XCTAssertNotNil(tmpDict);
224-
225-
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
226-
XCTAssertNotNil(tmpBool);
227-
228-
[expectation fulfill];
227+
if (@available(iOS 14.5, *)) {
228+
// Need ATT permission to use get old Apple Search Ads info
229+
XCTAssertNotNil(error);
230+
XCTAssert([@"The app is not authorized for ad tracking" isEqualToString:error.localizedDescription]);
231+
XCTAssertTrue(elapsedSeconds > 0);
232+
[expectation fulfill];
233+
234+
} else {
235+
XCTAssertNil(error);
236+
XCTAssertTrue(elapsedSeconds > 0);
237+
238+
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
239+
XCTAssertNotNil(tmpDict);
240+
241+
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
242+
XCTAssertNotNil(tmpBool);
243+
244+
[expectation fulfill];
245+
}
229246
}];
230247

231248
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {
@@ -238,16 +255,25 @@ - (void)testRequestAppleSearchAdsWithRetry_1 {
238255
__block XCTestExpectation *expectation = [self expectationWithDescription:@"AppleSearchAds"];
239256

240257
[self.appleSearchAds requestAttributionWithMaxAttempts:1 completion:^(NSDictionary * _Nullable attributionDetails, NSError * _Nullable error, NSTimeInterval elapsedSeconds) {
241-
XCTAssertNil(error);
242-
XCTAssertTrue(elapsedSeconds > 0);
243-
244-
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
245-
XCTAssertNotNil(tmpDict);
246-
247-
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
248-
XCTAssertNotNil(tmpBool);
249-
250-
[expectation fulfill];
258+
if (@available(iOS 14.5, *)) {
259+
// Need ATT permission to use get old Apple Search Ads info
260+
XCTAssertNotNil(error);
261+
XCTAssert([@"The app is not authorized for ad tracking" isEqualToString:error.localizedDescription]);
262+
XCTAssertTrue(elapsedSeconds > 0);
263+
[expectation fulfill];
264+
265+
} else {
266+
XCTAssertNil(error);
267+
XCTAssertTrue(elapsedSeconds > 0);
268+
269+
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
270+
XCTAssertNotNil(tmpDict);
271+
272+
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
273+
XCTAssertNotNil(tmpBool);
274+
275+
[expectation fulfill];
276+
}
251277
}];
252278

253279
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {
@@ -265,7 +291,7 @@ - (void)testRequestAppleSearchAdsWithRetry_NoResponse {
265291
XCTAssertNotNil(error);
266292
XCTAssertTrue(elapsedSeconds > 0);
267293
XCTAssertNil(attributionDetails);
268-
294+
269295
[expectation fulfill];
270296
}];
271297

@@ -283,19 +309,32 @@ - (void)testRequestAppleSearchAdsWithRetry_3 {
283309
self.appleSearchAds.adClient = mock;
284310

285311
[self.appleSearchAds requestAttributionWithMaxAttempts:3 completion:^(NSDictionary * _Nullable attributionDetails, NSError * _Nullable error, NSTimeInterval elapsedSeconds) {
286-
XCTAssertNil(error);
287-
XCTAssertTrue(elapsedSeconds > 0);
288-
289-
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
290-
XCTAssertNotNil(tmpDict);
291-
292-
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
293-
XCTAssertNotNil(tmpBool);
294-
295-
// verifies things were ignored
296-
XCTAssert(mock.ignoreCount == 2);
297-
298-
[expectation fulfill];
312+
if (@available(iOS 14.5, *)) {
313+
// Need ATT permission to use get old Apple Search Ads info
314+
XCTAssertNotNil(error);
315+
XCTAssert([@"The app is not authorized for ad tracking" isEqualToString:error.localizedDescription]);
316+
XCTAssertTrue(elapsedSeconds > 0);
317+
318+
// verifies things were ignored
319+
XCTAssert(mock.ignoreCount == 2);
320+
321+
[expectation fulfill];
322+
323+
} else {
324+
XCTAssertNil(error);
325+
XCTAssertTrue(elapsedSeconds > 0);
326+
327+
NSDictionary *tmpDict = [attributionDetails objectForKey:@"Version3.1"];
328+
XCTAssertNotNil(tmpDict);
329+
330+
NSNumber *tmpBool = [tmpDict objectForKey:@"iad-attribution"];
331+
XCTAssertNotNil(tmpBool);
332+
333+
// verifies things were ignored
334+
XCTAssert(mock.ignoreCount == 2);
335+
336+
[expectation fulfill];
337+
}
299338
}];
300339

301340
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {

0 commit comments

Comments
 (0)