Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
joreilly committed Jun 2, 2024
1 parent da17221 commit 8e666ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ jobs:
java-version: 17
- name: Build with Gradle
run: ./gradlew assembleDebug


- name: Build iOS shared code
run: ./gradlew :shared:compileKotlinIosArm64
#- name: Tests
# run: ./gradlew allTests

- name: Tests
run: ./gradlew :shared:jvmTest

- name: Build server
run: ./gradlew :server:assemble


androidTest:
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -36,9 +40,9 @@ jobs:
distribution: 'zulu'
java-version: 17

# - name: Android Instrumentation Tests
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: 29
# arch: x86_64
# script: ./gradlew androidApp:connectedAndroidTest
- name: Android Instrumentation Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
arch: x86_64
script: ./gradlew androidApp:connectedAndroidTest
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dev.johnoreilly.starwars.shared
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.api.toResponseJson
import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory
import com.apollographql.apollo3.cache.normalized.normalizedCache
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import dev.johnoreilly.starwars.shared.di.commonModule
Expand Down Expand Up @@ -35,29 +37,30 @@ class StarWarsRepositoryTest: KoinTest {
}
}

@Test
fun testStarWarsRepository() = runTest {
mockServerUrl = mockServer.url()
@Test
fun testStarWarsRepository() = runTest {
mockServerUrl = mockServer.url()

mockServer.enqueue(MockResponse.Builder().body(getAllPeopleMockResponse.toResponseJson()).build())
val people = repo.people.first()
assertEquals(2, people.size)
assertEquals("Person 1", people[0].name)
assertEquals("Home World 1", people[0].homeworld.name)
println(people)
mockServer.enqueue(MockResponse.Builder().body(getAllPeopleMockResponse.toResponseJson()).build())
val people = repo.people.first()
assertEquals(2, people.size)
assertEquals("Person 1", people[0].name)
assertEquals("Home World 1", people[0].homeworld.name)
println(people)

mockServer.enqueue(MockResponse.Builder().body(getAllFilmsMockResponse.toResponseJson()).build())
val films = repo.films.first()
assertEquals(2, films.size)
assertEquals("Film 1", films[0].title)
assertEquals("Director 1", films[0].director)
println(films)
}
mockServer.enqueue(MockResponse.Builder().body(getAllFilmsMockResponse.toResponseJson()).build())
val films = repo.films.first()
assertEquals(2, films.size)
assertEquals("Film 1", films[0].title)
assertEquals("Director 1", films[0].director)
println(films)
}

private fun createMockApolloClient(url: String): ApolloClient {
println("createMockApolloClient, ur = $url")
println("createMockApolloClient, url = $url")
return ApolloClient.Builder()
.serverUrl(url)
.normalizedCache(MemoryCacheFactory())
.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package dev.johnoreilly.starwars.shared

import dev.johnoreilly.starwars.shared.di.initKoin
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {

suspend fun main() {
val koin = initKoin().koin
val repo = koin.get<StarWarsRepository>()

Expand Down

0 comments on commit 8e666ba

Please sign in to comment.