|
431
|
1 |
/*
|
|
|
2 |
* Geekttrss is a RSS feed reader application on the Android Platform.
|
|
|
3 |
*
|
|
611
|
4 |
* Copyright (C) 2017-2020 by Frederic-Charles Barthelery.
|
|
431
|
5 |
*
|
|
|
6 |
* This file is part of Geekttrss.
|
|
|
7 |
*
|
|
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify
|
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
|
10 |
* the Free Software Foundation, either version 3 of the License, or
|
|
|
11 |
* (at your option) any later version.
|
|
|
12 |
*
|
|
|
13 |
* Geekttrss is distributed in the hope that it will be useful,
|
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 |
* GNU General Public License for more details.
|
|
|
17 |
*
|
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
*/
|
|
|
21 |
package com.geekorum.ttrss.webapi.model
|
|
|
22 |
|
|
|
23 |
import com.google.common.truth.Truth.assertThat
|
|
|
24 |
import kotlinx.serialization.UnstableDefault
|
|
|
25 |
import kotlinx.serialization.json.Json
|
|
|
26 |
import kotlin.test.Test
|
|
|
27 |
|
|
|
28 |
@UseExperimental(UnstableDefault::class)
|
|
|
29 |
class GetConfigJsonSerializationTest {
|
|
|
30 |
|
|
|
31 |
@Test
|
|
|
32 |
fun testThatGetConfigRequestPayloadDoCorrectJson() {
|
|
|
33 |
val payload = GetConfigRequestPayload().apply {
|
|
|
34 |
sessionId = "SESSION_ID"
|
|
|
35 |
}
|
|
|
36 |
val serializer = getSerializer<GetConfigRequestPayload>()
|
|
|
37 |
val result = Json.stringify(serializer, payload)
|
|
|
38 |
assertThat(result).isEqualTo("""
|
|
|
39 |
{"sid":"SESSION_ID","op":"getConfig"}
|
|
|
40 |
""".trimIndent())
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
@Test
|
|
|
44 |
fun testThatGetConfigResponsePayloadDoLoadCorrectly() {
|
|
|
45 |
val jsonString = """
|
|
|
46 |
{
|
|
|
47 |
"content" : {
|
|
|
48 |
"daemon_is_running" : true,
|
|
|
49 |
"icons_dir" : "feed-icons",
|
|
|
50 |
"icons_url" : "feed-icons",
|
|
|
51 |
"num_feeds" : 65
|
|
|
52 |
},
|
|
|
53 |
"seq" : 0,
|
|
|
54 |
"status" : 0
|
|
|
55 |
}
|
|
|
56 |
""".trimIndent()
|
|
|
57 |
val serializer = getSerializer<GetConfigResponsePayload>()
|
|
|
58 |
val result = Json.parse(serializer, jsonString)
|
|
|
59 |
val expected = GetConfigResponsePayload(
|
|
|
60 |
sequence = 0,
|
|
|
61 |
status = 0,
|
|
|
62 |
content = GetConfigResponsePayload.Content(daemonIsRunning = true,
|
|
|
63 |
iconsDir = "feed-icons",
|
|
|
64 |
iconsUrl = "feed-icons",
|
|
|
65 |
numFeeds = 65)
|
|
|
66 |
)
|
|
|
67 |
assertThat(result.sequence).isEqualTo(expected.sequence)
|
|
|
68 |
assertThat(result.status).isEqualTo(expected.status)
|
|
|
69 |
assertThat(result.content).isEqualTo(expected.content)
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@Test
|
|
|
73 |
fun testThatGetConfigResponsePayloadWithErrorDoLoadCorrectly() {
|
|
|
74 |
val jsonString = """
|
|
|
75 |
{
|
|
|
76 |
"seq": 2,
|
|
|
77 |
"status": 1,
|
|
|
78 |
"content": {"error":"NOT_LOGGED_IN"}
|
|
|
79 |
}
|
|
|
80 |
""".trimIndent()
|
|
|
81 |
val serializer = getSerializer<ListResponsePayload<Headline>>()
|
|
|
82 |
val result = Json.parse(serializer, jsonString)
|
|
|
83 |
val expected = GetConfigResponsePayload(
|
|
|
84 |
sequence = 2,
|
|
|
85 |
status = 1,
|
|
|
86 |
content = GetConfigResponsePayload.Content(error = Error.NOT_LOGGED_IN)
|
|
|
87 |
)
|
|
|
88 |
assertThat(result.sequence).isEqualTo(expected.sequence)
|
|
|
89 |
assertThat(result.status).isEqualTo(expected.status)
|
|
|
90 |
assertThat(result.content.error).isEqualTo(expected.content.error)
|
|
|
91 |
}
|
|
|
92 |
}
|