| author | Da Risk <da_risk@geekorum.com> |
| Mon, 16 Jan 2023 17:05:31 -0400 | |
| changeset 943 | 298742859784 |
| parent 886 | 7f5c2f2c7301 |
| child 1135 | 5dd06d1fbe83 |
| permissions | -rw-r--r-- |
| 431 | 1 |
/* |
2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
|
3 |
* |
|
|
943
298742859784
build: update license headers
Da Risk <da_risk@geekorum.com>
parents:
886
diff
changeset
|
4 |
* Copyright (C) 2017-2023 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 |
||
|
764
f1c8c08505a1
update to kotlin-1.4.10 and kotlinx.serialization-1.0.0
Da Risk <da_risk@geekorum.com>
parents:
750
diff
changeset
|
23 |
import com.geekorum.ttrss.webapi.Json |
| 431 | 24 |
import com.google.common.truth.Truth.assertThat |
25 |
import kotlin.test.Test |
|
26 |
||
27 |
class GetConfigJsonSerializationTest {
|
|
28 |
||
29 |
@Test |
|
30 |
fun testThatGetConfigRequestPayloadDoCorrectJson() {
|
|
31 |
val payload = GetConfigRequestPayload().apply {
|
|
32 |
sessionId = "SESSION_ID" |
|
33 |
} |
|
34 |
val serializer = getSerializer<GetConfigRequestPayload>() |
|
| 750 | 35 |
val result = Json.encodeToString(serializer, payload) |
| 431 | 36 |
assertThat(result).isEqualTo("""
|
37 |
{"sid":"SESSION_ID","op":"getConfig"}
|
|
38 |
""".trimIndent()) |
|
39 |
} |
|
40 |
||
41 |
@Test |
|
42 |
fun testThatGetConfigResponsePayloadDoLoadCorrectly() {
|
|
43 |
val jsonString = """ |
|
44 |
{
|
|
45 |
"content" : {
|
|
46 |
"daemon_is_running" : true, |
|
47 |
"icons_dir" : "feed-icons", |
|
48 |
"icons_url" : "feed-icons", |
|
|
886
7f5c2f2c7301
webapi: add Config.customSortTypes field
Da Risk <da_risk@geekorum.com>
parents:
882
diff
changeset
|
49 |
"custom_sort_types":[], |
| 431 | 50 |
"num_feeds" : 65 |
51 |
}, |
|
52 |
"seq" : 0, |
|
53 |
"status" : 0 |
|
54 |
} |
|
55 |
""".trimIndent() |
|
56 |
val serializer = getSerializer<GetConfigResponsePayload>() |
|
| 750 | 57 |
val result = Json.decodeFromString(serializer, jsonString) |
| 431 | 58 |
val expected = GetConfigResponsePayload( |
59 |
sequence = 0, |
|
60 |
status = 0, |
|
61 |
content = GetConfigResponsePayload.Content(daemonIsRunning = true, |
|
62 |
iconsDir = "feed-icons", |
|
63 |
iconsUrl = "feed-icons", |
|
64 |
numFeeds = 65) |
|
65 |
) |
|
66 |
assertThat(result.sequence).isEqualTo(expected.sequence) |
|
67 |
assertThat(result.status).isEqualTo(expected.status) |
|
68 |
assertThat(result.content).isEqualTo(expected.content) |
|
69 |
} |
|
70 |
||
71 |
@Test |
|
72 |
fun testThatGetConfigResponsePayloadWithErrorDoLoadCorrectly() {
|
|
73 |
val jsonString = """ |
|
74 |
{
|
|
75 |
"seq": 2, |
|
76 |
"status": 1, |
|
77 |
"content": {"error":"NOT_LOGGED_IN"}
|
|
78 |
} |
|
79 |
""".trimIndent() |
|
80 |
val serializer = getSerializer<ListResponsePayload<Headline>>() |
|
| 750 | 81 |
val result = Json.decodeFromString(serializer, jsonString) |
| 431 | 82 |
val expected = GetConfigResponsePayload( |
83 |
sequence = 2, |
|
84 |
status = 1, |
|
85 |
content = GetConfigResponsePayload.Content(error = Error.NOT_LOGGED_IN) |
|
86 |
) |
|
87 |
assertThat(result.sequence).isEqualTo(expected.sequence) |
|
88 |
assertThat(result.status).isEqualTo(expected.status) |
|
89 |
assertThat(result.content.error).isEqualTo(expected.content.error) |
|
90 |
} |
|
91 |
} |