diff --git a/src/main/kotlin/com/osglab/account/Application.kt b/src/main/kotlin/com/osglab/account/Application.kt index ad033e7..b85bf79 100644 --- a/src/main/kotlin/com/osglab/account/Application.kt +++ b/src/main/kotlin/com/osglab/account/Application.kt @@ -34,6 +34,7 @@ import com.osglab.account.features.credits.repositories.BillingTransactionRunner import com.osglab.account.features.credits.repositories.ExposedBillingTransactionRunner import com.osglab.account.features.credits.routes.AuthenticatedUserExtractor import com.osglab.account.features.credits.routes.creditRoutes +import com.osglab.account.features.credits.services.CreditOperations import com.osglab.account.features.credits.services.CreditService import com.osglab.account.features.credits.services.ReferralRewardConfig import com.osglab.account.features.gateway.adapters.CreditReservationAdapter @@ -336,6 +337,7 @@ fun accountServerModule(config: AppConfig): Module = module { ), ) } + single { get() } single { TrialCreditGranter { accountId -> get().grantSignupTrial( diff --git a/src/test/kotlin/com/osglab/account/ApplicationTest.kt b/src/test/kotlin/com/osglab/account/ApplicationTest.kt index c7fc12d..207f094 100644 --- a/src/test/kotlin/com/osglab/account/ApplicationTest.kt +++ b/src/test/kotlin/com/osglab/account/ApplicationTest.kt @@ -1,10 +1,19 @@ package com.osglab.account +import com.osglab.account.config.AppConfig +import com.osglab.account.features.credits.repositories.BillingTransactionRunner +import com.osglab.account.features.credits.repositories.BillingUnitOfWork +import com.osglab.account.features.credits.services.CreditOperations +import com.osglab.account.features.credits.services.CreditService import io.kotest.matchers.shouldBe import io.ktor.client.request.get import io.ktor.http.HttpStatusCode +import io.ktor.server.config.MapApplicationConfig import io.ktor.server.routing.routing import io.ktor.server.testing.testApplication +import org.koin.dsl.koinApplication +import org.koin.dsl.module +import java.util.Base64 import kotlin.test.Test class ApplicationTest { @@ -16,4 +25,49 @@ class ApplicationTest { client.get("/health/live").status shouldBe HttpStatusCode.OK } + + @Test + fun `application module exposes credit operations through its interface`() { + val transactionRunner = object : BillingTransactionRunner { + override suspend fun inTransaction(block: (BillingUnitOfWork) -> T): T = + error("Transaction runner is not used while resolving dependencies") + } + val application = koinApplication { + allowOverride(true) + modules(accountServerModule(testModuleConfig())) + modules(module { single { transactionRunner } }) + } + + try { + application.koin.get() shouldBe + application.koin.get() + } finally { + application.close() + } + } } + +private fun testModuleConfig(): AppConfig = AppConfig.from( + MapApplicationConfig( + "app.environment" to "test", + "app.database.jdbcUrl" to "jdbc:mysql://localhost:3306/test", + "app.database.username" to "test", + "app.database.password" to "database-password", + "app.database.migrationUsername" to "test_migrator", + "app.database.migrationPassword" to "migration-password", + "app.database.maximumPoolSize" to "4", + "app.session.issuer" to "https://issuer.example", + "app.session.audience" to "ios-app", + "app.session.secret" to "01234567890123456789012345678901", + "app.session.accessMinutes" to "15", + "app.session.refreshDays" to "30", + "app.encryption.keyBase64" to Base64.getEncoder().encodeToString(ByteArray(32) { 7 }), + "app.antiAbuse.identityHmacKeyBase64" to Base64.getEncoder().encodeToString(ByteArray(32) { 8 }), + "app.apple.clientId" to "com.example.app", + "app.apple.jwksUrl" to "https://appleid.apple.com/auth/keys", + "app.apple.tokenUrl" to "https://appleid.apple.com/auth/token", + "app.apple.revokeUrl" to "https://appleid.apple.com/auth/revoke", + "app.integrity.enforceDeviceCheck" to "false", + "app.integrity.enforceAppAttest" to "false", + ), +)