From 96226a882dd8b691d65ae544af6513ef4c80c0ad Mon Sep 17 00:00:00 2001 From: Daniel Jacob Chittoor Date: Tue, 30 Jun 2026 14:09:13 +0530 Subject: [PATCH] subscription: Cover testing for import input fallback Import requests queued by older code can omit the explicit mode field. That path must still be decoded as the previous export format while the new channel URL and input stream modes keep their WorkManager payloads stable. The pure data tests cover those round trips and the invalid mode cases without requiring the worker to be started. --- .../workers/SubscriptionImportInputTest.kt | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/src/test/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportInputTest.kt diff --git a/app/src/test/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportInputTest.kt b/app/src/test/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportInputTest.kt new file mode 100644 index 000000000..b61c358c3 --- /dev/null +++ b/app/src/test/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportInputTest.kt @@ -0,0 +1,62 @@ +package org.schabi.newpipe.local.subscription.workers + +import androidx.work.Data +import androidx.work.workDataOf +import org.junit.Assert.assertEquals +import org.junit.Test +import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput.ChannelUrlMode +import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput.InputStreamMode +import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput.PreviousExportMode + +class SubscriptionImportInputTest { + + @Test + fun `Channel URL mode round-trips through Work Data`() { + val input = ChannelUrlMode(serviceId = 0, url = "https://www.youtube.com") + assertEquals(input, SubscriptionImportInput.fromData(input.toData())) + } + + @Test + fun `Input stream mode round-trips through Work Data`() { + val input = InputStreamMode( + serviceId = 0, + url = "content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Fsubscriptions.csv" + ) + assertEquals(input, SubscriptionImportInput.fromData(input.toData())) + } + + @Test + fun `Previous export mode round-trips through Work Data`() { + val input = PreviousExportMode(url = "content://media/external/file/newpipe_subscriptions.json") + assertEquals(input, SubscriptionImportInput.fromData(input.toData())) + } + + @Test + fun `Missing mode falls back to previous export mode`() { + val data = Data.Builder() + .putString("url", "content://media/external/file/newpipe_subscriptions.json") + .build() + + assertEquals( + PreviousExportMode("content://media/external/file/newpipe_subscriptions.json"), + SubscriptionImportInput.fromData(data) + ) + } + + @Test(expected = IllegalArgumentException::class) + fun `Unknown mode throws`() { + SubscriptionImportInput.fromData(workDataOf("mode" to 99, "url" to "https://www.youtube.com")) + } + + @Test(expected = IllegalArgumentException::class) + fun `Channel URL mode without service id throws`() { + SubscriptionImportInput.fromData(workDataOf("mode" to 0, "url" to "https://www.youtube.com")) + } + + @Test(expected = IllegalArgumentException::class) + fun `Input stream mode without service id throws`() { + SubscriptionImportInput.fromData( + workDataOf("mode" to 1, "url" to "content://media/external/file/subscriptions.csv") + ) + } +}