-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// EUIDIMASecureSignalsAdapter.swift | ||
// | ||
|
||
import Foundation | ||
import GoogleInteractiveMediaAds | ||
import UID2 | ||
|
||
@available(iOS 13.0, *) | ||
@objc(EUIDIMASecureSignalsAdapter) | ||
public class EUIDIMASecureSignalsAdapter: NSObject { | ||
|
||
required public override init() { | ||
// Ensure UID2Manager has started | ||
_ = EUIDManager.shared | ||
} | ||
|
||
} | ||
|
||
extension EUIDIMASecureSignalsAdapter: IMASecureSignalsAdapter { | ||
|
||
public static func adapterVersion() -> IMAVersion { | ||
let version = IMAVersion() | ||
version.majorVersion = 0 | ||
version.minorVersion = 3 | ||
version.patchVersion = 3 | ||
return version | ||
} | ||
|
||
public static func adSDKVersion() -> IMAVersion { | ||
let sdkVersion = UID2SDKProperties.getUID2SDKVersion() | ||
let version = IMAVersion() | ||
version.majorVersion = sdkVersion.major | ||
version.minorVersion = sdkVersion.minor | ||
version.patchVersion = sdkVersion.patch | ||
return version | ||
} | ||
|
||
public func collectSignals(completion: @escaping IMASignalCompletionHandler) { | ||
Task { | ||
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else { | ||
completion(nil, AdvertisingTokenNotFoundError()) | ||
return | ||
} | ||
completion(advertisingToken, nil) | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Tests/UID2IMAPluginTests/EUIDIMASecureSignalsAdapterTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// EUIDIMASecureSignalsAdapterTests.swift | ||
// | ||
|
||
import XCTest | ||
import GoogleInteractiveMediaAds | ||
import UID2 | ||
import UID2IMAPlugin | ||
|
||
final class EUIDIMASecureSignalsAdapterTests: XCTestCase { | ||
/// 🟩 - IMA Adapter Request Signal Success | ||
func testRequestSignalsSuccess() async throws { | ||
// Seed the sample UID2Identity data in the UID2Manager | ||
await EUIDManager.shared.setAutomaticRefreshEnabled(false) | ||
await EUIDManager.shared.setIdentity( | ||
UID2Identity( | ||
advertisingToken: "euid-test-token", | ||
refreshToken: "refresh-token", | ||
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970, | ||
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970, | ||
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970, | ||
refreshResponseKey: "" | ||
) | ||
) | ||
|
||
let signal = try await EUIDIMASecureSignalsAdapter().collectSignals() | ||
|
||
// Confirm that Adapter returns expected data | ||
XCTAssertEqual("euid-test-token", signal) | ||
} | ||
|
||
/// 🟥 - GMA Adapter Request Signal Error No Identity | ||
func testRequestSignalsNoIdentity() async throws { | ||
// Ensure no identity is set | ||
await EUIDManager.shared.resetIdentity() | ||
|
||
let result = await Task<String?, Error> { | ||
try await EUIDIMASecureSignalsAdapter().collectSignals() | ||
}.result | ||
XCTAssertThrowsError(try result.get()) { error in | ||
let adapterError = error as? AdvertisingTokenNotFoundError | ||
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError) | ||
} | ||
} | ||
|
||
/// 🟥 - IMA Adapter Request Signal No Advertising Token Error | ||
func testRequestSignalsNoAdvertisingToken() async throws { | ||
// Set an identity with an invalid advertisingToken | ||
await EUIDManager.shared.setAutomaticRefreshEnabled(false) | ||
await EUIDManager.shared.setIdentity( | ||
UID2Identity( | ||
advertisingToken: "", | ||
refreshToken: "refresh-token", | ||
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970, | ||
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970, | ||
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970, | ||
refreshResponseKey: "" | ||
) | ||
) | ||
|
||
let result = await Task<String?, Error> { | ||
try await EUIDIMASecureSignalsAdapter().collectSignals() | ||
}.result | ||
XCTAssertThrowsError(try result.get()) { error in | ||
let adapterError = error as? AdvertisingTokenNotFoundError | ||
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError) | ||
} | ||
} | ||
|
||
func testAdSDKVersion() async throws { | ||
let adSDKVersion = EUIDIMASecureSignalsAdapter.adSDKVersion() | ||
let sdkVersion = await EUIDManager.shared.sdkVersion | ||
|
||
XCTAssertEqual(sdkVersion.major, adSDKVersion.majorVersion) | ||
XCTAssertEqual(sdkVersion.minor, adSDKVersion.minorVersion) | ||
XCTAssertEqual(sdkVersion.patch, adSDKVersion.patchVersion) | ||
} | ||
} |