Skip to content

Commit 9bd3936

Browse files
committed
Update test for response models
1 parent d8269ac commit 9bd3936

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

tests/languages/android/ServiceTest.kt

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.google.gson.Gson
66
import io.appwrite.exceptions.AppwriteException
77
import io.appwrite.extensions.fromJson
88
import io.appwrite.extensions.toJson
9+
import io.appwrite.models.Mock
10+
import io.appwrite.models.Error
911
import io.appwrite.services.Bar
1012
import io.appwrite.services.Foo
1113
import io.appwrite.services.General
@@ -68,37 +70,37 @@ class ServiceTest {
6870
}
6971

7072
runBlocking {
71-
var response: Response
73+
var mock: Mock
7274
// Foo Tests
73-
response = foo.get("string", 123, listOf("string in array"))
74-
printResponse(response)
75-
response = foo.post("string", 123, listOf("string in array"))
76-
printResponse(response)
77-
response = foo.put("string", 123, listOf("string in array"))
78-
printResponse(response)
79-
response = foo.patch("string", 123, listOf("string in array"))
80-
printResponse(response)
81-
response = foo.delete("string", 123, listOf("string in array"))
82-
printResponse(response)
75+
mock = foo.get("string", 123, listOf("string in array"))
76+
writeToFile(mock.result)
77+
mock = foo.post("string", 123, listOf("string in array"))
78+
writeToFile(mock.result)
79+
mock = foo.put("string", 123, listOf("string in array"))
80+
writeToFile(mock.result)
81+
mock = foo.patch("string", 123, listOf("string in array"))
82+
writeToFile(mock.result)
83+
mock = foo.delete("string", 123, listOf("string in array"))
84+
writeToFile(mock.result)
8385

8486
// Bar Tests
85-
response = bar.get("string", 123, listOf("string in array"))
86-
printResponse(response)
87-
response = bar.post("string", 123, listOf("string in array"))
88-
printResponse(response)
89-
response = bar.put("string", 123, listOf("string in array"))
90-
printResponse(response)
91-
response = bar.patch("string", 123, listOf("string in array"))
92-
printResponse(response)
93-
response = bar.delete("string", 123, listOf("string in array"))
94-
printResponse(response)
87+
mock = bar.get("string", 123, listOf("string in array"))
88+
writeToFile(mock.result)
89+
mock = bar.post("string", 123, listOf("string in array"))
90+
writeToFile(mock.result)
91+
mock = bar.put("string", 123, listOf("string in array"))
92+
writeToFile(mock.result)
93+
mock = bar.patch("string", 123, listOf("string in array"))
94+
writeToFile(mock.result)
95+
mock = bar.delete("string", 123, listOf("string in array"))
96+
writeToFile(mock.result)
9597

9698
// General Tests
97-
response = general.redirect()
98-
printResponse(response)
99+
val result = general.redirect()
100+
writeToFile((result as Map<String, Any>)["result"] as String)
99101

100-
response = general.upload("string", 123, listOf("string in array"), File("../../../resources/file.png"))
101-
printResponse(response)
102+
mock = general.upload("string", 123, listOf("string in array"), File("../../../resources/file.png"))
103+
writeToFile(mock.result)
102104

103105
try {
104106
general.error400()
@@ -123,17 +125,6 @@ class ServiceTest {
123125
}
124126
}
125127

126-
@Throws(IOException::class)
127-
private fun printResponse(response: Response) {
128-
// Store the outputs in a file and
129-
val gson = Gson()
130-
val map = gson.fromJson<Map<*, *>>(
131-
response.body!!.string(),
132-
MutableMap::class.java
133-
)
134-
writeToFile(map["result"] as String)
135-
}
136-
137128
private fun writeToFile(string: String?) {
138129
val text = "${string ?: ""}\n"
139130
File("result.txt").appendText(text)

0 commit comments

Comments
 (0)