-
Notifications
You must be signed in to change notification settings - Fork 0
Mock Model
Batu Tasvaluan edited this page May 13, 2020
·
1 revision
-
MockSource
: Put all the mock scenario here. -
MockScenario
: Declare you scenario, including the basic info and target api endpoints.- A scenario might have several target api endpoints.
-
MockApi
: Declare the mock api endpoint and the mock response model.
- The whole path
// if the api url is: https://test.com/the/path/of/member?id=1234
val urlPaths = listof("the", "path", "of", "member")
- html method
val htmlMethod = "GET" // Right now this library just support GET method
- parameters
// if the api url is: https://test.com/the/path/of/member?id=1234
val urlParams = mutableMapOf("id" to "1234")
- response object
// You can put DAO or json string
val responseObject = private fun getMembers(): String =
"{\"age\":12,\"id\":132,\"name\":\"Belly World\"}"
val responseObject = Member(
name = "Belly World",
id = 132,
age = 12
)
val urlPaths = listof("the", "path", "of", "member")
val responseObject = Member(
name = "Belly World",
id = 132,
age = 12
)
val mockApi = MockApi(urlParams).apply {
htmlMethod = "GET"
responseObject = responseObject
urlParams = mutableMapOf("id" to "1234")
}
-
Basic info
- It would show on Bubble Interface.
-
The list of MockApi:
- It might have muliple MockApi in one MockScenario.
- Example: The display members' address info, we might call first api to get
member id
, then call second api to get themember address info
.
-
Selection State
- Indicate the default selection state of this scenario.
vak mockApiList = listof(mockApi)
val mockScenario1 = MockScenario(
page = "Main Page",
name = "Member List - same data with address"
).apply {
selected = false
mockApiList = mockApiList
}
Another way to declare MockScenario and MockApi
val mockScenario =
scenario(page = "Main Page", name = "Member List - several") {
select {
true
}
add {
api("the", "path", "of", "member") {
params {
param("id", 1234)
}
response {
Member(
name = "Belly World",
id = 132,
age = 12
)
}
}
}
add {
api("another", "path") {
response {
AnotherObject()
}
}
}
}
class MyMockSource : MockSource {
val mockScenario = ... // just like code section above
override fun create(): List<MockScenario> =
mutableListOf<MockScenario>().apply {
add(mockScenario)
}
}
You can check the whole setting in sample code.
- You have to make sure the whole api path and parameter are all exactly right.
- You can Ignore the value of parameter by using ANY_PARAM_VALUE
// regular way
urlParams = mutableMapOf("id" to ANY_PARAM_VALUE)
/// DSL
params {
param("id", ANY_PARAM_VALUE)
}
- You can Ignore the value of api apth by using ANY_PATH (However, the size of path must be correct)
// regular way
val urlPaths = listof("the", "path", ANY_PATH, ANY_PATH)
// DSL
api("the", "path", ANY_PATH, ANY_PATH) {
...
}