From 7460935f32748b10f6b3fedf9e77a373a9010d05 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 27 Sep 2018 18:03:53 -0400 Subject: Move parsers to facebook folder (#1109) --- .../pitchedapps/frost/facebook/FbFullImageTest.kt | 32 ---------- .../com/pitchedapps/frost/facebook/FbParseTest.kt | 62 ------------------ .../pitchedapps/frost/facebook/FbRequestTest.kt | 74 ---------------------- .../frost/facebook/parsers/FbParseTest.kt | 61 ++++++++++++++++++ .../frost/facebook/requests/FbFullImageTest.kt | 32 ++++++++++ .../frost/facebook/requests/FbRequestTest.kt | 70 ++++++++++++++++++++ .../com/pitchedapps/frost/internal/Internal.kt | 3 +- 7 files changed, 164 insertions(+), 170 deletions(-) delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/FbFullImageTest.kt delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt create mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/parsers/FbParseTest.kt create mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt create mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbRequestTest.kt (limited to 'app/src/test/kotlin') diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbFullImageTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbFullImageTest.kt deleted file mode 100644 index 98dc7dda..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbFullImageTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.pitchedapps.frost.facebook - -import com.pitchedapps.frost.facebook.requests.getFullSizedImage -import com.pitchedapps.frost.facebook.requests.getFullSizedImageUrl -import com.pitchedapps.frost.internal.COOKIE -import com.pitchedapps.frost.internal.authDependent -import org.junit.BeforeClass -import org.junit.Test -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -/** - * Created by Allan Wang on 12/04/18. - */ -class FbFullImageTest { - - companion object { - @BeforeClass - @JvmStatic - fun before() { - authDependent() - } - } - - @Test - fun getFullImage() { - val url = "https://touch.facebook.com/photo/view_full_size/?fbid=107368839645039" - val result = COOKIE.getFullSizedImageUrl(url).blockingGet() - assertNotNull(result) - println(result) - } -} \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt deleted file mode 100644 index 8c568279..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.pitchedapps.frost.facebook - -import com.pitchedapps.frost.internal.COOKIE -import com.pitchedapps.frost.internal.assertComponentsNotEmpty -import com.pitchedapps.frost.internal.assertDescending -import com.pitchedapps.frost.internal.authDependent -import com.pitchedapps.frost.parsers.* -import org.junit.BeforeClass -import org.junit.Test -import kotlin.test.assertNotNull -import kotlin.test.assertTrue -import kotlin.test.fail - -/** - * Created by Allan Wang on 24/12/17. - */ -class FbParseTest { - - companion object { - @BeforeClass - @JvmStatic - fun before() { - authDependent() - } - } - - private inline fun FrostParser.test(action: T.() -> Unit = {}) = - parse(COOKIE).test(url, action) - - private inline fun ParseResponse?.test(url: String, action: T.() -> Unit = {}) { - val response = this - ?: fail("${T::class.simpleName} parser returned null for $url") - println(response) - response.data.action() - } - - @Test - fun message() = MessageParser.test { - threads.forEach { - it.assertComponentsNotEmpty() - assertTrue(it.id > FALLBACK_TIME_MOD, "id may not be properly matched") - assertNotNull(it.img, "img may not be properly matched") - } - threads.map(FrostThread::time).assertDescending("thread time values") - } - - @Test - fun messageUser() = MessageParser.queryUser(COOKIE, "allan").test("allan query") - - @Test - fun search() = SearchParser.test() - - @Test - fun notif() = NotifParser.test { - notifs.forEach { - it.assertComponentsNotEmpty() - assertTrue(it.id > FALLBACK_TIME_MOD, "id may not be properly matched") - assertNotNull(it.img, "img may not be properly matched") - } - notifs.map(FrostNotif::time).assertDescending("notif time values") - } -} \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt deleted file mode 100644 index 07e02249..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.pitchedapps.frost.facebook - -import com.fasterxml.jackson.databind.ObjectMapper -import com.pitchedapps.frost.facebook.requests.getAuth -import com.pitchedapps.frost.facebook.requests.getFullSizedImage -import com.pitchedapps.frost.facebook.requests.getMenuData -import com.pitchedapps.frost.facebook.requests.markNotificationRead -import com.pitchedapps.frost.internal.AUTH -import com.pitchedapps.frost.internal.COOKIE -import com.pitchedapps.frost.internal.USER_ID -import com.pitchedapps.frost.internal.authDependent -import okhttp3.Call -import org.junit.BeforeClass -import org.junit.Test -import kotlin.test.* - -/** - * Created by Allan Wang on 21/12/17. - */ -class FbRequestTest { - - companion object { - @BeforeClass - @JvmStatic - fun before() { - authDependent() - } - } - - /** - * Used to emulate [executeForNoError] - * Must be consistent with that method - */ - private fun Call.assertNoError() { - val data = execute().body()?.string() ?: fail("Content was null") - println("Call response: $data") - assertTrue(data.isNotEmpty(), "Content was empty") - assertFalse(data.contains("error"), "Content had error") - } - - @Test - fun auth() { - val auth = COOKIE.getAuth() - assertNotNull(auth) - assertEquals(USER_ID, auth.userId) - assertEquals(COOKIE, auth.cookie) - println("Test auth: ${auth.fb_dtsg}") - } - - @Test - fun markNotification() { - val notifId = 1514443903880 - AUTH.markNotificationRead(notifId).call.assertNoError() - } - - @Test - fun fullSizeImage() { - val fbid = 10155966932992838L // google's current cover photo - val url = AUTH.getFullSizedImage(fbid).invoke() - println(url) - assertTrue(url?.startsWith("https://scontent") == true) - } - - @Test - fun testMenu() { - val data = AUTH.getMenuData().invoke() - assertNotNull(data) - println(ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(data!!)) - assertTrue(data.data.isNotEmpty()) - assertTrue(data.footer.hasContent, "Footer may be badly parsed") - val items = data.flatMapValid() - assertTrue(items.size > 15, "Something may be badly parsed") - } -} diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/parsers/FbParseTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/parsers/FbParseTest.kt new file mode 100644 index 00000000..3307c72e --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/parsers/FbParseTest.kt @@ -0,0 +1,61 @@ +package com.pitchedapps.frost.facebook.parsers + +import com.pitchedapps.frost.internal.COOKIE +import com.pitchedapps.frost.internal.assertComponentsNotEmpty +import com.pitchedapps.frost.internal.assertDescending +import com.pitchedapps.frost.internal.authDependent +import org.junit.BeforeClass +import org.junit.Test +import kotlin.test.assertNotNull +import kotlin.test.assertTrue +import kotlin.test.fail + +/** + * Created by Allan Wang on 24/12/17. + */ +class FbParseTest { + + companion object { + @BeforeClass + @JvmStatic + fun before() { + authDependent() + } + } + + private inline fun FrostParser.test(action: T.() -> Unit = {}) = + parse(COOKIE).test(url, action) + + private inline fun ParseResponse?.test(url: String, action: T.() -> Unit = {}) { + val response = this + ?: fail("${T::class.simpleName} parser returned null for $url") + println(response) + response.data.action() + } + + @Test + fun message() = MessageParser.test { + threads.forEach { + it.assertComponentsNotEmpty() + assertTrue(it.id > FALLBACK_TIME_MOD, "id may not be properly matched") + assertNotNull(it.img, "img may not be properly matched") + } + threads.map(FrostThread::time).assertDescending("thread time values") + } + + @Test + fun messageUser() = MessageParser.queryUser(COOKIE, "allan").test("allan query") + + @Test + fun search() = SearchParser.test() + + @Test + fun notif() = NotifParser.test { + notifs.forEach { + it.assertComponentsNotEmpty() + assertTrue(it.id > FALLBACK_TIME_MOD, "id may not be properly matched") + assertNotNull(it.img, "img may not be properly matched") + } + notifs.map(FrostNotif::time).assertDescending("notif time values") + } +} \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt new file mode 100644 index 00000000..291637c6 --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt @@ -0,0 +1,32 @@ +package com.pitchedapps.frost.facebook.requests + +import com.pitchedapps.frost.facebook.requests.getFullSizedImage +import com.pitchedapps.frost.facebook.requests.getFullSizedImageUrl +import com.pitchedapps.frost.internal.COOKIE +import com.pitchedapps.frost.internal.authDependent +import org.junit.BeforeClass +import org.junit.Test +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +/** + * Created by Allan Wang on 12/04/18. + */ +class FbFullImageTest { + + companion object { + @BeforeClass + @JvmStatic + fun before() { + authDependent() + } + } + + @Test + fun getFullImage() { + val url = "https://touch.facebook.com/photo/view_full_size/?fbid=107368839645039" + val result = COOKIE.getFullSizedImageUrl(url).blockingGet() + assertNotNull(result) + println(result) + } +} \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbRequestTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbRequestTest.kt new file mode 100644 index 00000000..9899a018 --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbRequestTest.kt @@ -0,0 +1,70 @@ +package com.pitchedapps.frost.facebook.requests + +import com.fasterxml.jackson.databind.ObjectMapper +import com.pitchedapps.frost.internal.AUTH +import com.pitchedapps.frost.internal.COOKIE +import com.pitchedapps.frost.internal.USER_ID +import com.pitchedapps.frost.internal.authDependent +import okhttp3.Call +import org.junit.BeforeClass +import org.junit.Test +import kotlin.test.* + +/** + * Created by Allan Wang on 21/12/17. + */ +class FbRequestTest { + + companion object { + @BeforeClass + @JvmStatic + fun before() { + authDependent() + } + } + + /** + * Used to emulate [executeForNoError] + * Must be consistent with that method + */ + private fun Call.assertNoError() { + val data = execute().body()?.string() ?: fail("Content was null") + println("Call response: $data") + assertTrue(data.isNotEmpty(), "Content was empty") + assertFalse(data.contains("error"), "Content had error") + } + + @Test + fun auth() { + val auth = COOKIE.getAuth() + assertNotNull(auth) + assertEquals(USER_ID, auth.userId) + assertEquals(COOKIE, auth.cookie) + println("Test auth: ${auth.fb_dtsg}") + } + + @Test + fun markNotification() { + val notifId = 1514443903880 + AUTH.markNotificationRead(notifId).call.assertNoError() + } + + @Test + fun fullSizeImage() { + val fbid = 10155966932992838L // google's current cover photo + val url = AUTH.getFullSizedImage(fbid).invoke() + println(url) + assertEquals(url?.startsWith("https://scontent"), true) + } + + @Test + fun testMenu() { + val data = AUTH.getMenuData().invoke() + assertNotNull(data) + println(ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(data!!)) + assertTrue(data.data.isNotEmpty()) + assertTrue(data.footer.hasContent, "Footer may be badly parsed") + val items = data.flatMapValid() + assertTrue(items.size > 15, "Something may be badly parsed") + } +} diff --git a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt index e3beabd2..81175b19 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt @@ -42,7 +42,7 @@ val COOKIE: String by lazy { PROPS.getProperty("COOKIE") ?: "" } val USER_ID: Long by lazy { FB_USER_MATCHER.find(COOKIE)[1]?.toLong() ?: -1 } val AUTH: RequestAuth by lazy { COOKIE.getAuth().apply { - println("Auth:\nuser:$userId\nfb_dtsg: $fb_dtsg\nrev: $rev\nvalid: $isValid") + println("Auth:\nuser:$userId\nfb_dtsg: $fb_dtsg\nrev: $rev\ncomplete: $isComplete") } } @@ -56,7 +56,6 @@ fun testJsoup(url: String) = frostJsoup(COOKIE, url) fun authDependent() { println("Auth Dependent") Assume.assumeTrue(COOKIE.isNotEmpty() && VALID_COOKIE) - Assume.assumeTrue(AUTH.isValid) } /** -- cgit v1.2.3