From 5d8e3851fbb326a23083851a03e207b7fb0bd7d9 Mon Sep 17 00:00:00 2001 From: Cody Garvin Date: Wed, 10 Jun 2020 08:07:43 -0700 Subject: [PATCH] LIB-35: Updated class names for Swift --- Analytics/Classes/Crypto/SEGAES256Crypto.h | 1 + .../Classes/Integrations/SEGAliasPayload.h | 2 +- .../Classes/Integrations/SEGGroupPayload.h | 2 +- .../Classes/Integrations/SEGIdentifyPayload.h | 2 +- .../Classes/Integrations/SEGIntegration.h | 1 + .../Integrations/SEGIntegrationsManager.h | 2 +- Analytics/Classes/Integrations/SEGPayload.h | 7 +- .../Classes/Integrations/SEGScreenPayload.h | 1 + .../Classes/Integrations/SEGTrackPayload.h | 1 + Analytics/Classes/Internal/SEGFileStorage.h | 1 + Analytics/Classes/Internal/SEGHTTPClient.h | 1 + .../Classes/Internal/SEGSegmentIntegration.h | 1 + .../Internal/SEGSegmentIntegrationFactory.h | 1 + .../Classes/Internal/SEGStoreKitTracker.h | 1 + .../Classes/Internal/SEGUserDefaultsStorage.h | 1 + Analytics/Classes/Internal/SEGUtils.h | 1 + Analytics/Classes/Middlewares/SEGContext.h | 3 +- Analytics/Classes/Middlewares/SEGMiddleware.h | 4 ++ Analytics/Classes/SEGAnalytics.h | 4 +- Analytics/Classes/SEGAnalyticsConfiguration.h | 3 + Analytics/Vendor/SEGReachability.h | 1 + AnalyticsTests/AnalyticsTests.swift | 20 +++--- AnalyticsTests/AnalyticsUtilTests.swift | 8 +-- AnalyticsTests/AutoScreenReportingTest.swift | 2 +- AnalyticsTests/ContextTest.swift | 22 +++---- AnalyticsTests/CryptoTest.swift | 8 +-- AnalyticsTests/EndToEndTests.swift | 10 +-- AnalyticsTests/FileStorageTest.swift | 16 ++--- AnalyticsTests/HTTPClientTest.swift | 26 ++++---- AnalyticsTests/IntegrationsManagerTest.swift | 32 ++++----- AnalyticsTests/MiddlewareTests.swift | 66 +++++++++---------- AnalyticsTests/StoreKitTrackerTests.swift | 12 ++-- AnalyticsTests/TrackingTests.swift | 36 +++++----- AnalyticsTests/UserDefaultsStorageTest.swift | 12 ++-- AnalyticsTests/Utils/TestUtils.swift | 40 +++++------ 35 files changed, 187 insertions(+), 164 deletions(-) diff --git a/Analytics/Classes/Crypto/SEGAES256Crypto.h b/Analytics/Classes/Crypto/SEGAES256Crypto.h index 38bd66f9b..c8ff7e3b3 100644 --- a/Analytics/Classes/Crypto/SEGAES256Crypto.h +++ b/Analytics/Classes/Crypto/SEGAES256Crypto.h @@ -9,6 +9,7 @@ #import "SEGCrypto.h" +NS_SWIFT_NAME(AES256Crypto) @interface SEGAES256Crypto : NSObject @property (nonatomic, readonly, nonnull) NSString *password; diff --git a/Analytics/Classes/Integrations/SEGAliasPayload.h b/Analytics/Classes/Integrations/SEGAliasPayload.h index ed26bbaef..9983151af 100644 --- a/Analytics/Classes/Integrations/SEGAliasPayload.h +++ b/Analytics/Classes/Integrations/SEGAliasPayload.h @@ -3,7 +3,7 @@ NS_ASSUME_NONNULL_BEGIN - +NS_SWIFT_NAME(AliasPayload) @interface SEGAliasPayload : SEGPayload @property (nonatomic, readonly) NSString *theNewId; diff --git a/Analytics/Classes/Integrations/SEGGroupPayload.h b/Analytics/Classes/Integrations/SEGGroupPayload.h index 109e22543..2c823aa0d 100644 --- a/Analytics/Classes/Integrations/SEGGroupPayload.h +++ b/Analytics/Classes/Integrations/SEGGroupPayload.h @@ -3,7 +3,7 @@ NS_ASSUME_NONNULL_BEGIN - +NS_SWIFT_NAME(GroupPayload) @interface SEGGroupPayload : SEGPayload @property (nonatomic, readonly) NSString *groupId; diff --git a/Analytics/Classes/Integrations/SEGIdentifyPayload.h b/Analytics/Classes/Integrations/SEGIdentifyPayload.h index 84eab05d6..47440b4ab 100644 --- a/Analytics/Classes/Integrations/SEGIdentifyPayload.h +++ b/Analytics/Classes/Integrations/SEGIdentifyPayload.h @@ -3,7 +3,7 @@ NS_ASSUME_NONNULL_BEGIN - +NS_SWIFT_NAME(IdentifyPayload) @interface SEGIdentifyPayload : SEGPayload @property (nonatomic, readonly, nullable) NSString *userId; diff --git a/Analytics/Classes/Integrations/SEGIntegration.h b/Analytics/Classes/Integrations/SEGIntegration.h index 13c8b00b6..0820aafdd 100644 --- a/Analytics/Classes/Integrations/SEGIntegration.h +++ b/Analytics/Classes/Integrations/SEGIntegration.h @@ -9,6 +9,7 @@ NS_ASSUME_NONNULL_BEGIN +NS_SWIFT_NAME(Integration) @protocol SEGIntegration @optional diff --git a/Analytics/Classes/Integrations/SEGIntegrationsManager.h b/Analytics/Classes/Integrations/SEGIntegrationsManager.h index ec17275cb..661888e96 100644 --- a/Analytics/Classes/Integrations/SEGIntegrationsManager.h +++ b/Analytics/Classes/Integrations/SEGIntegrationsManager.h @@ -22,7 +22,7 @@ extern NSString *_Nonnull SEGAnalyticsIntegrationDidStart; @class SEGAnalytics; - +NS_SWIFT_NAME(IntegrationsManager) @interface SEGIntegrationsManager : NSObject // Exposed for testing. diff --git a/Analytics/Classes/Integrations/SEGPayload.h b/Analytics/Classes/Integrations/SEGPayload.h index cd4ca09ad..71d3f3441 100644 --- a/Analytics/Classes/Integrations/SEGPayload.h +++ b/Analytics/Classes/Integrations/SEGPayload.h @@ -3,7 +3,7 @@ NS_ASSUME_NONNULL_BEGIN - +NS_SWIFT_NAME(Payload) @interface SEGPayload : NSObject @property (nonatomic, readonly) JSON_DICT context; @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @end +NS_SWIFT_NAME(ApplicationLifecyclePayload) @interface SEGApplicationLifecyclePayload : SEGPayload @property (nonatomic, strong) NSString *notificationName; @@ -25,13 +26,14 @@ NS_ASSUME_NONNULL_BEGIN @end +NS_SWIFT_NAME(ContinueUserActivityPayload) @interface SEGContinueUserActivityPayload : SEGPayload @property (nonatomic, strong) NSUserActivity *activity; @end - +NS_SWIFT_NAME(OpenURLPayload) @interface SEGOpenURLPayload : SEGPayload @property (nonatomic, strong) NSURL *url; @@ -42,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END +NS_SWIFT_NAME(RemoteNotificationPayload) @interface SEGRemoteNotificationPayload : SEGPayload // SEGEventTypeHandleActionWithForRemoteNotification diff --git a/Analytics/Classes/Integrations/SEGScreenPayload.h b/Analytics/Classes/Integrations/SEGScreenPayload.h index 78e6639cd..b9bce04a3 100644 --- a/Analytics/Classes/Integrations/SEGScreenPayload.h +++ b/Analytics/Classes/Integrations/SEGScreenPayload.h @@ -4,6 +4,7 @@ NS_ASSUME_NONNULL_BEGIN +NS_SWIFT_NAME(ScreenPayload) @interface SEGScreenPayload : SEGPayload @property (nonatomic, readonly) NSString *name; diff --git a/Analytics/Classes/Integrations/SEGTrackPayload.h b/Analytics/Classes/Integrations/SEGTrackPayload.h index fc61b3f6d..feefb91a7 100644 --- a/Analytics/Classes/Integrations/SEGTrackPayload.h +++ b/Analytics/Classes/Integrations/SEGTrackPayload.h @@ -4,6 +4,7 @@ NS_ASSUME_NONNULL_BEGIN +NS_SWIFT_NAME(TrackPayload) @interface SEGTrackPayload : SEGPayload @property (nonatomic, readonly) NSString *event; diff --git a/Analytics/Classes/Internal/SEGFileStorage.h b/Analytics/Classes/Internal/SEGFileStorage.h index 6fbcf46ff..ca872c29c 100644 --- a/Analytics/Classes/Internal/SEGFileStorage.h +++ b/Analytics/Classes/Internal/SEGFileStorage.h @@ -9,6 +9,7 @@ #import "SEGStorage.h" +NS_SWIFT_NAME(FileStorage) @interface SEGFileStorage : NSObject @property (nonatomic, strong, nullable) id crypto; diff --git a/Analytics/Classes/Internal/SEGHTTPClient.h b/Analytics/Classes/Internal/SEGHTTPClient.h index 59a6897cd..ec8867e90 100644 --- a/Analytics/Classes/Internal/SEGHTTPClient.h +++ b/Analytics/Classes/Internal/SEGHTTPClient.h @@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN +NS_SWIFT_NAME(HTTPClient) @interface SEGHTTPClient : NSObject @property (nonatomic, strong) SEGRequestFactory requestFactory; diff --git a/Analytics/Classes/Internal/SEGSegmentIntegration.h b/Analytics/Classes/Internal/SEGSegmentIntegration.h index c32e01d70..3dacd3557 100644 --- a/Analytics/Classes/Internal/SEGSegmentIntegration.h +++ b/Analytics/Classes/Internal/SEGSegmentIntegration.h @@ -17,6 +17,7 @@ extern NSString *const kSEGQueueFilename; extern NSString *const kSEGTraitsFilename; +NS_SWIFT_NAME(SegmentIntegration) @interface SEGSegmentIntegration : NSObject - (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)httpClient fileStorage:(id)fileStorage userDefaultsStorage:(id)userDefaultsStorage; diff --git a/Analytics/Classes/Internal/SEGSegmentIntegrationFactory.h b/Analytics/Classes/Internal/SEGSegmentIntegrationFactory.h index 6aa38808b..b80a572b0 100644 --- a/Analytics/Classes/Internal/SEGSegmentIntegrationFactory.h +++ b/Analytics/Classes/Internal/SEGSegmentIntegrationFactory.h @@ -6,6 +6,7 @@ NS_ASSUME_NONNULL_BEGIN +NS_SWIFT_NAME(SegmentIntegrationFactory) @interface SEGSegmentIntegrationFactory : NSObject @property (nonatomic, strong) SEGHTTPClient *client; diff --git a/Analytics/Classes/Internal/SEGStoreKitTracker.h b/Analytics/Classes/Internal/SEGStoreKitTracker.h index ce271dc6b..87ede731c 100644 --- a/Analytics/Classes/Internal/SEGStoreKitTracker.h +++ b/Analytics/Classes/Internal/SEGStoreKitTracker.h @@ -5,6 +5,7 @@ NS_ASSUME_NONNULL_BEGIN +NS_SWIFT_NAME(StoreKitTracker) @interface SEGStoreKitTracker : NSObject + (instancetype)trackTransactionsForAnalytics:(SEGAnalytics *)analytics; diff --git a/Analytics/Classes/Internal/SEGUserDefaultsStorage.h b/Analytics/Classes/Internal/SEGUserDefaultsStorage.h index 1d594f722..a67448ec3 100644 --- a/Analytics/Classes/Internal/SEGUserDefaultsStorage.h +++ b/Analytics/Classes/Internal/SEGUserDefaultsStorage.h @@ -10,6 +10,7 @@ #import "SEGStorage.h" +NS_SWIFT_NAME(UserDefaultsStorage) @interface SEGUserDefaultsStorage : NSObject @property (nonatomic, strong, nullable) id crypto; diff --git a/Analytics/Classes/Internal/SEGUtils.h b/Analytics/Classes/Internal/SEGUtils.h index 330cba8a0..79a21d1e6 100644 --- a/Analytics/Classes/Internal/SEGUtils.h +++ b/Analytics/Classes/Internal/SEGUtils.h @@ -7,6 +7,7 @@ #import "SEGAnalyticsUtils.h" +NS_SWIFT_NAME(Utilities) @interface SEGUtils : NSObject + (NSData *_Nullable)dataFromPlist:(nonnull id)plist; diff --git a/Analytics/Classes/Middlewares/SEGContext.h b/Analytics/Classes/Middlewares/SEGContext.h index 30ac8353c..bbfc84433 100644 --- a/Analytics/Classes/Middlewares/SEGContext.h +++ b/Analytics/Classes/Middlewares/SEGContext.h @@ -42,12 +42,13 @@ typedef NS_ENUM(NSInteger, SEGEventType) { SEGEventTypeContinueUserActivity, SEGEventTypeOpenURL, -}; +} NS_SWIFT_NAME(EventType); @class SEGAnalytics; @protocol SEGMutableContext; +NS_SWIFT_NAME(Context) @interface SEGContext : NSObject // Loopback reference to the top level SEGAnalytics object. diff --git a/Analytics/Classes/Middlewares/SEGMiddleware.h b/Analytics/Classes/Middlewares/SEGMiddleware.h index 435af3e55..17f7ed82d 100644 --- a/Analytics/Classes/Middlewares/SEGMiddleware.h +++ b/Analytics/Classes/Middlewares/SEGMiddleware.h @@ -11,6 +11,7 @@ typedef void (^SEGMiddlewareNext)(SEGContext *_Nullable newContext); +NS_SWIFT_NAME(Middleware) @protocol SEGMiddleware @required @@ -33,6 +34,7 @@ typedef void (^SEGMiddlewareNext)(SEGContext *_Nullable newContext); typedef void (^SEGMiddlewareBlock)(SEGContext *_Nonnull context, SEGMiddlewareNext _Nonnull next); +NS_SWIFT_NAME(BlockMiddleware) @interface SEGBlockMiddleware : NSObject @property (nonnull, nonatomic, readonly) SEGMiddlewareBlock block; @@ -45,6 +47,7 @@ typedef void (^SEGMiddlewareBlock)(SEGContext *_Nonnull context, SEGMiddlewareNe typedef void (^RunMiddlewaresCallback)(BOOL earlyExit, NSArray> *_Nonnull remainingMiddlewares); // XXX TODO: Add some tests for SEGMiddlewareRunner +NS_SWIFT_NAME(MiddlewareRunner) @interface SEGMiddlewareRunner : NSObject // While it is certainly technically possible to change middlewares dynamically on the fly. we're explicitly NOT @@ -58,6 +61,7 @@ typedef void (^RunMiddlewaresCallback)(BOOL earlyExit, NSArray @end // Container object for middlewares for a specific destination. +NS_SWIFT_NAME(DestinationMiddleware) @interface SEGDestinationMiddleware : NSObject @property (nonatomic, strong, nonnull, readonly) NSString *integrationKey; @property (nonatomic, strong, nullable, readonly) NSArray> *middleware; diff --git a/Analytics/Classes/SEGAnalytics.h b/Analytics/Classes/SEGAnalytics.h index 9bab573f2..4af21710e 100644 --- a/Analytics/Classes/SEGAnalytics.h +++ b/Analytics/Classes/SEGAnalytics.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN */ @class SEGAnalyticsConfiguration; - +NS_SWIFT_NAME(Analytics) @interface SEGAnalytics : NSObject /** @@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN * * @see -setupWithConfiguration: */ -+ (instancetype _Nullable)sharedAnalytics; ++ (instancetype)sharedAnalytics; /*! @method diff --git a/Analytics/Classes/SEGAnalyticsConfiguration.h b/Analytics/Classes/SEGAnalyticsConfiguration.h index f016a1093..284a648c3 100644 --- a/Analytics/Classes/SEGAnalyticsConfiguration.h +++ b/Analytics/Classes/SEGAnalyticsConfiguration.h @@ -9,6 +9,7 @@ #import #import +NS_SWIFT_NAME(ApplicationProtocol) @protocol SEGApplicationProtocol @property (nullable, nonatomic, assign) id delegate; - (UIBackgroundTaskIdentifier)seg_beginBackgroundTaskWithName:(nullable NSString *)taskName expirationHandler:(void (^__nullable)(void))handler; @@ -32,6 +33,7 @@ typedef NSString *_Nonnull (^SEGAdSupportBlock)(void); /** * This object provides a set of properties to control various policies of the analytics client. Other than `writeKey`, these properties can be changed at any time. */ +NS_SWIFT_NAME(AnalyticsConfiguration) @interface SEGAnalyticsConfiguration : NSObject /** @@ -216,6 +218,7 @@ typedef NSString *_Nonnull (^SEGAdSupportBlock)(void); typedef NSDictionary * _Nonnull (^SEGRawModificationBlock)( NSDictionary * _Nonnull rawPayload); +NS_SWIFT_NAME(AnalyticsExperimental) @interface SEGAnalyticsExperimental : NSObject /** Experimental support for nanosecond timestamps. While the segment pipeline doesn't support this yet diff --git a/Analytics/Vendor/SEGReachability.h b/Analytics/Vendor/SEGReachability.h index 3c622ec68..d30415890 100644 --- a/Analytics/Vendor/SEGReachability.h +++ b/Analytics/Vendor/SEGReachability.h @@ -64,6 +64,7 @@ typedef void (^SEGNetworkReachable)(SEGReachability *reachability); typedef void (^SEGNetworkUnreachable)(SEGReachability *reachability); +NS_SWIFT_NAME(Reachability) @interface SEGReachability : NSObject @property (nonatomic, copy, nullable) SEGNetworkReachable reachableBlock; diff --git a/AnalyticsTests/AnalyticsTests.swift b/AnalyticsTests/AnalyticsTests.swift index a9b8b2e6c..53b026b6b 100644 --- a/AnalyticsTests/AnalyticsTests.swift +++ b/AnalyticsTests/AnalyticsTests.swift @@ -13,14 +13,14 @@ import Analytics class AnalyticsTests: QuickSpec { override func spec() { - let config = SEGAnalyticsConfiguration(writeKey: "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE") + let config = AnalyticsConfiguration(writeKey: "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE") let cachedSettings = [ "integrations": [ "Segment.io": ["apiKey": "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE"] ], "plan": ["track": [:]], ] as NSDictionary - var analytics: SEGAnalytics! + var analytics: Analytics! var testMiddleware: TestMiddleware! var testApplication: TestApplication! @@ -34,7 +34,7 @@ class AnalyticsTests: QuickSpec { UserDefaults.standard.set("test SEGQueue should be removed", forKey: "SEGQueue") expect(UserDefaults.standard.string(forKey: "SEGQueue")).toNot(beNil()) - analytics = SEGAnalytics(configuration: config) + analytics = Analytics(configuration: config) analytics.test_integrationsManager()?.test_setCachedSettings(settings: cachedSettings) } @@ -73,14 +73,14 @@ class AnalyticsTests: QuickSpec { }*/ it("persists anonymousId") { - let analytics2 = SEGAnalytics(configuration: config) + let analytics2 = Analytics(configuration: config) expect(analytics.getAnonymousId()) == analytics2.getAnonymousId() } it("persists userId") { analytics.identify("testUserId1") - let analytics2 = SEGAnalytics(configuration: config) + let analytics2 = Analytics(configuration: config) analytics2.test_integrationsManager()?.test_setCachedSettings(settings: cachedSettings) expect(analytics.test_integrationsManager()?.test_segmentIntegration()?.test_userId()) == "testUserId1" @@ -110,7 +110,7 @@ class AnalyticsTests: QuickSpec { UIApplicationLaunchOptionsKey.sourceApplication: "testApp", UIApplicationLaunchOptionsKey.url: "test://test", ]) - let event = testMiddleware.lastContext?.payload as? SEGTrackPayload + let event = testMiddleware.lastContext?.payload as? TrackPayload expect(event?.event) == "Application Opened" expect(event?.properties?["from_background"] as? Bool) == false expect(event?.properties?["referring_application"] as? String) == "testApp" @@ -120,7 +120,7 @@ class AnalyticsTests: QuickSpec { it("fires Application Opened during UIApplicationWillEnterForeground") { testMiddleware.swallowEvent = true NotificationCenter.default.post(name: .UIApplicationWillEnterForeground, object: testApplication) - let event = testMiddleware.lastContext?.payload as? SEGTrackPayload + let event = testMiddleware.lastContext?.payload as? TrackPayload expect(event?.event) == "Application Opened" expect(event?.properties?["from_background"] as? Bool) == true } @@ -128,7 +128,7 @@ class AnalyticsTests: QuickSpec { it("fires Application Backgrounded during UIApplicationDidEnterBackground") { testMiddleware.swallowEvent = true NotificationCenter.default.post(name: .UIApplicationDidEnterBackground, object: testApplication) - let event = testMiddleware.lastContext?.payload as? SEGTrackPayload + let event = testMiddleware.lastContext?.payload as? TrackPayload expect(event?.event) == "Application Backgrounded" } @@ -206,7 +206,7 @@ class AnalyticsTests: QuickSpec { analytics.open(URL(string: "fb123456789://authorize#access_token=hastoberedacted")!, options: [:]) - let event = testMiddleware.lastContext?.payload as? SEGTrackPayload + let event = testMiddleware.lastContext?.payload as? TrackPayload expect(event?.event) == "Deep Link Opened" expect(event?.properties?["url"] as? String) == "fb123456789://authorize#access_token=((redacted/fb-auth-token))" } @@ -218,7 +218,7 @@ class AnalyticsTests: QuickSpec { analytics.open(URL(string: "myapp://auth?token=hastoberedacted&other=stuff")!, options: [:]) - let event = testMiddleware.lastContext?.payload as? SEGTrackPayload + let event = testMiddleware.lastContext?.payload as? TrackPayload expect(event?.event) == "Deep Link Opened" expect(event?.properties?["url"] as? String) == "myapp://auth?token=((redacted/my-auth))&other=stuff" } diff --git a/AnalyticsTests/AnalyticsUtilTests.swift b/AnalyticsTests/AnalyticsUtilTests.swift index 8510f3913..53998922f 100644 --- a/AnalyticsTests/AnalyticsUtilTests.swift +++ b/AnalyticsTests/AnalyticsUtilTests.swift @@ -96,11 +96,11 @@ class AnalyticsUtilTests: QuickSpec { } it("works with strings") { - expect(SEGUtils.traverseJSON("a b foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar c" + expect(Utilities.traverseJSON("a b foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar c" } it("works recursively") { - expect(SEGUtils.traverseJSON("a b foo foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar foo-bar c" + expect(Utilities.traverseJSON("a b foo foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar foo-bar c" } it("works with nested dictionaries") { @@ -109,7 +109,7 @@ class AnalyticsUtilTests: QuickSpec { "bar": "foo" ] as [String: Any] - guard let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters) as? [String: Any] else { + guard let input = Utilities.traverseJSON(data, andReplaceWithFilters: filters) as? [String: Any] else { XCTFail("Failed to create actual result from traversed JSON replace") return } @@ -127,7 +127,7 @@ class AnalyticsUtilTests: QuickSpec { [1, nil, "qfoob", ["baz": "foo"]], "foo" ] as [Any] - let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters) + let input = Utilities.traverseJSON(data, andReplaceWithFilters: filters) let output = [ [1, nil, "qfoo-barb", ["baz": "foo-bar"]], "foo-bar" diff --git a/AnalyticsTests/AutoScreenReportingTest.swift b/AnalyticsTests/AutoScreenReportingTest.swift index 2bb715f87..a574b9024 100644 --- a/AnalyticsTests/AutoScreenReportingTest.swift +++ b/AnalyticsTests/AutoScreenReportingTest.swift @@ -17,7 +17,7 @@ class AutoScreenReportingTests: QuickSpec { var rootVC: UIViewController! beforeEach { - let config = SEGAnalyticsConfiguration(writeKey: "foobar") + let config = AnalyticsConfiguration(writeKey: "foobar") config.trackApplicationLifecycleEvents = true config.recordScreenViews = true diff --git a/AnalyticsTests/ContextTest.swift b/AnalyticsTests/ContextTest.swift index 58822175a..972aa884f 100644 --- a/AnalyticsTests/ContextTest.swift +++ b/AnalyticsTests/ContextTest.swift @@ -14,19 +14,19 @@ import Analytics class ContextTests: QuickSpec { override func spec() { - var analytics: SEGAnalytics! + var analytics: Analytics! beforeEach { - let config = SEGAnalyticsConfiguration(writeKey: "foobar") - analytics = SEGAnalytics(configuration: config) + let config = AnalyticsConfiguration(writeKey: "foobar") + analytics = Analytics(configuration: config) } it("throws when used incorrectly") { - var context: SEGContext? + var context: Context? var exception: NSException? SwiftTryCatch.tryRun({ - context = SEGContext() + context = Context() }, catchRun: { e in exception = e }, finallyRun: nil) @@ -37,25 +37,25 @@ class ContextTests: QuickSpec { it("initialized correctly") { - let context = SEGContext(analytics: analytics) + let context = Context(analytics: analytics) expect(context._analytics) == analytics - expect(context.eventType) == SEGEventType.undefined + expect(context.eventType) == EventType.undefined } it("accepts modifications") { - let context = SEGContext(analytics: analytics) + let context = Context(analytics: analytics) let newContext = context.modify { context in context.userId = "sloth" context.eventType = .track; } expect(newContext.userId) == "sloth" - expect(newContext.eventType) == SEGEventType.track; + expect(newContext.eventType) == EventType.track; } it("modifies copy in debug mode to catch bugs") { - let context = SEGContext(analytics: analytics).modify { context in + let context = Context(analytics: analytics).modify { context in context.debug = true } expect(context.debug) == true @@ -69,7 +69,7 @@ class ContextTests: QuickSpec { } it("modifies self in non-debug mode to optimize perf.") { - let context = SEGContext(analytics: analytics).modify { context in + let context = Context(analytics: analytics).modify { context in context.debug = false } expect(context.debug) == false diff --git a/AnalyticsTests/CryptoTest.swift b/AnalyticsTests/CryptoTest.swift index b56cddf22..daa179283 100644 --- a/AnalyticsTests/CryptoTest.swift +++ b/AnalyticsTests/CryptoTest.swift @@ -11,9 +11,9 @@ import Analytics class CryptoTest : QuickSpec { override func spec() { - var crypto : SEGAES256Crypto! + var crypto : AES256Crypto! beforeEach { - crypto = SEGAES256Crypto(password: "slothysloth") + crypto = AES256Crypto(password: "slothysloth") } it("encrypts and decrypts data") { @@ -35,7 +35,7 @@ class CryptoTest : QuickSpec { let encryptedData = crypto.encrypt(dataIn) expect(encryptedData).toNot(beNil()) - let crypto2 = SEGAES256Crypto(password: "wolf", salt: crypto.salt, iv: crypto.iv) + let crypto2 = AES256Crypto(password: "wolf", salt: crypto.salt, iv: crypto.iv) let dataOut = crypto2.decrypt(encryptedData!) expect(dataOut) != dataIn let strOut = String(data: dataOut!, encoding: String.Encoding.utf8) @@ -50,7 +50,7 @@ class CryptoTest : QuickSpec { let encryptedData = crypto.encrypt(dataIn) expect(encryptedData).toNot(beNil()) - let crypto2 = SEGAES256Crypto(password: crypto.password) + let crypto2 = AES256Crypto(password: crypto.password) let dataOut = crypto2.decrypt(encryptedData!) expect(dataOut) != dataIn diff --git a/AnalyticsTests/EndToEndTests.swift b/AnalyticsTests/EndToEndTests.swift index 59ce12f21..e126a936c 100644 --- a/AnalyticsTests/EndToEndTests.swift +++ b/AnalyticsTests/EndToEndTests.swift @@ -3,18 +3,18 @@ import XCTest class EndToEndTests: XCTestCase { - var analytics: SEGAnalytics! + var analytics: Analytics! override func setUp() { super.setUp() // Write Key for https://app.segment.com/segment-libraries/sources/analytics_ios_e2e_test/overview - let config = SEGAnalyticsConfiguration(writeKey: "3VxTfPsVOoEOSbbzzbFqVNcYMNu2vjnr") + let config = AnalyticsConfiguration(writeKey: "3VxTfPsVOoEOSbbzzbFqVNcYMNu2vjnr") config.flushAt = 1 - SEGAnalytics.setup(with: config) + Analytics.setup(with: config) - analytics = SEGAnalytics.shared() + analytics = Analytics.shared() } override func tearDown() { @@ -27,7 +27,7 @@ class EndToEndTests: XCTestCase { let uuid = UUID().uuidString let expectation = XCTestExpectation(description: "SegmentRequestDidSucceed") - SEGAnalytics.shared()?.configuration.experimental.rawSegmentModificationBlock = { data in + Analytics.shared().configuration.experimental.rawSegmentModificationBlock = { data in if let properties = data["properties"] as? Dictionary, let tempUUID = properties["id"] as? String, tempUUID == uuid { expectation.fulfill() diff --git a/AnalyticsTests/FileStorageTest.swift b/AnalyticsTests/FileStorageTest.swift index 7f1884519..993318ccc 100644 --- a/AnalyticsTests/FileStorageTest.swift +++ b/AnalyticsTests/FileStorageTest.swift @@ -11,16 +11,16 @@ import Analytics class FileStorageTest : QuickSpec { override func spec() { - var storage : SEGFileStorage! + var storage : FileStorage! beforeEach { - let url = SEGFileStorage.applicationSupportDirectoryURL() + let url = FileStorage.applicationSupportDirectoryURL() expect(url).toNot(beNil()) expect(url?.lastPathComponent) == "Application Support" - storage = SEGFileStorage(folder: url!, crypto: nil) + storage = FileStorage(folder: url!, crypto: nil) } it("Creates caches directory") { - let url = SEGFileStorage.cachesDirectoryURL() + let url = FileStorage.cachesDirectoryURL() expect(url).toNot(beNil()) expect(url?.lastPathComponent) == "Caches" } @@ -30,7 +30,7 @@ class FileStorageTest : QuickSpec { let url = tempDir.appendingPathComponent(NSUUID().uuidString) expect(try? url?.checkResourceIsReachable()).to(beNil()) - _ = SEGFileStorage(folder: url!, crypto: nil) + _ = FileStorage(folder: url!, crypto: nil) var isDir: ObjCBool = false let exists = FileManager.default.fileExists(atPath: url!.path, isDirectory: &isDir) @@ -109,9 +109,9 @@ class FileStorageTest : QuickSpec { } it("should work with crypto") { - let url = SEGFileStorage.applicationSupportDirectoryURL() - let crypto = SEGAES256Crypto(password: "thetrees") - let s = SEGFileStorage(folder: url!, crypto: crypto) + let url = FileStorage.applicationSupportDirectoryURL() + let crypto = AES256Crypto(password: "thetrees") + let s = FileStorage(folder: url!, crypto: crypto) let dict = [ "san francisco": "tech", "new york": "finance", diff --git a/AnalyticsTests/HTTPClientTest.swift b/AnalyticsTests/HTTPClientTest.swift index d25c2b696..9ae2ab64b 100644 --- a/AnalyticsTests/HTTPClientTest.swift +++ b/AnalyticsTests/HTTPClientTest.swift @@ -14,11 +14,11 @@ import Analytics class HTTPClientTest: QuickSpec { override func spec() { - var client: SEGHTTPClient! + var client: HTTPClient! beforeEach { LSNocilla.sharedInstance().start() - client = SEGHTTPClient(requestFactory: nil) + client = HTTPClient(requestFactory: nil) } afterEach { LSNocilla.sharedInstance().clearStubs() @@ -27,7 +27,7 @@ class HTTPClientTest: QuickSpec { describe("defaultRequestFactory") { it("preserves url") { - let factory = SEGHTTPClient.defaultRequestFactory() + let factory = HTTPClient.defaultRequestFactory() let url = URL(string: "https://api.segment.io/v1/batch") let request = factory(url!) expect(request.url) == url @@ -37,7 +37,7 @@ class HTTPClientTest: QuickSpec { describe("settingsForWriteKey") { it("succeeds for 2xx response") { _ = stubRequest("GET", "https://cdn-settings.segment.com/v1/projects/foo/settings" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withHeaders(["Accept-Encoding" : "gzip" ])! .andReturn(200)! .withHeaders(["Content-Type" : "application/json"])! @@ -64,7 +64,7 @@ class HTTPClientTest: QuickSpec { it("fails for non 2xx response") { _ = stubRequest("GET", "https://cdn-settings.segment.com/v1/projects/foo/settings" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withHeaders(["Accept-Encoding" : "gzip" ])! .andReturn(400)! .withHeaders(["Content-Type" : "application/json" ])! @@ -80,7 +80,7 @@ class HTTPClientTest: QuickSpec { it("fails for json error") { _ = stubRequest("GET", "https://cdn-settings.segment.com/v1/projects/foo/settings" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withHeaders(["Accept-Encoding":"gzip"])! .andReturn(200)! .withHeaders(["Content-Type":"application/json"])! @@ -117,7 +117,7 @@ class HTTPClientTest: QuickSpec { it("does not ask to retry for 2xx response") { _ = stubRequest("POST", "https://api.segment.io/v1/batch" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withJsonGzippedBody(batch as AnyObject) .withWriteKey("bar") .andReturn(200) @@ -132,7 +132,7 @@ class HTTPClientTest: QuickSpec { it("asks to retry for 3xx response") { _ = stubRequest("POST", "https://api.segment.io/v1/batch" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withJsonGzippedBody(batch as AnyObject) .withWriteKey("bar") .andReturn(304) @@ -147,7 +147,7 @@ class HTTPClientTest: QuickSpec { it("does not ask to retry for 4xx response") { _ = stubRequest("POST", "https://api.segment.io/v1/batch" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withJsonGzippedBody(batch as AnyObject) .withWriteKey("bar") .andReturn(401) @@ -162,7 +162,7 @@ class HTTPClientTest: QuickSpec { it("asks to retry for 429 response") { _ = stubRequest("POST", "https://api.segment.io/v1/batch" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withJsonGzippedBody(batch as AnyObject) .withWriteKey("bar") .andReturn(429) @@ -177,7 +177,7 @@ class HTTPClientTest: QuickSpec { it("asks to retry for 5xx response") { _ = stubRequest("POST", "https://api.segment.io/v1/batch" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withJsonGzippedBody(batch as AnyObject) .withWriteKey("bar") .andReturn(504) @@ -228,7 +228,7 @@ class HTTPClientTest: QuickSpec { it("succeeds for 2xx response") { _ = stubRequest("POST", "https://mobile-service.segment.com/v1/attribution" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withWriteKey("foo") .andReturn(200)! .withBody("{\"provider\": \"mock\"}" as NSString) @@ -247,7 +247,7 @@ class HTTPClientTest: QuickSpec { it("fails for non 2xx response") { _ = stubRequest("POST", "https://mobile-service.segment.com/v1/attribution" as NSString) - .withHeader("User-Agent", "analytics-ios/" + SEGAnalytics.version())! + .withHeader("User-Agent", "analytics-ios/" + Analytics.version())! .withWriteKey("foo") .andReturn(404)! .withBody("not found" as NSString) diff --git a/AnalyticsTests/IntegrationsManagerTest.swift b/AnalyticsTests/IntegrationsManagerTest.swift index 0942ef89d..4fa2700d2 100644 --- a/AnalyticsTests/IntegrationsManagerTest.swift +++ b/AnalyticsTests/IntegrationsManagerTest.swift @@ -12,8 +12,8 @@ class IntegrationsManagerTest: QuickSpec { it("valid value types are used in integration enablement flags") { var exception: NSException? = nil SwiftTryCatch.tryRun({ - SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": ["blah": 1]]) - SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": true]) + IntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": ["blah": 1]]) + IntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": true]) }, catchRun: { e in exception = e }, finallyRun: nil) @@ -24,7 +24,7 @@ class IntegrationsManagerTest: QuickSpec { it("asserts when invalid value types are used integration enablement flags") { var exception: NSException? = nil SwiftTryCatch.tryRun({ - SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": "blah"]) + IntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": "blah"]) }, catchRun: { e in exception = e }, finallyRun: nil) @@ -36,7 +36,7 @@ class IntegrationsManagerTest: QuickSpec { var exception: NSException? = nil SwiftTryCatch.tryRun({ // we don't accept array's as values. - SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": ["key", 1]]) + IntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": ["key", 1]]) }, catchRun: { e in exception = e }, finallyRun: nil) @@ -45,59 +45,59 @@ class IntegrationsManagerTest: QuickSpec { } it("pulls valid integration data when supplied") { - let enabled = SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": true]) + let enabled = IntegrationsManager.isIntegration("comScore", enabledInOptions: ["comScore": true]) expect(enabled).to(beTrue()) } it("falls back correctly when values aren't explicitly specified") { - let enabled = SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["all": true]) + let enabled = IntegrationsManager.isIntegration("comScore", enabledInOptions: ["all": true]) expect(enabled).to(beTrue()) - let allEnabled = SEGIntegrationsManager.isIntegration("comScore", enabledInOptions: ["All": true]) + let allEnabled = IntegrationsManager.isIntegration("comScore", enabledInOptions: ["All": true]) expect(allEnabled).to(beTrue()) } it("returns true when there is no plan") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Amplitude", inPlan:[:]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Amplitude", inPlan:[:]) expect(enabled).to(beTrue()) } it("returns true when plan is empty") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":[:]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":[:]]) expect(enabled).to(beTrue()) } it("returns true when plan enables event") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true]]]) expect(enabled).to(beTrue()) } it("returns false when plan disables event") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Amplitude", inPlan:["track":["hello world":["enabled":false]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Amplitude", inPlan:["track":["hello world":["enabled":false]]]) expect(enabled).to(beFalse()) } it("returns true for Segment integration even when plan disables event") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Segment.io", inPlan:["track":["hello world":["enabled":false]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Segment.io", inPlan:["track":["hello world":["enabled":false]]]) expect(enabled).to(beTrue()) } it("returns true when plan enables event for integration") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true, "integrations":["Mixpanel":true]]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true, "integrations":["Mixpanel":true]]]]) expect(enabled).to(beTrue()) } it("returns false when plan disables event for integration") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true, "integrations":["Mixpanel":false]]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true, "integrations":["Mixpanel":false]]]]) expect(enabled).to(beFalse()) } it("returns false when plan disables new events by default") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["__default":["enabled":false]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["__default":["enabled":false]]]) expect(enabled).to(beFalse()) } it("returns uses event plan rather over defaults") { - let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["__default":["enabled":false],"hello world":["enabled":true]]]) + let enabled = IntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["__default":["enabled":false],"hello world":["enabled":true]]]) expect(enabled).to(beTrue()) } } diff --git a/AnalyticsTests/MiddlewareTests.swift b/AnalyticsTests/MiddlewareTests.swift index 84746cb09..507507517 100644 --- a/AnalyticsTests/MiddlewareTests.swift +++ b/AnalyticsTests/MiddlewareTests.swift @@ -12,17 +12,17 @@ import Nimble import Analytics // Changing event names and adding custom attributes -let customizeAllTrackCalls = SEGBlockMiddleware { (context, next) in +let customizeAllTrackCalls = BlockMiddleware { (context, next) in if context.eventType == .track { next(context.modify { ctx in - guard let track = ctx.payload as? SEGTrackPayload else { + guard let track = ctx.payload as? TrackPayload else { return } let newEvent = "[New] \(track.event)" var newProps = track.properties ?? [:] newProps["customAttribute"] = "Hello" newProps["nullTest"] = NSNull() - ctx.payload = SEGTrackPayload( + ctx.payload = TrackPayload( event: newEvent, properties: newProps, context: track.context, @@ -35,35 +35,35 @@ let customizeAllTrackCalls = SEGBlockMiddleware { (context, next) in } // Simply swallows all calls and does not pass events downstream -let eatAllCalls = SEGBlockMiddleware { (context, next) in +let eatAllCalls = BlockMiddleware { (context, next) in } class SourceMiddlewareTests: QuickSpec { override func spec() { it("receives events") { - let config = SEGAnalyticsConfiguration(writeKey: "TESTKEY") - let passthrough = SEGPassthroughMiddleware() + let config = AnalyticsConfiguration(writeKey: "TESTKEY") + let passthrough = PassthroughMiddleware() config.sourceMiddleware = [ passthrough, ] - let analytics = SEGAnalytics(configuration: config) + let analytics = Analytics(configuration: config) analytics.identify("testUserId1") - expect(passthrough.lastContext?.eventType) == SEGEventType.identify - let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload + expect(passthrough.lastContext?.eventType) == EventType.identify + let identify = passthrough.lastContext?.payload as? IdentifyPayload expect(identify?.userId) == "testUserId1" } it("modifies and passes event to next") { - let config = SEGAnalyticsConfiguration(writeKey: "TESTKEY") - let passthrough = SEGPassthroughMiddleware() + let config = AnalyticsConfiguration(writeKey: "TESTKEY") + let passthrough = PassthroughMiddleware() config.sourceMiddleware = [ customizeAllTrackCalls, passthrough, ] - let analytics = SEGAnalytics(configuration: config) + let analytics = Analytics(configuration: config) analytics.track("Purchase Success") - expect(passthrough.lastContext?.eventType) == SEGEventType.track - let track = passthrough.lastContext?.payload as? SEGTrackPayload + expect(passthrough.lastContext?.eventType) == EventType.track + let track = passthrough.lastContext?.payload as? TrackPayload expect(track?.event) == "[New] Purchase Success" expect(track?.properties?["customAttribute"] as? String) == "Hello" let isNull = (track?.properties?["nullTest"] is NSNull) @@ -71,13 +71,13 @@ class SourceMiddlewareTests: QuickSpec { } it("expects event to be swallowed if next is not called") { - let config = SEGAnalyticsConfiguration(writeKey: "TESTKEY") - let passthrough = SEGPassthroughMiddleware() + let config = AnalyticsConfiguration(writeKey: "TESTKEY") + let passthrough = PassthroughMiddleware() config.sourceMiddleware = [ eatAllCalls, passthrough, ] - let analytics = SEGAnalytics(configuration: config) + let analytics = Analytics(configuration: config) analytics.track("Purchase Success") expect(passthrough.lastContext).to(beNil()) } @@ -87,10 +87,10 @@ class SourceMiddlewareTests: QuickSpec { class IntegrationMiddlewareTests: QuickSpec { override func spec() { it("receives events") { - let config = SEGAnalyticsConfiguration(writeKey: "TESTKEY") - let passthrough = SEGPassthroughMiddleware() - config.destinationMiddleware = [SEGDestinationMiddleware(key: SEGSegmentIntegrationFactory().key(), middleware: [passthrough])] - let analytics = SEGAnalytics(configuration: config) + let config = AnalyticsConfiguration(writeKey: "TESTKEY") + let passthrough = PassthroughMiddleware() + config.destinationMiddleware = [DestinationMiddleware(key: SegmentIntegrationFactory().key(), middleware: [passthrough])] + let analytics = Analytics(configuration: config) analytics.identify("testUserId1") // pump the runloop until we have a last context. @@ -105,16 +105,16 @@ class IntegrationMiddlewareTests: QuickSpec { } } - expect(passthrough.lastContext?.eventType) == SEGEventType.identify - let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload + expect(passthrough.lastContext?.eventType) == EventType.identify + let identify = passthrough.lastContext?.payload as? IdentifyPayload expect(identify?.userId) == "testUserId1" } it("modifies and passes event to next") { - let config = SEGAnalyticsConfiguration(writeKey: "TESTKEY") - let passthrough = SEGPassthroughMiddleware() - config.destinationMiddleware = [SEGDestinationMiddleware(key: SEGSegmentIntegrationFactory().key(), middleware: [customizeAllTrackCalls, passthrough])] - let analytics = SEGAnalytics(configuration: config) + let config = AnalyticsConfiguration(writeKey: "TESTKEY") + let passthrough = PassthroughMiddleware() + config.destinationMiddleware = [DestinationMiddleware(key: SegmentIntegrationFactory().key(), middleware: [customizeAllTrackCalls, passthrough])] + let analytics = Analytics(configuration: config) analytics.track("Purchase Success") // pump the runloop until we have a last context. @@ -129,8 +129,8 @@ class IntegrationMiddlewareTests: QuickSpec { } } - expect(passthrough.lastContext?.eventType) == SEGEventType.track - let track = passthrough.lastContext?.payload as? SEGTrackPayload + expect(passthrough.lastContext?.eventType) == EventType.track + let track = passthrough.lastContext?.payload as? TrackPayload expect(track?.event) == "[New] Purchase Success" expect(track?.properties?["customAttribute"] as? String) == "Hello" let isNull = (track?.properties?["nullTest"] is NSNull) @@ -138,10 +138,10 @@ class IntegrationMiddlewareTests: QuickSpec { } it("expects event to be swallowed if next is not called") { - let config = SEGAnalyticsConfiguration(writeKey: "TESTKEY") - let passthrough = SEGPassthroughMiddleware() - config.destinationMiddleware = [SEGDestinationMiddleware(key: SEGSegmentIntegrationFactory().key(), middleware: [eatAllCalls, passthrough])] - let analytics = SEGAnalytics(configuration: config) + let config = AnalyticsConfiguration(writeKey: "TESTKEY") + let passthrough = PassthroughMiddleware() + config.destinationMiddleware = [DestinationMiddleware(key: SegmentIntegrationFactory().key(), middleware: [eatAllCalls, passthrough])] + let analytics = Analytics(configuration: config) analytics.track("Purchase Success") // Since we're testing that an event is dropped, the previously used run loop pump won't work here. diff --git a/AnalyticsTests/StoreKitTrackerTests.swift b/AnalyticsTests/StoreKitTrackerTests.swift index 0a67decb1..cee21c01c 100644 --- a/AnalyticsTests/StoreKitTrackerTests.swift +++ b/AnalyticsTests/StoreKitTrackerTests.swift @@ -43,15 +43,15 @@ class StoreKitTrackerTests: QuickSpec { override func spec() { var test: TestMiddleware! - var tracker: SEGStoreKitTracker! - var analytics: SEGAnalytics! + var tracker: StoreKitTracker! + var analytics: Analytics! beforeEach { - let config = SEGAnalyticsConfiguration(writeKey: "foobar") + let config = AnalyticsConfiguration(writeKey: "foobar") test = TestMiddleware() config.sourceMiddleware = [test] - analytics = SEGAnalytics(configuration: config) - tracker = SEGStoreKitTracker.trackTransactions(for: analytics) + analytics = Analytics(configuration: config) + tracker = StoreKitTracker.trackTransactions(for: analytics) } it("SKPaymentQueue Observer") { @@ -61,7 +61,7 @@ class StoreKitTrackerTests: QuickSpec { tracker.productsRequest(SKProductsRequest(), didReceive: mockProductResponse()) - let payload = test.lastContext?.payload as? SEGTrackPayload + let payload = test.lastContext?.payload as? TrackPayload expect(payload?.event) == "Order Completed" } diff --git a/AnalyticsTests/TrackingTests.swift b/AnalyticsTests/TrackingTests.swift index 29275ca14..571445efa 100644 --- a/AnalyticsTests/TrackingTests.swift +++ b/AnalyticsTests/TrackingTests.swift @@ -13,16 +13,16 @@ import Analytics class TrackingTests: QuickSpec { override func spec() { - var passthrough: SEGPassthroughMiddleware! - var analytics: SEGAnalytics! + var passthrough: PassthroughMiddleware! + var analytics: Analytics! beforeEach { - let config = SEGAnalyticsConfiguration(writeKey: "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE") - passthrough = SEGPassthroughMiddleware() + let config = AnalyticsConfiguration(writeKey: "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE") + passthrough = PassthroughMiddleware() config.sourceMiddleware = [ passthrough, ] - analytics = SEGAnalytics(configuration: config) + analytics = Analytics(configuration: config) } afterEach { @@ -33,8 +33,8 @@ class TrackingTests: QuickSpec { analytics.identify("testUserId1", traits: [ "firstName": "Peter" ]) - expect(passthrough.lastContext?.eventType) == SEGEventType.identify - let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload + expect(passthrough.lastContext?.eventType) == EventType.identify + let identify = passthrough.lastContext?.payload as? IdentifyPayload expect(identify?.userId) == "testUserId1" expect(identify?.anonymousId).toNot(beNil()) expect(identify?.traits?["firstName"] as? String) == "Peter" @@ -46,8 +46,8 @@ class TrackingTests: QuickSpec { ], options: [ "anonymousId": "a_custom_anonymous_id" ]) - expect(passthrough.lastContext?.eventType) == SEGEventType.identify - let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload + expect(passthrough.lastContext?.eventType) == EventType.identify + let identify = passthrough.lastContext?.payload as? IdentifyPayload expect(identify?.userId) == "testUserId1" expect(identify?.anonymousId) == "a_custom_anonymous_id" expect(identify?.traits?["firstName"] as? String) == "Peter" @@ -63,16 +63,16 @@ class TrackingTests: QuickSpec { ] ] ]) - expect(passthrough.lastContext?.eventType) == SEGEventType.track - let payload = passthrough.lastContext?.payload as? SEGTrackPayload + expect(passthrough.lastContext?.eventType) == EventType.track + let payload = passthrough.lastContext?.payload as? TrackPayload expect(payload?.event) == "User Signup" expect(payload?.properties?["method"] as? String) == "SSO" } it("handles alias:") { analytics.alias("persistentUserId") - expect(passthrough.lastContext?.eventType) == SEGEventType.alias - let payload = passthrough.lastContext?.payload as? SEGAliasPayload + expect(passthrough.lastContext?.eventType) == EventType.alias + let payload = passthrough.lastContext?.payload as? AliasPayload expect(payload?.theNewId) == "persistentUserId" } @@ -80,8 +80,8 @@ class TrackingTests: QuickSpec { analytics.screen("Home", properties: [ "referrer": "Google" ]) - expect(passthrough.lastContext?.eventType) == SEGEventType.screen - let screen = passthrough.lastContext?.payload as? SEGScreenPayload + expect(passthrough.lastContext?.eventType) == EventType.screen + let screen = passthrough.lastContext?.payload as? ScreenPayload expect(screen?.name) == "Home" expect(screen?.properties?["referrer"] as? String) == "Google" } @@ -90,8 +90,8 @@ class TrackingTests: QuickSpec { analytics.group("acme-company", traits: [ "employees": 2333 ]) - expect(passthrough.lastContext?.eventType) == SEGEventType.group - let payload = passthrough.lastContext?.payload as? SEGGroupPayload + expect(passthrough.lastContext?.eventType) == EventType.group + let payload = passthrough.lastContext?.payload as? GroupPayload expect(payload?.groupId) == "acme-company" expect(payload?.traits?["employees"] as? Int) == 2333 } @@ -100,7 +100,7 @@ class TrackingTests: QuickSpec { analytics.track("null test", properties: [ "nullTest": NSNull() ]) - let payload = passthrough.lastContext?.payload as? SEGTrackPayload + let payload = passthrough.lastContext?.payload as? TrackPayload let isNull = (payload?.properties?["nullTest"] is NSNull) expect(isNull) == true } diff --git a/AnalyticsTests/UserDefaultsStorageTest.swift b/AnalyticsTests/UserDefaultsStorageTest.swift index 83185270d..727225157 100644 --- a/AnalyticsTests/UserDefaultsStorageTest.swift +++ b/AnalyticsTests/UserDefaultsStorageTest.swift @@ -11,12 +11,12 @@ import Analytics class UserDefaultsStorageTest : QuickSpec { override func spec() { - var storage : SEGUserDefaultsStorage! + var storage : UserDefaultsStorage! beforeEach { // let crypto = SEGAES256Crypto(password: "thetrees") // storage = SEGUserDefaultsStorage(defaults: NSUserDefaults.standardUserDefaults(), namespacePrefix: "segment", crypto: crypto) // storage = SEGUserDefaultsStorage(defaults: NSUserDefaults.standardUserDefaults(), namespacePrefix: nil, crypto: crypto) - storage = SEGUserDefaultsStorage(defaults: UserDefaults.standard, namespacePrefix: nil, crypto: nil) + storage = UserDefaultsStorage(defaults: UserDefaults.standard, namespacePrefix: nil, crypto: nil) } it("persists and loads data") { @@ -66,8 +66,8 @@ class UserDefaultsStorageTest : QuickSpec { } it("should work with crypto") { - let crypto = SEGAES256Crypto(password: "thetrees") - let s = SEGUserDefaultsStorage(defaults: UserDefaults.standard, namespacePrefix: nil, crypto: crypto) + let crypto = AES256Crypto(password: "thetrees") + let s = UserDefaultsStorage(defaults: UserDefaults.standard, namespacePrefix: nil, crypto: crypto) let dict = [ "san francisco": "tech", "new york": "finance", @@ -82,8 +82,8 @@ class UserDefaultsStorageTest : QuickSpec { it("should work with namespace") { - let crypto = SEGAES256Crypto(password: "thetrees") - let s = SEGUserDefaultsStorage(defaults: UserDefaults.standard, namespacePrefix: "segment", crypto: crypto) + let crypto = AES256Crypto(password: "thetrees") + let s = UserDefaultsStorage(defaults: UserDefaults.standard, namespacePrefix: "segment", crypto: crypto) let dict = [ "san francisco": "tech", "new york": "finance", diff --git a/AnalyticsTests/Utils/TestUtils.swift b/AnalyticsTests/Utils/TestUtils.swift index 2752b803e..f0e9aa19f 100644 --- a/AnalyticsTests/Utils/TestUtils.swift +++ b/AnalyticsTests/Utils/TestUtils.swift @@ -10,19 +10,19 @@ import Nocilla import Analytics -class SEGPassthroughMiddleware: SEGMiddleware { - var lastContext: SEGContext? +class PassthroughMiddleware: Middleware { + var lastContext: Context? - func context(_ context: SEGContext, next: @escaping SEGMiddlewareNext) { + func context(_ context: Context, next: @escaping SEGMiddlewareNext) { lastContext = context; next(context) } } -class TestMiddleware: SEGMiddleware { - var lastContext: SEGContext? +class TestMiddleware: Middleware { + var lastContext: Context? var swallowEvent = false - func context(_ context: SEGContext, next: @escaping SEGMiddlewareNext) { + func context(_ context: Context, next: @escaping SEGMiddlewareNext) { lastContext = context if !swallowEvent { next(context) @@ -30,27 +30,27 @@ class TestMiddleware: SEGMiddleware { } } -extension SEGAnalytics { - func test_integrationsManager() -> SEGIntegrationsManager? { - return self.value(forKey: "integrationsManager") as? SEGIntegrationsManager +extension Analytics { + func test_integrationsManager() -> IntegrationsManager? { + return self.value(forKey: "integrationsManager") as? IntegrationsManager } } -extension SEGIntegrationsManager { - func test_integrations() -> [String: SEGIntegration]? { - return self.value(forKey: "integrations") as? [String: SEGIntegration] +extension IntegrationsManager { + func test_integrations() -> [String: Integration]? { + return self.value(forKey: "integrations") as? [String: Integration] } - func test_segmentIntegration() -> SEGSegmentIntegration? { - return self.test_integrations()?["Segment.io"] as? SEGSegmentIntegration + func test_segmentIntegration() -> SegmentIntegration? { + return self.test_integrations()?["Segment.io"] as? SegmentIntegration } func test_setCachedSettings(settings: NSDictionary) { self.perform(Selector(("setCachedSettings:")), with: settings) } } -extension SEGSegmentIntegration { - func test_fileStorage() -> SEGFileStorage? { - return self.value(forKey: "fileStorage") as? SEGFileStorage +extension SegmentIntegration { + func test_fileStorage() -> FileStorage? { + return self.value(forKey: "fileStorage") as? FileStorage } func test_referrer() -> [String: AnyObject]? { return self.value(forKey: "referrer") as? [String: AnyObject] @@ -151,7 +151,7 @@ typealias AndSegmentWriteKeyMethod = (String) -> LSStubRequestDSL extension LSStubRequestDSL { var withWriteKey: AndSegmentWriteKeyMethod { return { writeKey in - let base64Token = SEGHTTPClient.authorizationHeader(writeKey) + let base64Token = HTTPClient.authorizationHeader(writeKey) return self.withHeaders([ "Authorization": "Basic \(base64Token)", ])! @@ -159,7 +159,7 @@ extension LSStubRequestDSL { } } -class TestApplication: NSObject, SEGApplicationProtocol { +class TestApplication: NSObject, ApplicationProtocol { class BackgroundTask { let identifier: UInt var isEnded = false @@ -171,7 +171,7 @@ class TestApplication: NSObject, SEGApplicationProtocol { var backgroundTasks = [BackgroundTask]() - // MARK: - SEGApplicationProtocol + // MARK: - ApplicationProtocol var delegate: UIApplicationDelegate? = nil func seg_beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)? = nil) -> UInt { let backgroundTask = BackgroundTask(identifier: (backgroundTasks.map({ $0.identifier }).max() ?? 0) + 1)