@@ -535,6 +535,82 @@ final class AmplitudeTests: XCTestCase {
535535 }
536536 #endif
537537
538+ func testRemnantDataNotMigratedInNonSandboxedApps( ) throws {
539+ let instanceName = " legacy_v3_ \( UUID ( ) . uuidString) " . lowercased ( )
540+ let bundle = Bundle ( for: type ( of: self ) )
541+ let legacyDbUrl = bundle. url ( forResource: " legacy_v3 " , withExtension: " sqlite " )
542+ let dbUrl = LegacyDatabaseStorage . getDatabasePath ( instanceName)
543+ let fileManager = FileManager . default
544+ let legacyDbExists = legacyDbUrl != nil ? fileManager. fileExists ( atPath: legacyDbUrl!. path) : false
545+ XCTAssertTrue ( legacyDbExists)
546+
547+ try fileManager. copyItem ( at: legacyDbUrl!, to: dbUrl)
548+
549+ addTeardownBlock {
550+ let fileManager = FileManager . default
551+ if fileManager. fileExists ( atPath: dbUrl. path) {
552+ try fileManager. removeItem ( at: dbUrl)
553+ }
554+ }
555+
556+ let apiKey = " test-api-key "
557+ let configuration = Configuration (
558+ apiKey: apiKey,
559+ instanceName: instanceName,
560+ migrateLegacyData: true
561+ )
562+ let amplitude = Amplitude ( configuration: configuration)
563+
564+ let deviceId = " 9B574574-74A7-4EDF-969D-164CB151B6C3 "
565+ let userId = " ios-sample-user-legacy "
566+
567+ #if os(macOS)
568+ // We don't want to transfer remnant data in non-sanboxed apps
569+ XCTAssertFalse ( amplitude. isSandboxEnabled ( ) )
570+ XCTAssertNotEqual ( amplitude. getDeviceId ( ) , deviceId)
571+ XCTAssertNotEqual ( amplitude. getUserId ( ) , userId)
572+ #else
573+ XCTAssertEqual ( amplitude. getDeviceId ( ) , deviceId)
574+ XCTAssertEqual ( amplitude. getUserId ( ) , userId)
575+ #endif
576+ }
577+
578+ #if os(macOS)
579+ func testRemnantDataNotMigratedInSandboxedMacApps( ) throws {
580+ let instanceName = " legacy_v3_ \( UUID ( ) . uuidString) " . lowercased ( )
581+ let bundle = Bundle ( for: type ( of: self ) )
582+ let legacyDbUrl = bundle. url ( forResource: " legacy_v3 " , withExtension: " sqlite " )
583+ let dbUrl = LegacyDatabaseStorage . getDatabasePath ( instanceName)
584+ let fileManager = FileManager . default
585+ let legacyDbExists = legacyDbUrl != nil ? fileManager. fileExists ( atPath: legacyDbUrl!. path) : false
586+ XCTAssertTrue ( legacyDbExists)
587+
588+ try fileManager. copyItem ( at: legacyDbUrl!, to: dbUrl)
589+
590+ addTeardownBlock {
591+ let fileManager = FileManager . default
592+ if fileManager. fileExists ( atPath: dbUrl. path) {
593+ try fileManager. removeItem ( at: dbUrl)
594+ }
595+ }
596+
597+ let apiKey = " test-api-key "
598+ let configuration = Configuration (
599+ apiKey: apiKey,
600+ instanceName: instanceName,
601+ migrateLegacyData: true
602+ )
603+ let amplitude = FakeAmplitudeWithSandboxEnabled ( configuration: configuration)
604+
605+ let deviceId = " 9B574574-74A7-4EDF-969D-164CB151B6C3 "
606+ let userId = " ios-sample-user-legacy "
607+
608+ XCTAssertTrue ( amplitude. isSandboxEnabled ( ) )
609+ XCTAssertEqual ( amplitude. getDeviceId ( ) , deviceId)
610+ XCTAssertEqual ( amplitude. getUserId ( ) , userId)
611+ }
612+ #endif
613+
538614 func testInit_Offline( ) {
539615 XCTAssertEqual ( Amplitude ( configuration: configuration) . configuration. offline, false )
540616 }
0 commit comments