Skip to content

Commit c1b8120

Browse files
committed
fix: load contacts after auth
1 parent 2da3269 commit c1b8120

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

app/src/main/java/to/bitkit/repositories/PubkyRepo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class PubkyRepo @Inject constructor(
262262
_authState.update { PubkyAuthState.Authenticated }
263263
Logger.info("Completed pubky auth for '$pk'", context = TAG)
264264
loadProfile()
265+
loadContacts()
265266
}.map { }
266267
}
267268

app/src/test/java/to/bitkit/repositories/PubkyRepoTest.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class PubkyRepoTest : BaseUnitTest() {
105105
val ffiProfile = mock<CorePubkyProfile>()
106106
whenever(ffiProfile.name).thenReturn("User")
107107
whenever(pubkyService.getProfile(VALID_SELF_KEY)).thenReturn(ffiProfile)
108+
whenever(keychain.loadString(Keychain.Key.PAYKIT_SESSION.name)).thenReturn(testSecret)
109+
whenever(pubkyService.sessionList(testSecret, Env.contactsBasePath)).thenReturn(emptyList())
108110

109111
val result = sut.completeAuthentication()
110112

@@ -122,6 +124,8 @@ class PubkyRepoTest : BaseUnitTest() {
122124
whenever(pubkyService.importSession(testSecret)).thenReturn(testPk)
123125
val ffiProfile = createFfiProfile(name = "User")
124126
whenever(pubkyService.getProfile(VALID_SELF_KEY)).thenReturn(ffiProfile)
127+
whenever(keychain.loadString(Keychain.Key.PAYKIT_SESSION.name)).thenReturn(testSecret)
128+
whenever(pubkyService.sessionList(testSecret, Env.contactsBasePath)).thenReturn(emptyList())
125129

126130
val result = sut.completeAuthentication()
127131

@@ -130,18 +134,20 @@ class PubkyRepoTest : BaseUnitTest() {
130134
}
131135

132136
@Test
133-
fun `completeAuthentication should not load contacts automatically`() = test {
137+
fun `completeAuthentication should load contacts automatically`() = test {
134138
val testSecret = "session_secret"
135139
val testPk = VALID_SELF_KEY.removePrefix("pubky")
136140
whenever(pubkyService.completeAuth()).thenReturn(testSecret)
137141
whenever(pubkyService.importSession(testSecret)).thenReturn(testPk)
138142
val ffiProfile = createFfiProfile(name = "User")
139143
whenever(pubkyService.getProfile(VALID_SELF_KEY)).thenReturn(ffiProfile)
144+
whenever(keychain.loadString(Keychain.Key.PAYKIT_SESSION.name)).thenReturn(testSecret)
145+
whenever(pubkyService.sessionList(testSecret, Env.contactsBasePath)).thenReturn(emptyList())
140146

141147
val result = sut.completeAuthentication()
142148

143149
assertTrue(result.isSuccess)
144-
verify(pubkyService, never()).sessionList(any(), any())
150+
verify(pubkyService).sessionList(testSecret, Env.contactsBasePath)
145151
}
146152

147153
@Test

0 commit comments

Comments
 (0)