Skip to content

Commit

Permalink
feat[mock]: mock updated for photo details service
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifulSaif007 committed Aug 24, 2024
1 parent 8bcda3e commit 3f4edf8
Show file tree
Hide file tree
Showing 7 changed files with 2,460 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.saiful.mock.mappers
package com.saiful.mock

import okhttp3.mockwebserver.RecordedRequest

Expand Down
2 changes: 0 additions & 2 deletions mock/src/main/java/com/saiful/mock/MockMaker.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.saiful.mock

import com.saiful.mock.mappers.MockApi

class MockMaker {

private val mockApis = mutableMapOf<Regex, MockApi>()
Expand Down
12 changes: 9 additions & 3 deletions mock/src/main/java/com/saiful/mock/mappers/PhotoMockApi.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package com.saiful.mock.mappers

import com.saiful.mock.MockApi

object PhotoMockApi {

private val PHOTOS = Regex("^photos\\?page=\\d+&per_page=\\d+\$")
private val PHOTO_DETAILS = Regex("^photos/[^/]+\$")

fun getMap(): Map<Regex, MockApi> = mapOf(
PHOTOS to MockApi(
path = "photos",
findPath = { recordedRequest ->
val regex = """page=(\d+)""".toRegex()
when (regex.find(recordedRequest.path.toString())?.groupValues?.get(1) ?: "") {
"1" -> "photos/one"
"2" -> "photos/two"
else -> "photos"
"1" -> "photos/list/one"
"2" -> "photos/list/two"
else -> "photos/list"
}
}
),
PHOTO_DETAILS to MockApi(
path = "photos/details"
)
)
}
Loading

0 comments on commit 3f4edf8

Please sign in to comment.