Loading app/src/main/java/foundation/e/apps/data/install/core/InstallationEnqueuer.kt +8 −5 Original line number Diff line number Diff line Loading @@ -91,11 +91,14 @@ class InstallationEnqueuer @Inject constructor( isSystemApp: Boolean ): Boolean { val user = sessionRepository.awaitUser() if (!isSystemApp && (user == User.GOOGLE || user == User.ANONYMOUS)) { return when { isSystemApp -> false user == User.ANONYMOUS -> { val authData = playStoreAuthStore.awaitAuthData() return !appInstall.isFree && authData?.isAnonymous == true } else { return false !appInstall.isFree && authData?.isAnonymous == true } else -> false } } Loading app/src/test/java/foundation/e/apps/installProcessor/InstallationEnqueuerTest.kt +63 −0 Original line number Diff line number Diff line Loading @@ -308,6 +308,69 @@ class InstallationEnqueuerTest { coVerify(exactly = 0) { playStoreAuthStore.awaitAuthData() } } @Test fun enqueue_allowsPaidAppForGoogleUser() = runTest { val appInstall = createNativeInstall(isFree = false) coEvery { sessionRepository.awaitUser() } returns User.GOOGLE coEvery { appManagerWrapper.addDownload(appInstall) } returns true coEvery { ageLimiter.allow(appInstall) } returns true every { networkStatusChecker.isNetworkAvailable() } returns true every { storageSpaceChecker.spaceMissing(appInstall) } returns 0L val result = enqueuer.enqueue(appInstall) assertTrue(result) assertTrue(appEventDispatcher.events.none { it is AppEvent.ErrorMessageEvent && it.data == R.string.paid_app_anonymous_message }) coVerify { appManagerWrapper.updateAwaiting(appInstall) } coVerify(exactly = 0) { playStoreAuthStore.awaitAuthData() } } @Test fun enqueue_allowsFreeAppForAnonymousUser() = runTest { val appInstall = createNativeInstall() coEvery { sessionRepository.awaitUser() } returns User.ANONYMOUS coEvery { playStoreAuthStore.awaitAuthData() } returns AuthData(email = "anon@example.com", isAnonymous = true) coEvery { appManagerWrapper.addDownload(appInstall) } returns true coEvery { ageLimiter.allow(appInstall) } returns true every { networkStatusChecker.isNetworkAvailable() } returns true every { storageSpaceChecker.spaceMissing(appInstall) } returns 0L val result = enqueuer.enqueue(appInstall) assertTrue(result) assertTrue(appEventDispatcher.events.none { it is AppEvent.ErrorMessageEvent && it.data == R.string.paid_app_anonymous_message }) coVerify { appManagerWrapper.updateAwaiting(appInstall) } coVerify { playStoreAuthStore.awaitAuthData() } } @Test fun enqueue_doesNotLookupAuthForNoGoogleUser() = runTest { val appInstall = createNativeInstall() coEvery { sessionRepository.awaitUser() } returns User.NO_GOOGLE coEvery { appManagerWrapper.addDownload(appInstall) } returns true coEvery { ageLimiter.allow(appInstall) } returns true every { networkStatusChecker.isNetworkAvailable() } returns true every { storageSpaceChecker.spaceMissing(appInstall) } returns 0L val result = enqueuer.enqueue(appInstall) assertTrue(result) assertTrue(appEventDispatcher.events.none { it is AppEvent.ErrorMessageEvent && it.data == R.string.paid_app_anonymous_message }) coVerify { appManagerWrapper.updateAwaiting(appInstall) } coVerify(exactly = 0) { playStoreAuthStore.awaitAuthData() } } @Test fun canEnqueue_handlesFreeAppNotPurchasedAsRestricted() = runTest { val appInstall = createNativeInstall(isFree = true) Loading Loading
app/src/main/java/foundation/e/apps/data/install/core/InstallationEnqueuer.kt +8 −5 Original line number Diff line number Diff line Loading @@ -91,11 +91,14 @@ class InstallationEnqueuer @Inject constructor( isSystemApp: Boolean ): Boolean { val user = sessionRepository.awaitUser() if (!isSystemApp && (user == User.GOOGLE || user == User.ANONYMOUS)) { return when { isSystemApp -> false user == User.ANONYMOUS -> { val authData = playStoreAuthStore.awaitAuthData() return !appInstall.isFree && authData?.isAnonymous == true } else { return false !appInstall.isFree && authData?.isAnonymous == true } else -> false } } Loading
app/src/test/java/foundation/e/apps/installProcessor/InstallationEnqueuerTest.kt +63 −0 Original line number Diff line number Diff line Loading @@ -308,6 +308,69 @@ class InstallationEnqueuerTest { coVerify(exactly = 0) { playStoreAuthStore.awaitAuthData() } } @Test fun enqueue_allowsPaidAppForGoogleUser() = runTest { val appInstall = createNativeInstall(isFree = false) coEvery { sessionRepository.awaitUser() } returns User.GOOGLE coEvery { appManagerWrapper.addDownload(appInstall) } returns true coEvery { ageLimiter.allow(appInstall) } returns true every { networkStatusChecker.isNetworkAvailable() } returns true every { storageSpaceChecker.spaceMissing(appInstall) } returns 0L val result = enqueuer.enqueue(appInstall) assertTrue(result) assertTrue(appEventDispatcher.events.none { it is AppEvent.ErrorMessageEvent && it.data == R.string.paid_app_anonymous_message }) coVerify { appManagerWrapper.updateAwaiting(appInstall) } coVerify(exactly = 0) { playStoreAuthStore.awaitAuthData() } } @Test fun enqueue_allowsFreeAppForAnonymousUser() = runTest { val appInstall = createNativeInstall() coEvery { sessionRepository.awaitUser() } returns User.ANONYMOUS coEvery { playStoreAuthStore.awaitAuthData() } returns AuthData(email = "anon@example.com", isAnonymous = true) coEvery { appManagerWrapper.addDownload(appInstall) } returns true coEvery { ageLimiter.allow(appInstall) } returns true every { networkStatusChecker.isNetworkAvailable() } returns true every { storageSpaceChecker.spaceMissing(appInstall) } returns 0L val result = enqueuer.enqueue(appInstall) assertTrue(result) assertTrue(appEventDispatcher.events.none { it is AppEvent.ErrorMessageEvent && it.data == R.string.paid_app_anonymous_message }) coVerify { appManagerWrapper.updateAwaiting(appInstall) } coVerify { playStoreAuthStore.awaitAuthData() } } @Test fun enqueue_doesNotLookupAuthForNoGoogleUser() = runTest { val appInstall = createNativeInstall() coEvery { sessionRepository.awaitUser() } returns User.NO_GOOGLE coEvery { appManagerWrapper.addDownload(appInstall) } returns true coEvery { ageLimiter.allow(appInstall) } returns true every { networkStatusChecker.isNetworkAvailable() } returns true every { storageSpaceChecker.spaceMissing(appInstall) } returns 0L val result = enqueuer.enqueue(appInstall) assertTrue(result) assertTrue(appEventDispatcher.events.none { it is AppEvent.ErrorMessageEvent && it.data == R.string.paid_app_anonymous_message }) coVerify { appManagerWrapper.updateAwaiting(appInstall) } coVerify(exactly = 0) { playStoreAuthStore.awaitAuthData() } } @Test fun canEnqueue_handlesFreeAppNotPurchasedAsRestricted() = runTest { val appInstall = createNativeInstall(isFree = true) Loading