aboutsummaryrefslogtreecommitdiff
path: root/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt')
-rw-r--r--app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt53
1 files changed, 50 insertions, 3 deletions
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 91eb968d..deaed333 100644
--- a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt
+++ b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt
@@ -1,9 +1,15 @@
package com.pitchedapps.frost.internal
-import com.pitchedapps.frost.facebook.FB_USER_MATCHER
+import com.pitchedapps.frost.facebook.*
+import com.pitchedapps.frost.utils.frostJsoup
+import org.junit.Assume
import java.io.File
import java.io.FileInputStream
import java.util.*
+import kotlin.reflect.full.starProjectedType
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+import kotlin.test.fail
/**
* Created by Allan Wang on 21/12/17.
@@ -24,5 +30,46 @@ val PROPS: Properties by lazy {
}
val COOKIE: String by lazy { PROPS.getProperty("COOKIE") ?: "" }
-val FB_DTSG: String by lazy { PROPS.getProperty("FB_DTSG") ?: "" }
-val USER_ID: Long by lazy { FB_USER_MATCHER.find(COOKIE)?.groupValues?.get(1)?.toLong() ?: -1 }
+val USER_ID: Long by lazy { FB_USER_MATCHER.find(COOKIE)[1]?.toLong() ?: -1 }
+val AUTH: RequestAuth by lazy {
+ (USER_ID to COOKIE).getAuth().apply {
+ println("Auth:\nuser:$userId\nfb_dtsg: $fb_dtsg\nrev: $rev\nvalid: $isValid")
+ }
+}
+
+val VALID_COOKIE: Boolean by lazy {
+ val data = testJsoup(FbItem.SETTINGS.url)
+ data.title() == "Settings"
+}
+
+fun testJsoup(url: String) = frostJsoup(COOKIE, url)
+
+fun authDependent() {
+ println("Auth Dependent")
+ Assume.assumeTrue(COOKIE.isNotEmpty() && VALID_COOKIE)
+ Assume.assumeTrue(AUTH.isValid)
+}
+
+/**
+ * Check that component strings are nonempty and are properly parsed
+ * To be used for data classes
+ */
+fun Any.assertComponentsNotEmpty() {
+ val components = this::class.members.filter { it.name.startsWith("component") }
+ if (components.isEmpty())
+ fail("${this::class.simpleName} has no components")
+ components.forEach {
+ when (it.returnType) {
+ String::class.starProjectedType -> {
+ val result = it.call(this) as String
+ assertTrue(result.isNotEmpty(), "${it.name} returned empty string")
+ if (result.startsWith("https"))
+ assertTrue(result.startsWith("https://"), "${it.name} has poorly formatted output $result")
+ }
+ }
+ }
+}
+
+fun <T : Comparable<T>> List<T>.assertDescending(tag: String) {
+ assertEquals(sortedDescending(), this, "$tag not sorted in descending order")
+} \ No newline at end of file