Skip to content

Commit 8f05fd6

Browse files
committed
Generate test credentials file for compose app
1 parent dbbd7e3 commit 8f05fd6

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

native/kotlin/example/composeApp/build.gradle.kts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,49 @@ val generateBuildConfig = tasks.register("generateBuildConfig") {
145145
}
146146
}
147147

148+
// Generate TestCredentials from test_credentials.json
149+
val generateTestCredentials = tasks.register("generateTestCredentials") {
150+
val outputDir = layout.buildDirectory.dir("generated/source/testCredentials")
151+
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot") as String
152+
val credentialsFile = file("$cargoProjectRoot/test_credentials.json")
153+
154+
inputs.file(credentialsFile)
155+
outputs.dir(outputDir)
156+
157+
doLast {
158+
val json = groovy.json.JsonSlurper().parseText(credentialsFile.readText()) as Map<*, *>
159+
160+
val testCredentialsFile = outputDir.get().file("rs/wordpress/example/TestCredentials.kt").asFile
161+
testCredentialsFile.parentFile.mkdirs()
162+
testCredentialsFile.writeText("""
163+
package rs.wordpress.example
164+
165+
object TestCredentials {
166+
const val SITE_URL = "${json["site_url"]}"
167+
const val ADMIN_USERNAME = "${json["admin_username"]}"
168+
const val ADMIN_PASSWORD = "${json["admin_password"]}"
169+
const val SUBSCRIBER_USERNAME = "${json["subscriber_username"]}"
170+
const val SUBSCRIBER_PASSWORD = "${json["subscriber_password"]}"
171+
}
172+
""".trimIndent())
173+
}
174+
}
175+
148176
kotlin.sourceSets.getByName("desktopMain") {
149177
kotlin.srcDir(layout.buildDirectory.dir("generated/source/buildConfig"))
150178
}
151179

180+
kotlin.sourceSets.getByName("commonMain") {
181+
kotlin.srcDir(layout.buildDirectory.dir("generated/source/testCredentials"))
182+
}
183+
152184
tasks.named("compileKotlinDesktop").configure {
153185
dependsOn(generateBuildConfig)
186+
dependsOn(generateTestCredentials)
187+
}
188+
189+
tasks.matching { it.name.startsWith("compileKotlin") && it.name.contains("Android") }.configureEach {
190+
dependsOn(generateTestCredentials)
154191
}
155192

156193
tasks.named("desktopProcessResources").configure {

native/kotlin/example/composeApp/src/commonMain/kotlin/rs/wordpress/example/shared/di/AppModule.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package rs.wordpress.example.shared.di
22

33
import org.koin.dsl.module
4+
import rs.wordpress.example.TestCredentials
45
import rs.wordpress.example.shared.localTestSiteUrl
56
import rs.wordpress.example.shared.repository.AuthenticationRepository
67
import rs.wordpress.example.shared.ui.plugins.PluginListViewModel
@@ -9,14 +10,10 @@ import rs.wordpress.example.shared.ui.welcome.WelcomeViewModel
910

1011
val authModule = module {
1112
single {
12-
// TODO: Read from test credentials file
1313
AuthenticationRepository(
1414
localTestSiteUrl = localTestSiteUrl().siteUrl,
15-
localTestSiteUsername = "[email protected]",
16-
// Until this works with the included test credentials, you can grab it from the
17-
// `test_credentials.json` file `make test-server` will generate in the root of the repo
18-
// The key is `admin_password`
19-
localTestSitePassword = "s3N7vlbdrFPDDI3MbyFUvS3P"
15+
localTestSiteUsername = TestCredentials.ADMIN_USERNAME,
16+
localTestSitePassword = TestCredentials.ADMIN_PASSWORD
2017
)
2118
}
2219
}

0 commit comments

Comments
 (0)