@@ -11,9 +11,11 @@ import Nimble
11
11
import Quick
12
12
13
13
class PostHogStorageManagerTest : QuickSpec {
14
- func getSut( ) -> PostHogStorageManager {
15
- let config = PostHogConfig ( apiKey: " 123 " )
16
- return PostHogStorageManager ( config)
14
+ func getSut( _ config: PostHogConfig ? = nil ) -> PostHogStorageManager {
15
+ let theConfig = config ?? PostHogConfig ( apiKey: " 123 " )
16
+ let storage = PostHogStorage ( theConfig)
17
+ storage. reset ( )
18
+ return PostHogStorageManager ( theConfig)
17
19
}
18
20
19
21
override func spec( ) {
@@ -46,15 +48,29 @@ class PostHogStorageManagerTest: QuickSpec {
46
48
sut. reset ( true )
47
49
}
48
50
49
- it ( " Can can accept id customization via config " ) {
51
+ it ( " Can accept anon id customization via config " ) {
50
52
let config = PostHogConfig ( apiKey: " 123 " )
51
53
let fixedUuid = UUID . v7 ( )
52
54
config. getAnonymousId = { _ in fixedUuid }
53
- let sut = PostHogStorageManager ( config)
55
+ let sut = self . getSut ( config)
54
56
let anonymousId = sut. getAnonymousId ( )
55
57
expect ( anonymousId) == fixedUuid. uuidString
56
58
57
59
sut. reset ( true )
58
60
}
61
+
62
+ it ( " Uses the correct fallback value for isIdentified " ) {
63
+ let anonymousIdToSet = UUID . v7 ( )
64
+ let distinctIdToSet = UUID . v7 ( ) . uuidString
65
+
66
+ let config = PostHogConfig ( apiKey: " 123 " )
67
+ config. getAnonymousId = { _ in anonymousIdToSet }
68
+
69
+ let sut = self . getSut ( config)
70
+ sut. setDistinctId ( distinctIdToSet)
71
+
72
+ // Don't call setIdentified(true), isIdentified should be derived from different anon and distinct ids
73
+ expect ( sut. isIdentified ( ) ) == true
74
+ }
59
75
}
60
76
}
0 commit comments