@@ -84,6 +84,7 @@ import com.duckduckgo.sync.store.ScopedPassword
8484import com.duckduckgo.sync.store.SyncStore
8585import com.squareup.moshi.Moshi
8686import kotlinx.coroutines.test.TestScope
87+ import kotlinx.coroutines.test.runTest
8788import org.junit.Assert.assertEquals
8889import org.junit.Assert.assertFalse
8990import org.junit.Assert.assertNull
@@ -1247,7 +1248,7 @@ class AppSyncAccountRepositoryTest {
12471248 // Per-manager logic is covered in ThirdPartyCredentialManagerTest and ProtectedKeyManagerTest.
12481249
12491250 @Test
1250- fun whenCreateThirdPartyCredentialThenDelegatesToManager () {
1251+ fun whenCreateThirdPartyCredentialThenDelegatesToManager () = runTest {
12511252 whenever(thirdPartyCredentialManager.create()).thenReturn(Success (true ))
12521253
12531254 val result = syncRepo.createThirdPartyCredential()
@@ -1307,7 +1308,7 @@ class AppSyncAccountRepositoryTest {
13071308 // joinAccountFromThirdPartyRecoveryCode
13081309
13091310 @Test
1310- fun whenJoinAccountFromThirdPartyAndAllStepsSucceedThenAtomicStoreUsesDdgTokenFromSecondLogin () {
1311+ fun whenJoinAccountFromThirdPartyAndAllStepsSucceedThenAtomicStoreUsesDdgTokenFromSecondLogin () = runTest {
13111312 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
13121313
13131314 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1325,7 +1326,7 @@ class AppSyncAccountRepositoryTest {
13251326 }
13261327
13271328 @Test
1328- fun whenJoinAccountFromThirdPartySucceedsThenScopedPasswordIsWrittenFromLocalRecoveryCode () {
1329+ fun whenJoinAccountFromThirdPartySucceedsThenScopedPasswordIsWrittenFromLocalRecoveryCode () = runTest {
13291330 // Defensive: even if the BE response omits encrypted_3party_credential (so performLogin's
13301331 // server-decoded SP path is a no-op), the join should still leave scopedPassword populated
13311332 // from the locally-parsed recovery code.
@@ -1339,7 +1340,7 @@ class AppSyncAccountRepositoryTest {
13391340 }
13401341
13411342 @Test
1342- fun whenJoinAccountFromThirdPartyThenStep7aPostUpgradeLoginUsesUnrestrictedScope () {
1343+ fun whenJoinAccountFromThirdPartyThenStep7aPostUpgradeLoginUsesUnrestrictedScope () = runTest {
13431344 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
13441345
13451346 syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1364,7 +1365,7 @@ class AppSyncAccountRepositoryTest {
13641365 }
13651366
13661367 @Test
1367- fun whenStep7aPostUpgradeLoginReturns401ThenAbortsWithoutAtomicStore () {
1368+ fun whenStep7aPostUpgradeLoginReturns401ThenAbortsWithoutAtomicStore () = runTest {
13681369 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(step7aResult = step7aLoginUnauthorized)
13691370
13701371 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1375,7 +1376,7 @@ class AppSyncAccountRepositoryTest {
13751376 }
13761377
13771378 @Test
1378- fun whenStep7aPostUpgradeLoginFailsWithNon401ThenAbortsWithoutAtomicStore () {
1379+ fun whenStep7aPostUpgradeLoginFailsWithNon401ThenAbortsWithoutAtomicStore () = runTest {
13791380 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(step7aResult = step7aLoginServerError)
13801381
13811382 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1389,7 +1390,7 @@ class AppSyncAccountRepositoryTest {
13891390 }
13901391
13911392 @Test
1392- fun whenJoinAccountFromThirdPartyAndAccountAlreadyHasDdgCredentialThenAbortsBeforePost () {
1393+ fun whenJoinAccountFromThirdPartyAndAccountAlreadyHasDdgCredentialThenAbortsBeforePost () = runTest {
13931394 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(accountAlreadyHasDdg = true )
13941395
13951396 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1402,7 +1403,7 @@ class AppSyncAccountRepositoryTest {
14021403 }
14031404
14041405 @Test
1405- fun whenStep7PostRateLimitedThenRetriesAndSucceeds () {
1406+ fun whenStep7PostRateLimitedThenRetriesAndSucceeds () = runTest {
14061407 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
14071408 whenever(syncApi.createAccessCredential(anyString(), eq(" ddg" ), any()))
14081409 .thenReturn(Error (code = API_CODE .TOO_MANY_REQUESTS_2 .code, reason = " rate limited" ), Success (true ))
@@ -1414,7 +1415,7 @@ class AppSyncAccountRepositoryTest {
14141415 }
14151416
14161417 @Test
1417- fun whenStep7aLoginServerErrorThenRetriesAndSucceeds () {
1418+ fun whenStep7aLoginServerErrorThenRetriesAndSucceeds () = runTest {
14181419 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
14191420 whenever(syncApi.login(eq(userId), any(), eq(deviceId), any(), any(), eq<String ?>(null )))
14201421 .thenReturn(step7aLoginServerError, step7aLoginSuccess)
@@ -1434,7 +1435,7 @@ class AppSyncAccountRepositoryTest {
14341435 }
14351436
14361437 @Test
1437- fun whenStep7aLoginTransportErrorThenRetriesAndSucceeds () {
1438+ fun whenStep7aLoginTransportErrorThenRetriesAndSucceeds () = runTest {
14381439 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
14391440 whenever(syncApi.login(eq(userId), any(), eq(deviceId), any(), any(), eq<String ?>(null )))
14401441 .thenReturn(step7aLoginTransportError, step7aLoginSuccess)
@@ -1446,7 +1447,7 @@ class AppSyncAccountRepositoryTest {
14461447 }
14471448
14481449 @Test
1449- fun whenStep7aLogin401ThenAbortsWithoutRetry () {
1450+ fun whenStep7aLogin401ThenAbortsWithoutRetry () = runTest {
14501451 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(step7aResult = step7aLoginUnauthorized)
14511452
14521453 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1457,7 +1458,7 @@ class AppSyncAccountRepositoryTest {
14571458 }
14581459
14591460 @Test
1460- fun whenStep7Post409AlreadyExistsThenAbortsWithoutRetry () {
1461+ fun whenStep7Post409AlreadyExistsThenAbortsWithoutRetry () = runTest {
14611462 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
14621463 whenever(syncApi.createAccessCredential(anyString(), eq(" ddg" ), any()))
14631464 .thenReturn(Error (code = API_CODE .COUNT_LIMIT .code, reason = " already exists" ))
@@ -1470,7 +1471,7 @@ class AppSyncAccountRepositoryTest {
14701471 }
14711472
14721473 @Test
1473- fun whenStep7PostRateLimitedBeyondRetryLimitThenAbortsWithoutStore () {
1474+ fun whenStep7PostRateLimitedBeyondRetryLimitThenAbortsWithoutStore () = runTest {
14741475 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode()
14751476 whenever(syncApi.createAccessCredential(anyString(), eq(" ddg" ), any()))
14761477 .thenReturn(Error (code = API_CODE .TOO_MANY_REQUESTS_1 .code, reason = " rate limited" ))
@@ -1484,7 +1485,7 @@ class AppSyncAccountRepositoryTest {
14841485 }
14851486
14861487 @Test
1487- fun whenJoinAccountFromThirdPartyAndCodeIsLaterMinorVersionThenAccepted () {
1488+ fun whenJoinAccountFromThirdPartyAndCodeIsLaterMinorVersionThenAccepted () = runTest {
14881489 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(version = " 2.5" )
14891490
14901491 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1493,7 +1494,7 @@ class AppSyncAccountRepositoryTest {
14931494 }
14941495
14951496 @Test
1496- fun whenJoinAccountFromThirdPartyAndCodeIsBareMajorVersionThenAccepted () {
1497+ fun whenJoinAccountFromThirdPartyAndCodeIsBareMajorVersionThenAccepted () = runTest {
14971498 // "2" is the spec's common shorthand for "2.0" (Transport TD 1214486492252757).
14981499 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(version = " 2" )
14991500
@@ -1503,7 +1504,7 @@ class AppSyncAccountRepositoryTest {
15031504 }
15041505
15051506 @Test
1506- fun whenJoinAccountFromThirdPartyAndCodeIsMajorVersion3ThenRejectedWithoutNetwork () {
1507+ fun whenJoinAccountFromThirdPartyAndCodeIsMajorVersion3ThenRejectedWithoutNetwork () = runTest {
15071508 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(version = " 3.0" )
15081509
15091510 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
@@ -1513,7 +1514,7 @@ class AppSyncAccountRepositoryTest {
15131514 }
15141515
15151516 @Test
1516- fun whenJoinAccountFromThirdPartyAndCodeCidIsNotThirdPartyThenRejectedWithoutNetwork () {
1517+ fun whenJoinAccountFromThirdPartyAndCodeCidIsNotThirdPartyThenRejectedWithoutNetwork () = runTest {
15171518 val pastedCode = prepareForJoinAccountFromThirdPartyRecoveryCode(cid = " ddg" )
15181519
15191520 val result = syncRepo.joinAccountFromThirdPartyRecoveryCode(pastedCode)
0 commit comments