@@ -466,9 +466,27 @@ class PubkyRepoTest : BaseUnitTest() {
466466 }
467467
468468 @Test
469- fun `fetchContactProfile should return profile on success` () = test {
470- val contactKey = " pubky://contact3"
469+ fun `fetchContactProfile should return bitkit profile when available` () = test {
470+ val contactKey = " pubkycontact3"
471+ val strippedKey = contactKey.removePrefix(" pubky" )
472+ val json = """ {"name":"Bob","bio":"Bio"}"""
473+ whenever(pubkyService.fetchFileString(" pubky://$strippedKey${Env .profilePath} " ))
474+ .thenReturn(json)
475+
476+ val result = sut.fetchContactProfile(contactKey)
477+
478+ assertTrue(result.isSuccess)
479+ assertEquals(" Bob" , result.getOrNull()?.name)
480+ verify(pubkyService, never()).getProfile(contactKey)
481+ }
482+
483+ @Test
484+ fun `fetchContactProfile should fall back to pubky profile when bitkit profile is missing` () = test {
485+ val contactKey = " pubkycontact3"
486+ val strippedKey = contactKey.removePrefix(" pubky" )
471487 val contactProfile = mock<CorePubkyProfile >()
488+ whenever(pubkyService.fetchFileString(" pubky://$strippedKey${Env .profilePath} " ))
489+ .thenThrow(RuntimeException (" Missing bitkit profile" ))
472490 whenever(contactProfile.name).thenReturn(" Bob" )
473491 whenever(contactProfile.bio).thenReturn(" Bio" )
474492 whenever(pubkyService.getProfile(contactKey)).thenReturn(contactProfile)
@@ -480,13 +498,17 @@ class PubkyRepoTest : BaseUnitTest() {
480498 }
481499
482500 @Test
483- fun `fetchContactProfile should return failure on error` () = test {
484- val contactKey = " pubky://failing"
485- whenever(pubkyService.getProfile(contactKey)).thenThrow(RuntimeException (" Failed" ))
501+ fun `fetchContactProfile should fall back to placeholder when remote lookup fails` () = test {
502+ val contactKey = " pubkycontact3"
503+ val strippedKey = contactKey.removePrefix(" pubky" )
504+ whenever(pubkyService.fetchFileString(" pubky://$strippedKey${Env .profilePath} " ))
505+ .thenThrow(RuntimeException (" Missing bitkit profile" ))
506+ whenever(pubkyService.getProfile(contactKey)).thenThrow(RuntimeException (" Missing pubky profile" ))
486507
487508 val result = sut.fetchContactProfile(contactKey)
488509
489- assertTrue(result.isFailure)
510+ assertTrue(result.isSuccess)
511+ assertEquals(PubkyProfile .placeholder(contactKey), result.getOrNull())
490512 }
491513
492514 @Test
0 commit comments