mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 02:07:01 +05:30
all: reformat with ktfmt google style
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
8448910628
commit
db07a12be5
54 changed files with 496 additions and 656 deletions
|
@ -4,16 +4,12 @@ import dev.msfjarvis.lobsters.model.LobstersPost
|
|||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
/**
|
||||
* Simple interface defining an API for lobste.rs
|
||||
*/
|
||||
/** Simple interface defining an API for lobste.rs */
|
||||
interface LobstersApi {
|
||||
|
||||
@GET("hottest.json")
|
||||
suspend fun getHottestPosts(@Query("page") page: Int): List<LobstersPost>
|
||||
@GET("hottest.json") suspend fun getHottestPosts(@Query("page") page: Int): List<LobstersPost>
|
||||
|
||||
@GET("newest.json")
|
||||
suspend fun getNewestPosts(@Query("page") page: Int): List<LobstersPost>
|
||||
@GET("newest.json") suspend fun getNewestPosts(@Query("page") page: Int): List<LobstersPost>
|
||||
|
||||
companion object {
|
||||
const val BASE_URL = "https://lobste.rs"
|
||||
|
|
|
@ -5,8 +5,6 @@ import com.squareup.moshi.JsonClass
|
|||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class KeybaseSignature(
|
||||
@Json(name = "kb_username")
|
||||
val kbUsername: String,
|
||||
@Json(name = "sig_hash")
|
||||
val sigHash: String,
|
||||
@Json(name = "kb_username") val kbUsername: String,
|
||||
@Json(name = "sig_hash") val sigHash: String,
|
||||
)
|
||||
|
|
|
@ -5,22 +5,16 @@ import com.squareup.moshi.JsonClass
|
|||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class LobstersPost(
|
||||
@Json(name = "short_id")
|
||||
val shortId: String,
|
||||
@Json(name = "short_id_url")
|
||||
val shortIdUrl: String,
|
||||
@Json(name = "created_at")
|
||||
val createdAt: String,
|
||||
@Json(name = "short_id") val shortId: String,
|
||||
@Json(name = "short_id_url") val shortIdUrl: String,
|
||||
@Json(name = "created_at") val createdAt: String,
|
||||
val title: String,
|
||||
val url: String,
|
||||
val score: Long,
|
||||
val flags: Long,
|
||||
@Json(name = "comment_count")
|
||||
val commentCount: Long,
|
||||
@Json(name = "comment_count") val commentCount: Long,
|
||||
val description: String,
|
||||
@Json(name = "comments_url")
|
||||
val commentsUrl: String,
|
||||
@Json(name = "submitter_user")
|
||||
val submitterUser: Submitter,
|
||||
@Json(name = "comments_url") val commentsUrl: String,
|
||||
@Json(name = "submitter_user") val submitterUser: Submitter,
|
||||
val tags: List<String>,
|
||||
)
|
||||
|
|
|
@ -6,22 +6,14 @@ import com.squareup.moshi.JsonClass
|
|||
@JsonClass(generateAdapter = true)
|
||||
class Submitter(
|
||||
val username: String,
|
||||
@Json(name = "created_at")
|
||||
val createdAt: String,
|
||||
@Json(name = "is_admin")
|
||||
val isAdmin: Boolean,
|
||||
@Json(name = "created_at") val createdAt: String,
|
||||
@Json(name = "is_admin") val isAdmin: Boolean,
|
||||
val about: String,
|
||||
@Json(name = "is_moderator")
|
||||
val isModerator: Boolean,
|
||||
@Json(name = "is_moderator") val isModerator: Boolean,
|
||||
val karma: Long = 0,
|
||||
@Json(name = "avatar_url")
|
||||
val avatarUrl: String,
|
||||
@Json(name = "invited_by_user")
|
||||
val invitedByUser: String,
|
||||
@Json(name = "github_username")
|
||||
val githubUsername: String? = null,
|
||||
@Json(name = "twitter_username")
|
||||
val twitterUsername: String? = null,
|
||||
@Json(name = "keybase_signatures")
|
||||
val keybaseSignatures: List<KeybaseSignature> = emptyList(),
|
||||
@Json(name = "avatar_url") val avatarUrl: String,
|
||||
@Json(name = "invited_by_user") val invitedByUser: String,
|
||||
@Json(name = "github_username") val githubUsername: String? = null,
|
||||
@Json(name = "twitter_username") val twitterUsername: String? = null,
|
||||
@Json(name = "keybase_signatures") val keybaseSignatures: List<KeybaseSignature> = emptyList(),
|
||||
)
|
||||
|
|
|
@ -22,26 +22,26 @@ class LobstersApiTest {
|
|||
companion object {
|
||||
private val webServer = MockWebServer()
|
||||
private val apiData = TestUtils.getJson("hottest.json")
|
||||
private val moshi = Moshi.Builder()
|
||||
.build()
|
||||
private val okHttp = OkHttpClient.Builder()
|
||||
.build()
|
||||
private val retrofit = Retrofit.Builder()
|
||||
.client(okHttp)
|
||||
.baseUrl("http://localhost:8080/")
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
.build()
|
||||
private val moshi = Moshi.Builder().build()
|
||||
private val okHttp = OkHttpClient.Builder().build()
|
||||
private val retrofit =
|
||||
Retrofit.Builder()
|
||||
.client(okHttp)
|
||||
.baseUrl("http://localhost:8080/")
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
.build()
|
||||
private val apiClient = retrofit.create<LobstersApi>()
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUp() {
|
||||
webServer.start(8080)
|
||||
webServer.dispatcher = object : Dispatcher() {
|
||||
override fun dispatch(request: RecordedRequest): MockResponse {
|
||||
return MockResponse().setBody(apiData).setResponseCode(200)
|
||||
webServer.dispatcher =
|
||||
object : Dispatcher() {
|
||||
override fun dispatch(request: RecordedRequest): MockResponse {
|
||||
return MockResponse().setBody(apiData).setResponseCode(200)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
@ -60,18 +60,14 @@ class LobstersApiTest {
|
|||
@Test
|
||||
fun `no moderator posts in test data`() = runBlocking {
|
||||
val posts = apiClient.getHottestPosts(1)
|
||||
val moderatorPosts = posts.asSequence()
|
||||
.filter { it.submitterUser.isModerator }
|
||||
.toSet()
|
||||
val moderatorPosts = posts.asSequence().filter { it.submitterUser.isModerator }.toSet()
|
||||
assertTrue(moderatorPosts.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `posts with no urls`() = runBlocking {
|
||||
val posts = apiClient.getHottestPosts(1)
|
||||
val commentsOnlyPosts = posts.asSequence()
|
||||
.filter { it.url.isEmpty() }
|
||||
.toSet()
|
||||
val commentsOnlyPosts = posts.asSequence().filter { it.url.isEmpty() }.toSet()
|
||||
assertEquals(2, commentsOnlyPosts.size)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue