diff --git a/app-ktor/build.gradle.kts b/app-ktor/build.gradle.kts index a219444f..62c619dc 100644 --- a/app-ktor/build.gradle.kts +++ b/app-ktor/build.gradle.kts @@ -24,7 +24,6 @@ dependencies { implementation(project(":common")) implementation(project(":tts-lib")) implementation(project(":tts-client")) - implementation(project(":specs")) implementation(project(":core")) implementation(project(":db-common")) implementation(project(":db-pg")) diff --git a/app-ktor/src/main/kotlin/AppMain.kt b/app-ktor/src/main/kotlin/AppMain.kt index 1d276faa..66f65452 100644 --- a/app-ktor/src/main/kotlin/AppMain.kt +++ b/app-ktor/src/main/kotlin/AppMain.kt @@ -75,7 +75,7 @@ fun main(args: Array) = io.ktor.server.jetty.EngineMain.main(args) * - To disable authentication for debugging use `-DKEYCLOAK_DEBUG_AUTH=auth-uuid` * - For run mode (prod, test, stub) use `-DRUN_MODE=mode` * - * Example: `-DBOOTSTRAP_SERVERS=LOGS_KAFKA_HOSTS_IS_UNDEFINED -DKEYCLOAK_DEBUG_AUTH=c9a414f5-3f75-4494-b664-f4c8b33ff4e6 -DRUN_MODE=test` + * Example: `-DBOOTSTRAP_SERVERS=LOGS_KAFKA_HOSTS_IS_UNDEFINED -DKEYCLOAK_DEBUG_AUTH=c9a414f5-3f75-4494-b664-f4c8b33ff4e6 -DRUN_MODE=test -DDATA_DIRECTORY=/local/data` */ @KtorExperimentalLocationsAPI @Suppress("unused") @@ -86,7 +86,7 @@ fun Application.module( ) { logger.info(printGeneralSettings(runConfig, keycloakConfig, tutorConfig)) - val repositories = appRepositories() + val repositories = appRepositories(runConfig) val port = environment.config.property("ktor.deployment.port").getString() @@ -195,7 +195,7 @@ fun Application.module( if (principal == null) { call.respond(HttpStatusCode.Unauthorized) } else { - call.respond(thymeleafContent(runConfig, tutorConfig, keycloakConfig, principal)) + call.respond(thymeleafContent(tutorConfig, keycloakConfig, principal)) } } } @@ -212,14 +212,13 @@ fun Application.module( contextConfig = contextConfig, ) get("/") { - call.respond(thymeleafContent(runConfig, tutorConfig, keycloakConfig, null)) + call.respond(thymeleafContent(tutorConfig, keycloakConfig, null)) } } } } private fun thymeleafContent( - runConfig: RunConfig, tutorConfig: TutorConfig, keycloakConfig: KeycloakConfig, principal: OAuthAccessTokenResponse.OAuth2? @@ -239,7 +238,6 @@ private fun thymeleafContent( ) } val commonConfig = mapOf( - "runMode" to runConfig.modeString(), "numberOfWordsToShow" to tutorConfig.numberOfWordsToShow.toString(), "numberOfWordsPerStage" to tutorConfig.numberOfWordsPerStage.toString(), "numberOfRightAnswers" to tutorConfig.numberOfRightAnswers.toString(), diff --git a/app-ktor/src/main/kotlin/Repositories.kt b/app-ktor/src/main/kotlin/Repositories.kt index 6b9b4cca..0289da72 100644 --- a/app-ktor/src/main/kotlin/Repositories.kt +++ b/app-ktor/src/main/kotlin/Repositories.kt @@ -1,5 +1,6 @@ package com.gitlab.sszuev.flashcards +import com.gitlab.sszuev.flashcards.config.RunConfig import com.gitlab.sszuev.flashcards.dbmem.MemDbCardRepository import com.gitlab.sszuev.flashcards.dbmem.MemDbDictionaryRepository import com.gitlab.sszuev.flashcards.dbpg.PgDbCardRepository @@ -7,11 +8,17 @@ import com.gitlab.sszuev.flashcards.dbpg.PgDbDictionaryRepository import com.gitlab.sszuev.flashcards.speaker.createDirectTTSResourceRepository import com.gitlab.sszuev.flashcards.speaker.rabbitmq.RMQTTSResourceRepository -fun appRepositories() = AppRepositories( - prodTTSClientRepository = RMQTTSResourceRepository(), - testTTSClientRepository = createDirectTTSResourceRepository(), - prodCardRepository = PgDbCardRepository(), - testCardRepository = MemDbCardRepository(), - prodDictionaryRepository = PgDbDictionaryRepository(), - testDictionaryRepository = MemDbDictionaryRepository(), -) \ No newline at end of file +fun appRepositories(config: RunConfig) = if (config.mode == RunConfig.Mode.TEST) { + AppRepositories( + cardRepository = MemDbCardRepository(), + dictionaryRepository = MemDbDictionaryRepository(), + ttsClientRepository = createDirectTTSResourceRepository(), + ) +} else { + AppRepositories( + PgDbCardRepository(), + dictionaryRepository = + PgDbDictionaryRepository(), + ttsClientRepository = RMQTTSResourceRepository(), + ) +} \ No newline at end of file diff --git a/app-ktor/src/main/kotlin/config/RunConfig.kt b/app-ktor/src/main/kotlin/config/RunConfig.kt index a71226e4..d39e4c51 100644 --- a/app-ktor/src/main/kotlin/config/RunConfig.kt +++ b/app-ktor/src/main/kotlin/config/RunConfig.kt @@ -1,19 +1,18 @@ package com.gitlab.sszuev.flashcards.config -import com.gitlab.sszuev.flashcards.model.common.AppMode import io.ktor.server.config.ApplicationConfig data class RunConfig( val auth: String, - val mode: AppMode, + val mode: Mode, ) { constructor(config: ApplicationConfig) : this( auth = config.property("run-config.debug-auth").getString(), - mode = AppMode.valueOf(config.property("run-config.mode").getString().uppercase()), + mode = Mode.valueOf(config.property("run-config.mode").getString().uppercase()), ) - fun modeString(): String { - return mode.name.lowercase() + enum class Mode { + PROD, TEST } } \ No newline at end of file diff --git a/app-ktor/src/test/kotlin/TestUtils.kt b/app-ktor/src/test/kotlin/TestUtils.kt index d688cf67..4852912c 100644 --- a/app-ktor/src/test/kotlin/TestUtils.kt +++ b/app-ktor/src/test/kotlin/TestUtils.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.gitlab.sszuev.flashcards.config.KeycloakConfig +import com.gitlab.sszuev.flashcards.config.RunConfig import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.request.HttpRequestBuilder import io.ktor.client.request.header @@ -21,7 +22,7 @@ import io.ktor.server.testing.ApplicationTestBuilder import io.ktor.server.testing.testApplication import java.util.Base64 -val testKeycloakConfig = KeycloakConfig( +private val testKeycloakConfig = KeycloakConfig( authorizeAddress = "http://test-keycloak-server.ex", accessTokenAddress = "http://test-keycloak-server.ex", clientId = "test-client", @@ -31,12 +32,14 @@ val testKeycloakConfig = KeycloakConfig( realm = "test-realm", ) +private val testRunConfig = RunConfig(auth = "", mode = RunConfig.Mode.TEST) + @OptIn(KtorExperimentalLocationsAPI::class) fun testSecuredApp( block: suspend ApplicationTestBuilder.() -> Unit ) { testApplication { - application { module(keycloakConfig = testKeycloakConfig) } + application { module(keycloakConfig = testKeycloakConfig, runConfig = testRunConfig) } block() } } diff --git a/app-ktor/src/test/kotlin/api/controllers/CardControllerRunTest.kt b/app-ktor/src/test/kotlin/api/controllers/CardControllerRunTest.kt index 1d9a2227..e5f48c25 100644 --- a/app-ktor/src/test/kotlin/api/controllers/CardControllerRunTest.kt +++ b/app-ktor/src/test/kotlin/api/controllers/CardControllerRunTest.kt @@ -5,7 +5,6 @@ import com.gitlab.sszuev.flashcards.api.v1.models.CardWordExampleResource import com.gitlab.sszuev.flashcards.api.v1.models.CardWordResource import com.gitlab.sszuev.flashcards.api.v1.models.CreateCardRequest import com.gitlab.sszuev.flashcards.api.v1.models.CreateCardResponse -import com.gitlab.sszuev.flashcards.api.v1.models.DebugResource import com.gitlab.sszuev.flashcards.api.v1.models.DeleteCardRequest import com.gitlab.sszuev.flashcards.api.v1.models.DeleteCardResponse import com.gitlab.sszuev.flashcards.api.v1.models.GetAllCardsRequest @@ -20,7 +19,6 @@ import com.gitlab.sszuev.flashcards.api.v1.models.LearnResource import com.gitlab.sszuev.flashcards.api.v1.models.ResetCardRequest import com.gitlab.sszuev.flashcards.api.v1.models.ResetCardResponse import com.gitlab.sszuev.flashcards.api.v1.models.Result -import com.gitlab.sszuev.flashcards.api.v1.models.RunMode import com.gitlab.sszuev.flashcards.api.v1.models.SearchCardsRequest import com.gitlab.sszuev.flashcards.api.v1.models.SearchCardsResponse import com.gitlab.sszuev.flashcards.api.v1.models.UpdateCardRequest @@ -56,7 +54,6 @@ internal class CardControllerRunTest { fun `test get-audio-resource`() = testSecuredApp { val requestBody = GetAudioRequest( requestId = "resource-request", - debug = DebugResource(mode = RunMode.TEST), word = "xxx", lang = "xx", ) @@ -77,7 +74,6 @@ internal class CardControllerRunTest { fun `test get-all-cards success`() = testSecuredApp { val requestBody = GetAllCardsRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), dictionaryId = "2", ) val response = testPost("/v1/api/cards/get-all", requestBody) @@ -95,7 +91,6 @@ internal class CardControllerRunTest { // deterministic dictionary,we know exactly what entity is coming back: val requestBody = GetCardRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), cardId = "246", ) val response = testPost("/v1/api/cards/get", requestBody) @@ -137,7 +132,6 @@ internal class CardControllerRunTest { ) val requestBody = CreateCardRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), card = CardResource( dictionaryId = expectedCard.dictionaryId.asString(), words = expectedCard.words.map { @@ -170,7 +164,6 @@ internal class CardControllerRunTest { val start = OffsetDateTime.now(ZoneOffset.UTC).minusMinutes(1) val requestBody = UpdateCardRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), card = CardResource( cardId = "1", dictionaryId = "1", @@ -211,7 +204,6 @@ internal class CardControllerRunTest { fun `test search-cards success`() = testSecuredApp { val requestBody = SearchCardsRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), dictionaryIds = listOf("1", "2"), random = false, length = 2, @@ -230,7 +222,6 @@ internal class CardControllerRunTest { fun `test learn-card success`() = testSecuredApp { val requestBody = LearnCardsRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), cards = listOf(LearnResource(cardId = "246", details = mapOf("mosaic" to 42L))) ) val response = testPost("/v1/api/cards/learn", requestBody) @@ -247,7 +238,6 @@ internal class CardControllerRunTest { fun `test reset-card success`() = testSecuredApp { val requestBody = ResetCardRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), cardId = "246", ) val response = testPost("/v1/api/cards/reset", requestBody) @@ -264,7 +254,6 @@ internal class CardControllerRunTest { fun `test delete-card success`() = testSecuredApp { val requestBody = DeleteCardRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), cardId = "2", ) val response = testPost("/v1/api/cards/delete", requestBody) diff --git a/app-ktor/src/test/kotlin/api/controllers/CardControllerStubsTest.kt b/app-ktor/src/test/kotlin/api/controllers/CardControllerStubsTest.kt deleted file mode 100644 index 285dbb8a..00000000 --- a/app-ktor/src/test/kotlin/api/controllers/CardControllerStubsTest.kt +++ /dev/null @@ -1,328 +0,0 @@ -package com.gitlab.sszuev.flashcards.api.controllers - -import com.gitlab.sszuev.flashcards.api.v1.models.BaseResponse -import com.gitlab.sszuev.flashcards.api.v1.models.CardResource -import com.gitlab.sszuev.flashcards.api.v1.models.CardWordResource -import com.gitlab.sszuev.flashcards.api.v1.models.CreateCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.CreateCardResponse -import com.gitlab.sszuev.flashcards.api.v1.models.DebugResource -import com.gitlab.sszuev.flashcards.api.v1.models.DebugStub -import com.gitlab.sszuev.flashcards.api.v1.models.DeleteCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.DeleteCardResponse -import com.gitlab.sszuev.flashcards.api.v1.models.ErrorResource -import com.gitlab.sszuev.flashcards.api.v1.models.GetAllCardsRequest -import com.gitlab.sszuev.flashcards.api.v1.models.GetAllCardsResponse -import com.gitlab.sszuev.flashcards.api.v1.models.GetAudioRequest -import com.gitlab.sszuev.flashcards.api.v1.models.GetAudioResponse -import com.gitlab.sszuev.flashcards.api.v1.models.GetCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.GetCardResponse -import com.gitlab.sszuev.flashcards.api.v1.models.LearnCardsRequest -import com.gitlab.sszuev.flashcards.api.v1.models.LearnCardsResponse -import com.gitlab.sszuev.flashcards.api.v1.models.LearnResource -import com.gitlab.sszuev.flashcards.api.v1.models.ResetCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.ResetCardResponse -import com.gitlab.sszuev.flashcards.api.v1.models.Result -import com.gitlab.sszuev.flashcards.api.v1.models.RunMode -import com.gitlab.sszuev.flashcards.api.v1.models.SearchCardsRequest -import com.gitlab.sszuev.flashcards.api.v1.models.SearchCardsResponse -import com.gitlab.sszuev.flashcards.api.v1.models.UpdateCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.UpdateCardResponse -import com.gitlab.sszuev.flashcards.model.domain.CardEntity -import com.gitlab.sszuev.flashcards.stubs.stubCard -import com.gitlab.sszuev.flashcards.stubs.stubCards -import com.gitlab.sszuev.flashcards.stubs.stubError -import com.gitlab.sszuev.flashcards.stubs.stubLearnCardDetails -import com.gitlab.sszuev.flashcards.testPost -import com.gitlab.sszuev.flashcards.testSecuredApp -import io.ktor.client.call.body -import io.ktor.client.statement.HttpResponse -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test - -class CardControllerStubsTest { - - companion object { - private val testCard = CardResource( - words = stubCard.words.map { CardWordResource(word = it.word) }, - cardId = stubCard.cardId.asString(), - dictionaryId = stubCard.dictionaryId.asString() - ) - private val testLearnCard = LearnResource( - cardId = stubLearnCardDetails.cardId.asString(), - details = stubLearnCardDetails.details.mapKeys { it.toString() }, - ) - private val debugSuccess = DebugResource( - mode = RunMode.STUB, - stub = DebugStub.SUCCESS - ) - private val debugError = DebugResource( - mode = RunMode.STUB, - stub = DebugStub.ERROR_UNKNOWN - ) - - private suspend inline fun testResponseSuccess( - requestId: String?, - response: HttpResponse - ): X { - val res = response.body() - Assertions.assertEquals(200, response.status.value) - Assertions.assertEquals(requestId, res.requestId) - Assertions.assertEquals(Result.SUCCESS, res.result) - Assertions.assertNull(res.errors) - return res - } - - private suspend inline fun testResponseError( - requestId: String?, - response: HttpResponse - ): X { - val res = response.body() - Assertions.assertEquals(200, response.status.value) - Assertions.assertEquals(requestId, res.requestId) - Assertions.assertEquals(Result.ERROR, res.result) - Assertions.assertNotNull(res.errors) - asserError(res.errors) - return res - } - - private fun asserError(errors: List?) { - Assertions.assertNotNull(errors) - errors?.let { Assertions.assertEquals(1, it.size) } - val error = errors!![0] - Assertions.assertEquals(stubError.field, error.field) - Assertions.assertEquals(stubError.message, error.message) - Assertions.assertEquals(stubError.code, error.code) - Assertions.assertEquals(stubError.group, error.group) - } - - private fun assertCard(actual: CardEntity, expected: CardResource) { - Assertions.assertEquals(actual.cardId.asString(), expected.cardId) - Assertions.assertEquals(actual.dictionaryId.asString(), expected.dictionaryId) - Assertions.assertEquals(actual.words.size, expected.words!!.size) - actual.words.forEachIndexed { index, word -> - Assertions.assertEquals(word.word, expected.words!![index].word) - } - } - } - - @Test - fun `test create-card success`() = testSecuredApp { - val requestBody = CreateCardRequest( - requestId = "success-request", - debug = debugSuccess, - card = testCard - ) - val response = testPost("/v1/api/cards/create", requestBody) - testResponseSuccess(requestBody.requestId, response) - } - - @Test - fun `test create-card error`() = testSecuredApp { - val requestBody = CreateCardRequest( - requestId = "error-request", - debug = debugError, - card = testCard - ) - val response = testPost("/v1/api/cards/create", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test update-card success`() = testSecuredApp { - val requestBody = UpdateCardRequest( - requestId = "success-request", - debug = debugSuccess, - card = testCard - ) - val response = testPost("/v1/api/cards/update", requestBody) - testResponseSuccess(requestBody.requestId, response) - } - - @Test - fun `test update-card error`() = testSecuredApp { - val requestBody = UpdateCardRequest( - requestId = "error-request", - debug = debugError, - card = testCard - ) - val response = testPost("/v1/api/cards/update", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test search-cards card success`() = testSecuredApp { - val requestBody = SearchCardsRequest( - requestId = "success-request", - debug = debugSuccess, - dictionaryIds = listOf("42"), - length = 1, - random = false, - unknown = true, - ) - val response = testPost("/v1/api/cards/search", requestBody) - val responseBody = testResponseSuccess(requestBody.requestId, response) - Assertions.assertEquals(stubCards.size, responseBody.cards!!.size) - responseBody.cards!!.forEachIndexed { index, cardResource -> - val card = stubCards[index] - assertCard(card, cardResource) - } - } - - @Test - fun `test search-cards error`() = testSecuredApp { - val requestBody = SearchCardsRequest( - requestId = "error-request", - debug = debugError, - dictionaryIds = listOf("a", "b", "c"), - length = 42, - random = true, - unknown = false, - ) - val response = testPost("/v1/api/cards/search", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test get-card success`() = testSecuredApp { - val requestBody = GetCardRequest( - requestId = "success-request", - debug = debugSuccess, - cardId = testCard.cardId, - ) - val response = testPost("/v1/api/cards/get", requestBody) - val responseBody = testResponseSuccess(requestBody.requestId, response) - Assertions.assertNotNull(responseBody.card) - val responseEntity = responseBody.card!! - assertCard(stubCard, responseEntity) - } - - @Test - fun `test get-card error`() = testSecuredApp { - val requestBody = GetCardRequest( - requestId = "error-request", - debug = debugError, - cardId = testCard.cardId, - ) - val response = testPost("/v1/api/cards/get", requestBody) - val responseBody = testResponseError(requestBody.requestId, response) - Assertions.assertNull(responseBody.card) - } - - @Test - fun `test cards-learn success`() = testSecuredApp { - val requestBody = LearnCardsRequest( - requestId = "success-request", - debug = debugSuccess, - cards = listOf(testLearnCard.copy(cardId = "a"), testLearnCard.copy(cardId = "b")), - ) - val response = testPost("/v1/api/cards/learn", requestBody) - testResponseSuccess(requestBody.requestId, response) - } - - @Test - fun `test cards-learn error`() = testSecuredApp { - val requestBody = LearnCardsRequest( - requestId = "error-request", - debug = debugError, - cards = listOf(testLearnCard.copy(cardId = "d"), testLearnCard.copy(cardId = "e")), - ) - val response = testPost("/v1/api/cards/learn", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test reset-card success`() = testSecuredApp { - val requestBody = ResetCardRequest( - requestId = "success-request", - debug = debugSuccess, - cardId = "42", - ) - val response = testPost("/v1/api/cards/reset", requestBody) - testResponseSuccess(requestBody.requestId, response) - } - - @Test - fun `test reset-card error`() = testSecuredApp { - val requestBody = ResetCardRequest( - requestId = "error-request", - debug = debugError, - cardId = "42", - ) - val response = testPost("/v1/api/cards/reset", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test delete-card success`() = testSecuredApp { - val requestBody = DeleteCardRequest( - requestId = "success-request", - debug = debugSuccess, - cardId = "42", - ) - val response = testPost("/v1/api/cards/delete", requestBody) - testResponseSuccess(requestBody.requestId, response) - } - - @Test - fun `test delete-card error`() = testSecuredApp { - val requestBody = DeleteCardRequest( - requestId = "error-request", - debug = debugError, - cardId = "42", - ) - val response = testPost("/v1/api/cards/delete", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test get-audio resource error`() = testSecuredApp { - val requestBody = GetAudioRequest( - requestId = "error-request", - debug = debugError, - word = "xxx", - lang = "xx", - ) - val response = testPost("/v1/api/sounds/get", requestBody) - testResponseError(requestBody.requestId, response) - } - - @Test - fun `test get-audio resource success`() = testSecuredApp { - val requestBody = GetAudioRequest( - requestId = "success-request", - debug = debugSuccess, - word = "xxx", - lang = "xx", - ) - val response = testPost("/v1/api/sounds/get", requestBody) - testResponseSuccess(requestBody.requestId, response) - } - - - @Test - fun `test get-all-cards card success`() = testSecuredApp { - val requestBody = GetAllCardsRequest( - requestId = "success-request", - debug = debugSuccess, - dictionaryId = "42", - ) - val response = testPost("/v1/api/cards/get-all", requestBody) - val responseBody = testResponseSuccess(requestBody.requestId, response) - Assertions.assertEquals(stubCards.size, responseBody.cards!!.size) - responseBody.cards!!.forEachIndexed { index, cardResource -> - val card = stubCards[index] - assertCard(card, cardResource) - } - } - - @Test - fun `test get-all-cards error`() = testSecuredApp { - val requestBody = GetAllCardsRequest( - requestId = "error-request", - debug = debugError, - dictionaryId = "XXX", - ) - val response = testPost("/v1/api/cards/get-all", requestBody) - testResponseError(requestBody.requestId, response) - } -} diff --git a/app-ktor/src/test/kotlin/api/controllers/DictionaryControllerRunTest.kt b/app-ktor/src/test/kotlin/api/controllers/DictionaryControllerRunTest.kt index dba23287..8e15d289 100644 --- a/app-ktor/src/test/kotlin/api/controllers/DictionaryControllerRunTest.kt +++ b/app-ktor/src/test/kotlin/api/controllers/DictionaryControllerRunTest.kt @@ -2,7 +2,6 @@ package com.gitlab.sszuev.flashcards.api.controllers import com.gitlab.sszuev.flashcards.api.v1.models.CreateDictionaryRequest import com.gitlab.sszuev.flashcards.api.v1.models.CreateDictionaryResponse -import com.gitlab.sszuev.flashcards.api.v1.models.DebugResource import com.gitlab.sszuev.flashcards.api.v1.models.DeleteDictionaryRequest import com.gitlab.sszuev.flashcards.api.v1.models.DeleteDictionaryResponse import com.gitlab.sszuev.flashcards.api.v1.models.DictionaryResource @@ -11,7 +10,6 @@ import com.gitlab.sszuev.flashcards.api.v1.models.DownloadDictionaryResponse import com.gitlab.sszuev.flashcards.api.v1.models.GetAllDictionariesRequest import com.gitlab.sszuev.flashcards.api.v1.models.GetAllDictionariesResponse import com.gitlab.sszuev.flashcards.api.v1.models.Result -import com.gitlab.sszuev.flashcards.api.v1.models.RunMode import com.gitlab.sszuev.flashcards.api.v1.models.UploadDictionaryRequest import com.gitlab.sszuev.flashcards.api.v1.models.UploadDictionaryResponse import com.gitlab.sszuev.flashcards.dbmem.MemDatabase @@ -33,7 +31,6 @@ internal class DictionaryControllerRunTest { fun `test get-all-dictionaries success`() = testSecuredApp { val requestBody = GetAllDictionariesRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), ) val response = testPost("/v1/api/dictionaries/get-all", requestBody) val res = response.body() @@ -53,7 +50,6 @@ internal class DictionaryControllerRunTest { fun `test create-dictionary success`() = testSecuredApp { val requestBody = CreateDictionaryRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), dictionary = DictionaryResource( name = "xxx ", sourceLang = "sS", @@ -77,7 +73,6 @@ internal class DictionaryControllerRunTest { fun `test delete-dictionary success`() = testSecuredApp { val requestBody = DeleteDictionaryRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), dictionaryId = "1", ) val response = testPost("/v1/api/dictionaries/delete", requestBody) @@ -92,7 +87,6 @@ internal class DictionaryControllerRunTest { fun `test download-dictionary success`() = testSecuredApp { val requestBody = DownloadDictionaryRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), dictionaryId = "2", ) val response = testPost("/v1/api/dictionaries/download", requestBody) @@ -120,7 +114,6 @@ internal class DictionaryControllerRunTest { """.trimIndent() val requestBody = UploadDictionaryRequest( requestId = "success-request", - debug = DebugResource(mode = RunMode.TEST), resource = txt.toByteArray(Charsets.UTF_16), ) val response = testPost("/v1/api/dictionaries/upload", requestBody) diff --git a/common/src/commonMain/kotlin/AppRepositories.kt b/common/src/commonMain/kotlin/AppRepositories.kt index 401492fb..5fecd57a 100644 --- a/common/src/commonMain/kotlin/AppRepositories.kt +++ b/common/src/commonMain/kotlin/AppRepositories.kt @@ -1,6 +1,5 @@ package com.gitlab.sszuev.flashcards -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.repositories.DbCardRepository import com.gitlab.sszuev.flashcards.repositories.DbDictionaryRepository import com.gitlab.sszuev.flashcards.repositories.NoOpDbCardRepository @@ -9,39 +8,12 @@ import com.gitlab.sszuev.flashcards.repositories.NoOpTTSResourceRepository import com.gitlab.sszuev.flashcards.repositories.TTSResourceRepository data class AppRepositories( - private val prodTTSClientRepository: TTSResourceRepository = NoOpTTSResourceRepository, - private val testTTSClientRepository: TTSResourceRepository = NoOpTTSResourceRepository, - private val prodDictionaryRepository: DbDictionaryRepository = NoOpDbDictionaryRepository, - private val testDictionaryRepository: DbDictionaryRepository = NoOpDbDictionaryRepository, - private val prodCardRepository: DbCardRepository = NoOpDbCardRepository, - private val testCardRepository: DbCardRepository = NoOpDbCardRepository, + val cardRepository: DbCardRepository = NoOpDbCardRepository, + val dictionaryRepository: DbDictionaryRepository = NoOpDbDictionaryRepository, + val ttsClientRepository: TTSResourceRepository = NoOpTTSResourceRepository, ) { companion object { val NO_OP_REPOSITORIES = AppRepositories() } - - fun dictionaryRepository(mode: AppMode): DbDictionaryRepository { - return when (mode) { - AppMode.PROD -> prodDictionaryRepository - AppMode.TEST -> testDictionaryRepository - AppMode.STUB -> NoOpDbDictionaryRepository - } - } - - fun cardRepository(mode: AppMode): DbCardRepository { - return when (mode) { - AppMode.PROD -> prodCardRepository - AppMode.TEST -> testCardRepository - AppMode.STUB -> NoOpDbCardRepository - } - } - - fun ttsClientRepository(mode: AppMode): TTSResourceRepository { - return when (mode) { - AppMode.PROD -> prodTTSClientRepository - AppMode.TEST -> testTTSClientRepository - AppMode.STUB -> NoOpTTSResourceRepository - } - } } \ No newline at end of file diff --git a/common/src/commonMain/kotlin/CardContext.kt b/common/src/commonMain/kotlin/CardContext.kt index 10e25e9d..252e931f 100644 --- a/common/src/commonMain/kotlin/CardContext.kt +++ b/common/src/commonMain/kotlin/CardContext.kt @@ -3,10 +3,8 @@ package com.gitlab.sszuev.flashcards import com.gitlab.sszuev.flashcards.model.common.AppAuthId import com.gitlab.sszuev.flashcards.model.common.AppContext import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppRequestId import com.gitlab.sszuev.flashcards.model.common.AppStatus -import com.gitlab.sszuev.flashcards.model.common.AppStub import com.gitlab.sszuev.flashcards.model.common.NONE import com.gitlab.sszuev.flashcards.model.domain.CardEntity import com.gitlab.sszuev.flashcards.model.domain.CardFilter @@ -29,8 +27,6 @@ data class CardContext( override val config: AppConfig = AppConfig.DEFAULT, override var status: AppStatus = AppStatus.INIT, - override var workMode: AppMode = AppMode.PROD, - override var debugCase: AppStub = AppStub.NONE, override var requestId: AppRequestId = AppRequestId.NONE, override var requestAppAuthId: AppAuthId = AppAuthId.NONE, override var normalizedRequestAppAuthId: AppAuthId = AppAuthId.NONE, @@ -61,5 +57,5 @@ data class CardContext( var responseCardEntity: CardEntity = CardEntity.EMPTY, // get cards list response: var responseCardEntityList: List = listOf(), -): AppContext +) : AppContext diff --git a/common/src/commonMain/kotlin/DictionaryContext.kt b/common/src/commonMain/kotlin/DictionaryContext.kt index e4d78a27..db20e926 100644 --- a/common/src/commonMain/kotlin/DictionaryContext.kt +++ b/common/src/commonMain/kotlin/DictionaryContext.kt @@ -3,10 +3,8 @@ package com.gitlab.sszuev.flashcards import com.gitlab.sszuev.flashcards.model.common.AppAuthId import com.gitlab.sszuev.flashcards.model.common.AppContext import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppRequestId import com.gitlab.sszuev.flashcards.model.common.AppStatus -import com.gitlab.sszuev.flashcards.model.common.AppStub import com.gitlab.sszuev.flashcards.model.common.NONE import com.gitlab.sszuev.flashcards.model.domain.DictionaryEntity import com.gitlab.sszuev.flashcards.model.domain.DictionaryId @@ -22,8 +20,6 @@ data class DictionaryContext( override val config: AppConfig = AppConfig.DEFAULT, override var status: AppStatus = AppStatus.INIT, - override var workMode: AppMode = AppMode.PROD, - override var debugCase: AppStub = AppStub.NONE, override var requestId: AppRequestId = AppRequestId.NONE, override var requestAppAuthId: AppAuthId = AppAuthId.NONE, override var normalizedRequestAppAuthId: AppAuthId = AppAuthId.NONE, diff --git a/common/src/commonMain/kotlin/model/common/AppContext.kt b/common/src/commonMain/kotlin/model/common/AppContext.kt index 1a0602c4..136d3b5a 100644 --- a/common/src/commonMain/kotlin/model/common/AppContext.kt +++ b/common/src/commonMain/kotlin/model/common/AppContext.kt @@ -12,8 +12,6 @@ interface AppContext { val config: AppConfig var status: AppStatus - var workMode: AppMode - var debugCase: AppStub var requestId: AppRequestId // get user: diff --git a/common/src/commonMain/kotlin/model/common/AppMode.kt b/common/src/commonMain/kotlin/model/common/AppMode.kt deleted file mode 100644 index 16172165..00000000 --- a/common/src/commonMain/kotlin/model/common/AppMode.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.gitlab.sszuev.flashcards.model.common - -enum class AppMode { - PROD, - TEST, - STUB, -} \ No newline at end of file diff --git a/common/src/commonMain/kotlin/model/common/AppStub.kt b/common/src/commonMain/kotlin/model/common/AppStub.kt deleted file mode 100644 index a8b125c6..00000000 --- a/common/src/commonMain/kotlin/model/common/AppStub.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.gitlab.sszuev.flashcards.model.common - -/** - * Describes stub cases. - */ -enum class AppStub { - NONE, - SUCCESS, - UNKNOWN_ERROR, - - ERROR_UNEXPECTED_FIELD, - - ERROR_WRONG_CARD_ID, - ERROR_WRONG_DICTIONARY_ID, - ERROR_CARD_WRONG_WORD, - ERROR_CARD_WRONG_TRANSCRIPTION, - ERROR_CARD_WRONG_TRANSLATION, - ERROR_CARD_WRONG_EXAMPLES, - ERROR_CARD_WRONG_PART_OF_SPEECH, - ERROR_CARD_WRONG_DETAILS, - ERROR_CARD_WRONG_AUDIO_RESOURCE, - - ERROR_AUDIO_RESOURCE_WRONG_RESOURCE_ID, - ERROR_AUDIO_RESOURCE_NOT_FOUND, - ERROR_AUDIO_RESOURCE_SERVER_ERROR, - - ERROR_CARDS_WRONG_FILTER_LENGTH, - - ERROR_LEARN_CARD_WRONG_CARD_ID, - ERROR_LEARN_CARD_WRONG_STAGES, - ERROR_LEARN_CARD_WRONG_DETAILS, -} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 54bf8901..6e90c4d1 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -12,7 +12,6 @@ dependencies { implementation(project(":cor-lib")) implementation(project(":db-common")) implementation(project(":common")) - implementation(project(":specs")) testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion") diff --git a/core/src/main/kotlin/CardCorProcessor.kt b/core/src/main/kotlin/CardCorProcessor.kt index fba6fe4c..03455b7b 100644 --- a/core/src/main/kotlin/CardCorProcessor.kt +++ b/core/src/main/kotlin/CardCorProcessor.kt @@ -11,8 +11,6 @@ import com.gitlab.sszuev.flashcards.core.processes.processLearnCards import com.gitlab.sszuev.flashcards.core.processes.processResetCard import com.gitlab.sszuev.flashcards.core.processes.processResource import com.gitlab.sszuev.flashcards.core.processes.processUpdateCard -import com.gitlab.sszuev.flashcards.core.stubs.cardStubSuccess -import com.gitlab.sszuev.flashcards.core.stubs.stubError import com.gitlab.sszuev.flashcards.core.validators.validateCardEntityDictionaryId import com.gitlab.sszuev.flashcards.core.validators.validateCardEntityHasNoCardId import com.gitlab.sszuev.flashcards.core.validators.validateCardEntityHasValidCardId @@ -28,11 +26,7 @@ import com.gitlab.sszuev.flashcards.core.validators.validateResourceGetLangId import com.gitlab.sszuev.flashcards.core.validators.validateResourceGetWord import com.gitlab.sszuev.flashcards.core.validators.validateUserId import com.gitlab.sszuev.flashcards.corlib.chain -import com.gitlab.sszuev.flashcards.model.common.AppStub import com.gitlab.sszuev.flashcards.model.domain.CardOperation -import com.gitlab.sszuev.flashcards.stubs.stubAudioResource -import com.gitlab.sszuev.flashcards.stubs.stubCard -import com.gitlab.sszuev.flashcards.stubs.stubCards /** * Main class fot business logic, @@ -48,15 +42,6 @@ class CardCorProcessor { initContext() operation(CardOperation.GET_RESOURCE) { - stubs(CardOperation.GET_RESOURCE) { - cardStubSuccess(CardOperation.GET_RESOURCE) { - this.responseTTSResourceEntity = stubAudioResource - } - stubError(CardOperation.GET_RESOURCE) - stubError(CardOperation.GET_RESOURCE, AppStub.ERROR_AUDIO_RESOURCE_WRONG_RESOURCE_ID) - stubError(CardOperation.GET_RESOURCE, AppStub.ERROR_AUDIO_RESOURCE_NOT_FOUND) - stubError(CardOperation.GET_RESOURCE, AppStub.ERROR_AUDIO_RESOURCE_SERVER_ERROR) - } normalizers(CardOperation.GET_RESOURCE) validators(CardOperation.GET_RESOURCE) { validateUserId(CardOperation.GET_RESOURCE) @@ -69,14 +54,6 @@ class CardCorProcessor { } operation(CardOperation.SEARCH_CARDS) { - stubs(CardOperation.SEARCH_CARDS) { - cardStubSuccess(CardOperation.SEARCH_CARDS) { - this.responseCardEntityList = stubCards - } - stubError(CardOperation.SEARCH_CARDS) - stubError(CardOperation.SEARCH_CARDS, AppStub.ERROR_CARDS_WRONG_FILTER_LENGTH) - stubError(CardOperation.SEARCH_CARDS, AppStub.ERROR_WRONG_DICTIONARY_ID) - } normalizers(CardOperation.SEARCH_CARDS) validators(CardOperation.SEARCH_CARDS) { validateUserId(CardOperation.SEARCH_CARDS) @@ -89,13 +66,6 @@ class CardCorProcessor { } operation(CardOperation.GET_ALL_CARDS) { - stubs(CardOperation.GET_ALL_CARDS) { - cardStubSuccess(CardOperation.GET_ALL_CARDS) { - this.responseCardEntityList = stubCards - } - stubError(CardOperation.GET_ALL_CARDS) - stubError(CardOperation.GET_ALL_CARDS, AppStub.ERROR_WRONG_DICTIONARY_ID) - } normalizers(CardOperation.GET_ALL_CARDS) validators(CardOperation.GET_ALL_CARDS) { validateUserId(CardOperation.GET_ALL_CARDS) @@ -107,20 +77,6 @@ class CardCorProcessor { } operation(CardOperation.CREATE_CARD) { - stubs(CardOperation.CREATE_CARD) { - cardStubSuccess(CardOperation.CREATE_CARD) { - this.responseCardEntity = stubCard - } - stubError(CardOperation.CREATE_CARD) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_UNEXPECTED_FIELD) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_WORD) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_TRANSLATION) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_TRANSCRIPTION) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_EXAMPLES) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_PART_OF_SPEECH) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_DETAILS) - stubError(CardOperation.CREATE_CARD, AppStub.ERROR_CARD_WRONG_AUDIO_RESOURCE) - } normalizers(CardOperation.CREATE_CARD) validators(CardOperation.CREATE_CARD) { validateUserId(CardOperation.CREATE_CARD) @@ -134,20 +90,6 @@ class CardCorProcessor { } operation(CardOperation.UPDATE_CARD) { - stubs(CardOperation.UPDATE_CARD) { - cardStubSuccess(CardOperation.UPDATE_CARD) { - this.responseCardEntity = stubCard - } - stubError(CardOperation.UPDATE_CARD) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_WRONG_CARD_ID) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_WORD) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_TRANSLATION) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_TRANSCRIPTION) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_EXAMPLES) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_PART_OF_SPEECH) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_DETAILS) - stubError(CardOperation.UPDATE_CARD, AppStub.ERROR_CARD_WRONG_AUDIO_RESOURCE) - } normalizers(CardOperation.UPDATE_CARD) validators(CardOperation.UPDATE_CARD) { validateUserId(CardOperation.UPDATE_CARD) @@ -161,13 +103,6 @@ class CardCorProcessor { } operation(CardOperation.LEARN_CARDS) { - stubs(CardOperation.LEARN_CARDS) { - cardStubSuccess(CardOperation.LEARN_CARDS) - stubError(CardOperation.LEARN_CARDS) - stubError(CardOperation.LEARN_CARDS, AppStub.ERROR_LEARN_CARD_WRONG_CARD_ID) - stubError(CardOperation.LEARN_CARDS, AppStub.ERROR_LEARN_CARD_WRONG_STAGES) - stubError(CardOperation.LEARN_CARDS, AppStub.ERROR_LEARN_CARD_WRONG_DETAILS) - } normalizers(CardOperation.LEARN_CARDS) validators(CardOperation.LEARN_CARDS) { validateUserId(CardOperation.LEARN_CARDS) @@ -181,13 +116,6 @@ class CardCorProcessor { } operation(CardOperation.GET_CARD) { - stubs(CardOperation.GET_CARD) { - cardStubSuccess(CardOperation.GET_CARD) { - this.responseCardEntity = stubCard - } - stubError(CardOperation.GET_CARD) - stubError(CardOperation.GET_CARD, AppStub.ERROR_WRONG_CARD_ID) - } normalizers(CardOperation.GET_CARD) validators(CardOperation.GET_CARD) { validateUserId(CardOperation.GET_CARD) @@ -199,11 +127,6 @@ class CardCorProcessor { } operation(CardOperation.RESET_CARD) { - stubs(CardOperation.RESET_CARD) { - cardStubSuccess(CardOperation.RESET_CARD) - stubError(CardOperation.RESET_CARD) - stubError(CardOperation.RESET_CARD, AppStub.ERROR_WRONG_CARD_ID) - } normalizers(CardOperation.RESET_CARD) validators(CardOperation.RESET_CARD) { validateUserId(CardOperation.RESET_CARD) @@ -215,11 +138,6 @@ class CardCorProcessor { } operation(CardOperation.DELETE_CARD) { - stubs(CardOperation.DELETE_CARD) { - cardStubSuccess(CardOperation.DELETE_CARD) - stubError(CardOperation.DELETE_CARD) - stubError(CardOperation.DELETE_CARD, AppStub.ERROR_WRONG_CARD_ID) - } normalizers(CardOperation.DELETE_CARD) validators(CardOperation.DELETE_CARD) { validateUserId(CardOperation.DELETE_CARD) diff --git a/core/src/main/kotlin/ContextChains.kt b/core/src/main/kotlin/ContextChains.kt index f4508776..9e005d8f 100644 --- a/core/src/main/kotlin/ContextChains.kt +++ b/core/src/main/kotlin/ContextChains.kt @@ -4,7 +4,6 @@ import com.gitlab.sszuev.flashcards.corlib.ChainDSL import com.gitlab.sszuev.flashcards.corlib.chain import com.gitlab.sszuev.flashcards.corlib.worker import com.gitlab.sszuev.flashcards.model.common.AppContext -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppOperation import com.gitlab.sszuev.flashcards.model.common.AppStatus @@ -32,17 +31,6 @@ internal fun ChainDSL.operation( configure() } -internal fun ChainDSL.stubs( - operation: AppOperation, - configure: ChainDSL.() -> Unit -) = chain { - this.name = "${operation.name} ::: stubs" - test { - this.operation == operation && this.workMode == AppMode.STUB && this.status == AppStatus.RUN - } - configure() -} - internal fun ChainDSL.validators( operation: AppOperation, configure: ChainDSL.() -> Unit @@ -60,7 +48,7 @@ internal fun ChainDSL.runs( ) = chain { this.name = "${operation.name} ::: process" test { - this.operation == operation && this.workMode != AppMode.STUB && this.status == AppStatus.RUN + this.operation == operation && this.status == AppStatus.RUN } configure() finish(operation) @@ -71,7 +59,7 @@ internal fun ChainDSL.finish( ) = worker { this.name = "${operation.name} ::: finish" test { - this.operation == operation && this.workMode != AppMode.STUB && this.status == AppStatus.RUN + this.operation == operation && this.status == AppStatus.RUN } process { this.status = AppStatus.OK diff --git a/core/src/main/kotlin/DictionaryCorProcessor.kt b/core/src/main/kotlin/DictionaryCorProcessor.kt index 14baa365..7426d804 100644 --- a/core/src/main/kotlin/DictionaryCorProcessor.kt +++ b/core/src/main/kotlin/DictionaryCorProcessor.kt @@ -7,8 +7,6 @@ import com.gitlab.sszuev.flashcards.core.processes.processDeleteDictionary import com.gitlab.sszuev.flashcards.core.processes.processDownloadDictionary import com.gitlab.sszuev.flashcards.core.processes.processGetAllDictionary import com.gitlab.sszuev.flashcards.core.processes.processUploadDictionary -import com.gitlab.sszuev.flashcards.core.stubs.dictionaryStubSuccess -import com.gitlab.sszuev.flashcards.core.stubs.stubError import com.gitlab.sszuev.flashcards.core.validators.validateDictionaryEntityHasNoCardId import com.gitlab.sszuev.flashcards.core.validators.validateDictionaryId import com.gitlab.sszuev.flashcards.core.validators.validateDictionaryLangId @@ -16,7 +14,6 @@ import com.gitlab.sszuev.flashcards.core.validators.validateDictionaryResource import com.gitlab.sszuev.flashcards.core.validators.validateUserId import com.gitlab.sszuev.flashcards.corlib.chain import com.gitlab.sszuev.flashcards.model.domain.DictionaryOperation -import com.gitlab.sszuev.flashcards.stubs.stubDictionaries class DictionaryCorProcessor { suspend fun execute(context: DictionaryContext) = businessChain.exec(context) @@ -27,12 +24,6 @@ class DictionaryCorProcessor { initContext() operation(DictionaryOperation.GET_ALL_DICTIONARIES) { - stubs(DictionaryOperation.GET_ALL_DICTIONARIES) { - dictionaryStubSuccess(DictionaryOperation.GET_ALL_DICTIONARIES) { - this.responseDictionaryEntityList = stubDictionaries - } - stubError(DictionaryOperation.GET_ALL_DICTIONARIES) - } normalizers(DictionaryOperation.GET_ALL_DICTIONARIES) validators(DictionaryOperation.GET_ALL_DICTIONARIES) { } diff --git a/core/src/main/kotlin/processes/CardProcessWorkers.kt b/core/src/main/kotlin/processes/CardProcessWorkers.kt index fca46ce4..91b98f86 100644 --- a/core/src/main/kotlin/processes/CardProcessWorkers.kt +++ b/core/src/main/kotlin/processes/CardProcessWorkers.kt @@ -23,11 +23,11 @@ fun ChainDSL.processGetCard() = worker { process { val userId = this.normalizedRequestAppAuthId val cardId = this.normalizedRequestCardEntityId - val card = this.repositories.cardRepository(this.workMode).findCardById(cardId.asString())?.toCardEntity() + val card = this.repositories.cardRepository.findCardById(cardId.asString())?.toCardEntity() if (card == null) { this.errors.add(noCardFoundDataError(CardOperation.GET_CARD, cardId)) } else { - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(card.dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -66,7 +66,7 @@ fun ChainDSL.processGetAllCards() = worker { val userId = this.normalizedRequestAppAuthId val dictionaryId = this.normalizedRequestDictionaryId val dictionary = - this.repositories.dictionaryRepository(this.workMode).findDictionaryById(dictionaryId.asString()) + this.repositories.dictionaryRepository.findDictionaryById(dictionaryId.asString()) ?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -80,7 +80,7 @@ fun ChainDSL.processGetAllCards() = worker { this.errors.add(forbiddenEntityDataError(CardOperation.GET_ALL_CARDS, dictionaryId, userId)) } else { val cards = postProcess( - this.repositories.cardRepository(this.workMode) + this.repositories.cardRepository .findCardsByDictionaryId(dictionaryId.asString()).map { it.toCardEntity() }.iterator() ) { dictionary } this.responseCardEntityList = cards @@ -106,7 +106,7 @@ fun ChainDSL.processCardSearch() = worker { } process { val userId = this.normalizedRequestAppAuthId - val found = this.repositories.dictionaryRepository(this.workMode) + val found = this.repositories.dictionaryRepository .findDictionariesByIdIn(this.normalizedRequestCardFilter.dictionaryIds.map { it.asString() }) .map { it.toDictionaryEntity() } .associateBy { it.dictionaryId } @@ -137,7 +137,7 @@ fun ChainDSL.processCreateCard() = worker { process { val userId = this.normalizedRequestAppAuthId val dictionaryId = this.normalizedRequestCardEntity.dictionaryId - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -150,7 +150,7 @@ fun ChainDSL.processCreateCard() = worker { } else if (dictionary.userId != userId) { this.errors.add(forbiddenEntityDataError(CardOperation.CREATE_CARD, dictionaryId, userId)) } else { - val res = this.repositories.cardRepository(this.workMode) + val res = this.repositories.cardRepository .createCard(this.normalizedRequestCardEntity.toDbCard()).toCardEntity() this.responseCardEntity = postProcess(res) { dictionary } } @@ -169,7 +169,7 @@ fun ChainDSL.processUpdateCard() = worker { process { val userId = this.normalizedRequestAppAuthId val dictionaryId = this.normalizedRequestCardEntity.dictionaryId - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -182,7 +182,7 @@ fun ChainDSL.processUpdateCard() = worker { } else if (dictionary.userId != userId) { this.errors.add(forbiddenEntityDataError(CardOperation.UPDATE_CARD, dictionaryId, userId)) } else { - val res = this.repositories.cardRepository(this.workMode) + val res = this.repositories.cardRepository .updateCard(this.normalizedRequestCardEntity.toDbCard()).toCardEntity() this.responseCardEntity = postProcess(res) { dictionary } } @@ -201,7 +201,7 @@ fun ChainDSL.processLearnCards() = worker { process { val userId = this.normalizedRequestAppAuthId val cardLearns = this.normalizedRequestCardLearnList.associateBy { it.cardId } - val foundCards = this.repositories.cardRepository(this.workMode) + val foundCards = this.repositories.cardRepository .findCardsByIdIn(cardLearns.keys.map { it.asString() }).map { it.toCardEntity() }.toSet() val foundCardIds = foundCards.map { it.cardId }.toSet() val missedCardIds = cardLearns.keys - foundCardIds @@ -210,7 +210,7 @@ fun ChainDSL.processLearnCards() = worker { } val dictionaryIds = foundCards.map { it.dictionaryId }.toSet() val foundDictionaries = - this.repositories.dictionaryRepository(this.workMode) + this.repositories.dictionaryRepository .findDictionariesByIdIn(dictionaryIds.map { it.asString() }) .map { it.toDictionaryEntity() } .associateBy { it.dictionaryId } @@ -243,12 +243,12 @@ fun ChainDSL.processResetCard() = worker { process { val userId = this.normalizedRequestAppAuthId val cardId = this.normalizedRequestCardEntityId - val card = this.repositories.cardRepository(this.workMode).findCardById(cardId.asString())?.toCardEntity() + val card = this.repositories.cardRepository.findCardById(cardId.asString())?.toCardEntity() if (card == null) { this.errors.add(noCardFoundDataError(CardOperation.RESET_CARD, cardId)) } else { val dictionaryId = card.dictionaryId - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -261,7 +261,7 @@ fun ChainDSL.processResetCard() = worker { } else if (dictionary.userId != userId) { this.errors.add(forbiddenEntityDataError(CardOperation.RESET_CARD, dictionaryId, userId)) } else { - val res = this.repositories.cardRepository(this.workMode).updateCard(card.copy(answered = 0).toDbCard()) + val res = this.repositories.cardRepository.updateCard(card.copy(answered = 0).toDbCard()) this.responseCardEntity = postProcess(res.toCardEntity()) { dictionary } } } @@ -280,11 +280,11 @@ fun ChainDSL.processDeleteCard() = worker { process { val userId = this.normalizedRequestAppAuthId val cardId = this.normalizedRequestCardEntityId - val card = this.repositories.cardRepository(this.workMode).findCardById(cardId.asString())?.toCardEntity() + val card = this.repositories.cardRepository.findCardById(cardId.asString())?.toCardEntity() if (card == null) { this.errors.add(noCardFoundDataError(CardOperation.DELETE_CARD, cardId)) } else { - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(card.dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -297,7 +297,7 @@ fun ChainDSL.processDeleteCard() = worker { } else if (dictionary.userId != userId) { this.errors.add(forbiddenEntityDataError(CardOperation.DELETE_CARD, card.cardId, userId)) } else { - this.repositories.cardRepository(this.workMode) + this.repositories.cardRepository .deleteCard(this.normalizedRequestCardEntityId.asString()) } } @@ -324,7 +324,7 @@ private suspend fun CardContext.postProcess( dictionary: (DictionaryId) -> DictionaryEntity ): CardEntity { check(card != CardEntity.EMPTY) { "Null card" } - val tts = this.repositories.ttsClientRepository(this.workMode) + val tts = this.repositories.ttsClientRepository val sourceLang = dictionary.invoke(card.dictionaryId).sourceLang.langId val words = card.words.map { word -> val wordAudioId = tts.findResourceId(TTSResourceGet(word.word, sourceLang).normalize()) diff --git a/core/src/main/kotlin/processes/DictionaryProcessWokers.kt b/core/src/main/kotlin/processes/DictionaryProcessWokers.kt index 5bd27195..92950447 100644 --- a/core/src/main/kotlin/processes/DictionaryProcessWokers.kt +++ b/core/src/main/kotlin/processes/DictionaryProcessWokers.kt @@ -22,12 +22,12 @@ fun ChainDSL.processGetAllDictionary() = worker { } process { val userId = this.normalizedRequestAppAuthId - val res = this.repositories.dictionaryRepository(this.workMode) + val res = this.repositories.dictionaryRepository .findDictionariesByUserId(userId.asString()) .map { it.toDictionaryEntity() }.toList() this.responseDictionaryEntityList = res.map { dictionary -> val cards = - this.repositories.cardRepository(this.workMode) + this.repositories.cardRepository .findCardsByDictionaryId(dictionary.dictionaryId.asString()) .toList() val total = cards.size @@ -49,7 +49,7 @@ fun ChainDSL.processCreateDictionary() = worker { } process { val userId = this.normalizedRequestAppAuthId - val res = this.repositories.dictionaryRepository(this.workMode) + val res = this.repositories.dictionaryRepository .createDictionary(this.normalizedRequestDictionaryEntity.copy(userId = userId).toDbDictionary()) .toDictionaryEntity() this.responseDictionaryEntity = res @@ -68,7 +68,7 @@ fun ChainDSL.processDeleteDictionary() = worker { process { val userId = this.normalizedRequestAppAuthId val dictionaryId = this.normalizedRequestDictionaryId - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -81,7 +81,7 @@ fun ChainDSL.processDeleteDictionary() = worker { } else if (dictionary.userId != userId) { this.errors.add(forbiddenEntityDataError(DictionaryOperation.DELETE_DICTIONARY, dictionaryId, userId)) } else { - this.repositories.dictionaryRepository(this.workMode) + this.repositories.dictionaryRepository .deleteDictionary(this.normalizedRequestDictionaryId.asString()) } this.status = if (this.errors.isNotEmpty()) AppStatus.FAIL else AppStatus.RUN @@ -99,7 +99,7 @@ fun ChainDSL.processDownloadDictionary() = worker { process { val userId = this.normalizedRequestAppAuthId val dictionaryId = this.normalizedRequestDictionaryId - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .findDictionaryById(dictionaryId.asString())?.toDictionaryEntity() if (dictionary == null) { this.errors.add( @@ -112,7 +112,7 @@ fun ChainDSL.processDownloadDictionary() = worker { } else if (dictionary.userId != userId) { this.errors.add(forbiddenEntityDataError(DictionaryOperation.DOWNLOAD_DICTIONARY, dictionaryId, userId)) } else { - val cards = this.repositories.cardRepository(this.workMode) + val cards = this.repositories.cardRepository .findCardsByDictionaryId(dictionaryId.asString()) .map { it.toCardEntity() } .map { it.toDocumentCard(this.config) } @@ -141,7 +141,7 @@ fun ChainDSL.processUploadDictionary() = worker { try { val userId = this.normalizedRequestAppAuthId val document = createReader().parse(this.requestDictionaryResourceEntity.data) - val dictionary = this.repositories.dictionaryRepository(this.workMode) + val dictionary = this.repositories.dictionaryRepository .createDictionary( document.toDictionaryEntity().copy(userId = userId).toDbDictionary() ) @@ -152,7 +152,7 @@ fun ChainDSL.processUploadDictionary() = worker { .map { it.toDbCard() } .toList() if (cards.isNotEmpty()) { - this.repositories.cardRepository(this.workMode).createCards(cards) + this.repositories.cardRepository.createCards(cards) } this.responseDictionaryEntity = dictionary } catch (ex: Exception) { diff --git a/core/src/main/kotlin/processes/ResourceProcessWorkers.kt b/core/src/main/kotlin/processes/ResourceProcessWorkers.kt index 5234fd4e..12fbeb77 100644 --- a/core/src/main/kotlin/processes/ResourceProcessWorkers.kt +++ b/core/src/main/kotlin/processes/ResourceProcessWorkers.kt @@ -12,7 +12,7 @@ fun ChainDSL.processResource() = worker { this.name = "process audio resource request" process { val request = this.normalizedRequestTTSResourceGet - val foundId = this.repositories.ttsClientRepository(this.workMode).findResourceId(request) + val foundId = this.repositories.ttsClientRepository.findResourceId(request) if (foundId.errors.isNotEmpty()) { this.errors.addAll(foundId.errors) this.status = AppStatus.FAIL @@ -28,7 +28,7 @@ fun ChainDSL.processResource() = worker { this.status = AppStatus.FAIL return@process } - val foundResource = this.repositories.ttsClientRepository(this.workMode).getResource(foundId.id) + val foundResource = this.repositories.ttsClientRepository.getResource(foundId.id) if (foundResource.errors.isNotEmpty()) { this.errors.addAll(foundId.errors) this.status = AppStatus.FAIL diff --git a/core/src/main/kotlin/processes/SearchCardsHelper.kt b/core/src/main/kotlin/processes/SearchCardsHelper.kt index a1c0397f..0820c755 100644 --- a/core/src/main/kotlin/processes/SearchCardsHelper.kt +++ b/core/src/main/kotlin/processes/SearchCardsHelper.kt @@ -18,7 +18,7 @@ private val comparator: Comparator = Comparator { left, */ internal fun CardContext.findCardDeck(): List { val threshold = config.numberOfRightAnswers - var cards = this.repositories.cardRepository(this.workMode) + var cards = this.repositories.cardRepository .findCardsByDictionaryIdIn(this.normalizedRequestCardFilter.dictionaryIds.map { it.asString() }) .filter { !this.normalizedRequestCardFilter.onlyUnknown || (it.answered ?: -1) <= threshold } .map { it.toCardEntity() } diff --git a/core/src/main/kotlin/processes/UpdateCardsHelper.kt b/core/src/main/kotlin/processes/UpdateCardsHelper.kt index d5f4d030..05032269 100644 --- a/core/src/main/kotlin/processes/UpdateCardsHelper.kt +++ b/core/src/main/kotlin/processes/UpdateCardsHelper.kt @@ -25,5 +25,5 @@ internal fun CardContext.learnCards( } card.copy(stats = details, answered = answered.toInt()).toDbCard() } - return this.repositories.cardRepository(this.workMode).updateCards(cards).map { it.toCardEntity() } + return this.repositories.cardRepository.updateCards(cards).map { it.toCardEntity() } } \ No newline at end of file diff --git a/core/src/main/kotlin/stubs/StubWorkers.kt b/core/src/main/kotlin/stubs/StubWorkers.kt deleted file mode 100644 index 8de18b4b..00000000 --- a/core/src/main/kotlin/stubs/StubWorkers.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.gitlab.sszuev.flashcards.core.stubs - -import com.gitlab.sszuev.flashcards.CardContext -import com.gitlab.sszuev.flashcards.DictionaryContext -import com.gitlab.sszuev.flashcards.core.validators.fail -import com.gitlab.sszuev.flashcards.corlib.ChainDSL -import com.gitlab.sszuev.flashcards.corlib.worker -import com.gitlab.sszuev.flashcards.model.common.AppContext -import com.gitlab.sszuev.flashcards.model.common.AppOperation -import com.gitlab.sszuev.flashcards.model.common.AppStatus -import com.gitlab.sszuev.flashcards.model.common.AppStub -import com.gitlab.sszuev.flashcards.model.domain.CardOperation -import com.gitlab.sszuev.flashcards.model.domain.DictionaryOperation -import com.gitlab.sszuev.flashcards.stubs.stubError -import com.gitlab.sszuev.flashcards.stubs.stubErrorForCode - -fun ChainDSL.dictionaryStubSuccess( - operation: DictionaryOperation, - configure: DictionaryContext.() -> Unit = {} -) = stubSuccess(operation, configure) - -fun ChainDSL.cardStubSuccess( - operation: CardOperation, - configure: CardContext.() -> Unit = {} -) = stubSuccess(operation, configure) - -fun ChainDSL.stubSuccess( - operation: AppOperation, - configure: Context.() -> Unit = {} -) = worker { - name = "Stub :: ${operation.name} success" - test { - this.debugCase == AppStub.SUCCESS && this.status == AppStatus.RUN - } - process { - this.status = AppStatus.OK - this.configure() - } -} - -fun ChainDSL.stubError(operation: AppOperation) = worker { - this.name = "stub :: ${operation.name} fail unknown" - test { - this.debugCase == AppStub.UNKNOWN_ERROR && this.status == AppStatus.RUN - } - process { - fail(stubError) - } -} - -fun ChainDSL.stubError(operation: AppOperation, debugCase: AppStub) = - stubError("Stub :: ${operation.name} fail ${debugCase.name}", debugCase) - -private fun ChainDSL.stubError(name: String, debugCase: AppStub) = worker { - this.name = name - test { - this.debugCase == debugCase && this.status == AppStatus.RUN - } - process { - fail(stubErrorForCode(debugCase)) - } -} \ No newline at end of file diff --git a/core/src/test/kotlin/CardCorProcessorRunCardsTest.kt b/core/src/test/kotlin/CardCorProcessorRunCardsTest.kt index 241695d0..75a8b0c9 100644 --- a/core/src/test/kotlin/CardCorProcessorRunCardsTest.kt +++ b/core/src/test/kotlin/CardCorProcessorRunCardsTest.kt @@ -8,7 +8,6 @@ import com.gitlab.sszuev.flashcards.dbcommon.mocks.MockDbCardRepository import com.gitlab.sszuev.flashcards.dbcommon.mocks.MockDbDictionaryRepository import com.gitlab.sszuev.flashcards.model.common.AppAuthId import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppRequestId import com.gitlab.sszuev.flashcards.model.common.AppStatus import com.gitlab.sszuev.flashcards.model.domain.CardEntity @@ -25,10 +24,6 @@ import com.gitlab.sszuev.flashcards.repositories.DbDictionaryRepository import com.gitlab.sszuev.flashcards.repositories.TTSResourceIdResponse import com.gitlab.sszuev.flashcards.repositories.TTSResourceRepository import com.gitlab.sszuev.flashcards.speaker.MockTTSResourceRepository -import com.gitlab.sszuev.flashcards.stubs.stubCard -import com.gitlab.sszuev.flashcards.stubs.stubCards -import com.gitlab.sszuev.flashcards.stubs.stubDictionaries -import com.gitlab.sszuev.flashcards.stubs.stubDictionary import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @@ -50,13 +45,12 @@ internal class CardCorProcessorRunCardsTest { val context = CardContext( operation = op, repositories = AppRepositories().copy( - testCardRepository = cardRepository, - testDictionaryRepository = dictionaryRepository, - testTTSClientRepository = ttsResourceRepository, + cardRepository = cardRepository, + dictionaryRepository = dictionaryRepository, + ttsClientRepository = ttsResourceRepository, ), ) context.requestAppAuthId = testUserId - context.workMode = AppMode.TEST context.requestId = requestId(op) return context } @@ -186,7 +180,7 @@ internal class CardCorProcessorRunCardsTest { Assertions.assertEquals( testCards.size, - (context.repositories.ttsClientRepository(AppMode.TEST) as MockTTSResourceRepository).findResourceIdCounts.toInt() + (context.repositories.ttsClientRepository as MockTTSResourceRepository).findResourceIdCounts.toInt() ) Assertions.assertEquals(testCards, context.responseCardEntityList) diff --git a/core/src/test/kotlin/CardCorProcessorRunResourceTest.kt b/core/src/test/kotlin/CardCorProcessorRunResourceTest.kt index 7178093e..4626e8f5 100644 --- a/core/src/test/kotlin/CardCorProcessorRunResourceTest.kt +++ b/core/src/test/kotlin/CardCorProcessorRunResourceTest.kt @@ -3,7 +3,6 @@ package com.gitlab.sszuev.flashcards.core import com.gitlab.sszuev.flashcards.AppRepositories import com.gitlab.sszuev.flashcards.CardContext import com.gitlab.sszuev.flashcards.model.common.AppAuthId -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppRequestId import com.gitlab.sszuev.flashcards.model.common.AppStatus import com.gitlab.sszuev.flashcards.model.domain.CardOperation @@ -28,11 +27,10 @@ internal class CardCorProcessorRunResourceTest { val context = CardContext( operation = CardOperation.GET_RESOURCE, repositories = AppRepositories().copy( - testTTSClientRepository = repository + ttsClientRepository = repository ) ) context.requestAppAuthId = AppAuthId("42") - context.workMode = AppMode.TEST context.requestId = requestId() return context } diff --git a/core/src/test/kotlin/CardCorProcessorStubTest.kt b/core/src/test/kotlin/CardCorProcessorStubTest.kt deleted file mode 100644 index a65348d6..00000000 --- a/core/src/test/kotlin/CardCorProcessorStubTest.kt +++ /dev/null @@ -1,292 +0,0 @@ -package com.gitlab.sszuev.flashcards.core - -import com.gitlab.sszuev.flashcards.CardContext -import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppMode -import com.gitlab.sszuev.flashcards.model.common.AppRequestId -import com.gitlab.sszuev.flashcards.model.common.AppStatus -import com.gitlab.sszuev.flashcards.model.common.AppStub -import com.gitlab.sszuev.flashcards.model.domain.CardEntity -import com.gitlab.sszuev.flashcards.model.domain.CardFilter -import com.gitlab.sszuev.flashcards.model.domain.CardId -import com.gitlab.sszuev.flashcards.model.domain.CardLearn -import com.gitlab.sszuev.flashcards.model.domain.CardOperation -import com.gitlab.sszuev.flashcards.model.domain.DictionaryId -import com.gitlab.sszuev.flashcards.model.domain.LangId -import com.gitlab.sszuev.flashcards.model.domain.Stage -import com.gitlab.sszuev.flashcards.model.domain.TTSResourceGet -import com.gitlab.sszuev.flashcards.stubs.stubAudioResource -import com.gitlab.sszuev.flashcards.stubs.stubCard -import com.gitlab.sszuev.flashcards.stubs.stubCards -import com.gitlab.sszuev.flashcards.stubs.stubError -import com.gitlab.sszuev.flashcards.stubs.stubErrorForCode -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runTest -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments -import org.junit.jupiter.params.provider.EnumSource -import org.junit.jupiter.params.provider.MethodSource -import java.util.UUID - -@OptIn(ExperimentalCoroutinesApi::class) -internal class CardCorProcessorStubTest { - - companion object { - private val processor = CardCorProcessor() - private val requestId = UUID.randomUUID().toString() - private val testCard = stubCard.copy() - private val testAudioResourceGet = TTSResourceGet(lang = LangId("xx"), word = "xxx") - - private val testCardFilter = CardFilter( - dictionaryIds = listOf(2, 4, 42).map { DictionaryId(it.toString()) }, - length = 42, - random = true, - onlyUnknown = false, - ) - private val testCardLearn = CardLearn( - cardId = CardId("42"), - details = mapOf(Stage.SELF_TEST to 42) - ) - - private fun testContext(op: CardOperation, case: AppStub): CardContext { - val context = CardContext(operation = op) - context.workMode = AppMode.STUB - context.debugCase = case - context.requestId = AppRequestId(requestId) - return context - } - - private fun assertSuccess(context: CardContext) { - Assertions.assertEquals(requestId, context.requestId.asString()) - Assertions.assertEquals(AppStatus.OK, context.status) - Assertions.assertTrue(context.errors.isEmpty()) - } - - private fun assertFail(context: CardContext, expected: AppError = stubError) { - Assertions.assertEquals(requestId, context.requestId.asString()) - Assertions.assertEquals(AppStatus.FAIL, context.status) - Assertions.assertEquals(listOf(expected), context.errors) - } - - @JvmStatic - private fun updateCreateStubErrors(): List { - val cases = listOf( - AppStub.ERROR_CARD_WRONG_WORD, - AppStub.ERROR_CARD_WRONG_TRANSCRIPTION, - AppStub.ERROR_CARD_WRONG_TRANSLATION, - AppStub.ERROR_CARD_WRONG_EXAMPLES, - AppStub.ERROR_CARD_WRONG_PART_OF_SPEECH, - AppStub.ERROR_CARD_WRONG_DETAILS, - AppStub.ERROR_CARD_WRONG_AUDIO_RESOURCE, - ) - val operations = listOf(CardOperation.CREATE_CARD, CardOperation.UPDATE_CARD) - return operations.flatMap { op -> cases.map { Arguments.of(op, it) } } - } - } - - @ParameterizedTest - @EnumSource( - value = CardOperation::class, - names = [ - "CREATE_CARD", - "UPDATE_CARD", - ] - ) - fun `test create-card & update-card success`(operation: CardOperation) = runTest { - val context = testContext(operation, AppStub.SUCCESS) - context.requestCardEntity = testCard - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(testCard, context.responseCardEntity) - } - - @ParameterizedTest - @EnumSource( - value = CardOperation::class, - names = [ - "CREATE_CARD", - "UPDATE_CARD", - ] - ) - fun `test create-card & update-card unknown fail`(operation: CardOperation) = runTest { - val context = testContext(operation, AppStub.UNKNOWN_ERROR) - context.requestCardEntity = testCard - processor.execute(context) - assertFail(context) - Assertions.assertEquals(CardEntity.EMPTY, context.responseCardEntity) - } - - @Test - fun `test create-card specific fail`() = - testCreateUpdateCardSpecificStubFail(CardOperation.CREATE_CARD, AppStub.ERROR_UNEXPECTED_FIELD) - - @Test - fun `test update-card specific fail`() = - testCreateUpdateCardSpecificStubFail(CardOperation.UPDATE_CARD, AppStub.ERROR_WRONG_CARD_ID) - - @ParameterizedTest - @MethodSource("updateCreateStubErrors") - fun `test create-card & update-card specific fail`(operation: CardOperation, case: AppStub) = - testCreateUpdateCardSpecificStubFail(operation, case) - - private fun testCreateUpdateCardSpecificStubFail(operation: CardOperation, case: AppStub) = runTest { - val context = testContext(operation, case) - context.requestCardEntity = testCard - processor.execute(context) - assertFail(context, stubErrorForCode(case)) - Assertions.assertEquals(CardEntity.EMPTY, context.responseCardEntity) - } - - @Test - fun `test search-cards success`() = runTest { - val context = testContext(CardOperation.SEARCH_CARDS, AppStub.SUCCESS) - context.requestCardFilter = testCardFilter - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(stubCards, context.responseCardEntityList) - } - - @Test - fun `test search-cards unknown fail`() = runTest { - val context = testContext(CardOperation.SEARCH_CARDS, AppStub.UNKNOWN_ERROR) - context.requestCardFilter = testCardFilter - processor.execute(context) - assertFail(context) - Assertions.assertEquals(CardEntity.EMPTY, context.responseCardEntity) - } - - @ParameterizedTest - @EnumSource( - value = AppStub::class, - names = [ - "ERROR_WRONG_DICTIONARY_ID", - "ERROR_CARDS_WRONG_FILTER_LENGTH" - ] - ) - fun `test search-cards specific fail`(case: AppStub) = runTest { - val context = testContext(CardOperation.SEARCH_CARDS, case) - context.requestCardFilter = testCardFilter - processor.execute(context) - assertFail(context, stubErrorForCode(case)) - Assertions.assertTrue(context.responseCardEntityList.isEmpty()) - } - - @Test - fun `test learn-cards success`() = runTest { - val context = testContext(CardOperation.LEARN_CARDS, AppStub.SUCCESS) - context.requestCardLearnList = listOf(testCardLearn, testCardLearn) - processor.execute(context) - assertSuccess(context) - } - - @Test - fun `test learn-cards unknown fail`() = runTest { - val context = testContext(CardOperation.LEARN_CARDS, AppStub.UNKNOWN_ERROR) - context.requestCardLearnList = listOf(testCardLearn) - processor.execute(context) - assertFail(context) - } - - @ParameterizedTest - @EnumSource( - value = AppStub::class, - names = [ - "ERROR_LEARN_CARD_WRONG_CARD_ID", - "ERROR_LEARN_CARD_WRONG_STAGES", - "ERROR_LEARN_CARD_WRONG_DETAILS" - ] - ) - fun `test learn-cards specific fail`(case: AppStub) = runTest { - val context = testContext(CardOperation.LEARN_CARDS, case) - context.requestCardLearnList = listOf(testCardLearn) - processor.execute(context) - assertFail(context, stubErrorForCode(case)) - } - - @Test - fun `test get-card success`() = runTest { - val context = testContext(CardOperation.GET_CARD, AppStub.SUCCESS) - context.requestCardEntityId = testCard.cardId - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(stubCard, context.responseCardEntity) - } - - @Test - fun `test get-all-cards success`() = runTest { - val context = testContext(CardOperation.GET_ALL_CARDS, AppStub.SUCCESS) - context.requestDictionaryId = DictionaryId("42") - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(stubCards, context.responseCardEntityList) - } - - @Test - fun `test get-all-cards error`() = runTest { - val context = testContext(CardOperation.GET_ALL_CARDS, AppStub.ERROR_WRONG_DICTIONARY_ID) - context.requestDictionaryId = DictionaryId("42") - processor.execute(context) - assertFail(context, stubErrorForCode(AppStub.ERROR_WRONG_DICTIONARY_ID)) - Assertions.assertTrue(context.responseCardEntityList.isEmpty()) - } - - @ParameterizedTest - @EnumSource( - value = CardOperation::class, - names = [ - "RESET_CARD", - "DELETE_CARD", - ] - ) - fun `test request-with-card-id success`(operation: CardOperation) = runTest { - val context = testContext(operation, AppStub.SUCCESS) - context.requestCardEntityId = testCard.cardId - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(CardEntity.EMPTY, context.responseCardEntity) - } - - @ParameterizedTest - @EnumSource( - value = CardOperation::class, - names = [ - "GET_CARD", - "RESET_CARD", - "DELETE_CARD", - ] - ) - fun `test request-with-card-id specific fail`(operation: CardOperation) = runTest { - val context = testContext(operation, AppStub.ERROR_WRONG_CARD_ID) - context.requestCardEntity = testCard - processor.execute(context) - assertFail(context, stubErrorForCode(AppStub.ERROR_WRONG_CARD_ID)) - Assertions.assertEquals(CardEntity.EMPTY, context.responseCardEntity) - } - - @Test - fun `test get audio resource`() = runTest { - val context = testContext(CardOperation.GET_RESOURCE, AppStub.SUCCESS) - context.requestTTSResourceGet = testAudioResourceGet - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(stubAudioResource, context.responseTTSResourceEntity) - } - - @ParameterizedTest - @EnumSource( - value = AppStub::class, - names = [ - "ERROR_AUDIO_RESOURCE_WRONG_RESOURCE_ID", - "ERROR_AUDIO_RESOURCE_SERVER_ERROR", - "ERROR_AUDIO_RESOURCE_NOT_FOUND", - ] - ) - fun `test get-audion resource specific fail`(case: AppStub) = runTest { - val context = testContext(CardOperation.GET_RESOURCE, case) - context.requestTTSResourceGet = testAudioResourceGet - processor.execute(context) - assertFail(context, stubErrorForCode(case)) - } -} \ No newline at end of file diff --git a/core/src/test/kotlin/CardCorProcessorValidationTest.kt b/core/src/test/kotlin/CardCorProcessorValidationTest.kt index bb40f9c6..05a0441e 100644 --- a/core/src/test/kotlin/CardCorProcessorValidationTest.kt +++ b/core/src/test/kotlin/CardCorProcessorValidationTest.kt @@ -3,7 +3,6 @@ package com.gitlab.sszuev.flashcards.core import com.gitlab.sszuev.flashcards.CardContext import com.gitlab.sszuev.flashcards.model.common.AppAuthId import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppRequestId import com.gitlab.sszuev.flashcards.model.domain.CardEntity import com.gitlab.sszuev.flashcards.model.domain.CardFilter @@ -15,7 +14,6 @@ import com.gitlab.sszuev.flashcards.model.domain.DictionaryId import com.gitlab.sszuev.flashcards.model.domain.LangId import com.gitlab.sszuev.flashcards.model.domain.Stage import com.gitlab.sszuev.flashcards.model.domain.TTSResourceGet -import com.gitlab.sszuev.flashcards.stubs.stubCard import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions @@ -24,6 +22,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.EnumSource import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.ValueSource import java.util.UUID @OptIn(ExperimentalCoroutinesApi::class) @@ -46,10 +45,9 @@ internal class CardCorProcessorValidationTest { details = mapOf(Stage.MOSAIC to 42) ) - private fun testContext(op: CardOperation, mode: AppMode = AppMode.TEST): CardContext { + private fun testContext(op: CardOperation): CardContext { val context = CardContext(operation = op) context.requestAppAuthId = AppAuthId("42") - context.workMode = mode context.requestId = AppRequestId(requestId) return context } @@ -83,19 +81,11 @@ internal class CardCorProcessorValidationTest { return listOf("21", "42") } - @JvmStatic - private fun wrongIdsWithMode(): List { - val modes = listOf(AppMode.TEST, AppMode.STUB) - val ids = wrongIds() - return modes.flatMap { op -> ids.map { Arguments.of(it, op) } } - } - @JvmStatic private fun wrongIdsToOperationsWithCardIdInRequest(): List { val ops = listOf(CardOperation.GET_CARD, CardOperation.RESET_CARD, CardOperation.DELETE_CARD) - val modes = listOf(AppMode.TEST, AppMode.STUB) val ids = wrongIds() - return ops.flatMap { op -> modes.flatMap { m -> ids.map { Arguments.of(it, m, op) } } } + return ops.flatMap { op -> ids.map { Arguments.of(it, op) } } } @JvmStatic @@ -108,23 +98,13 @@ internal class CardCorProcessorValidationTest { @JvmStatic private fun wrongWordsCreateUpdateCardRequest(): List { val ops = listOf(CardOperation.CREATE_CARD, CardOperation.UPDATE_CARD) - val modes = listOf(AppMode.TEST, AppMode.STUB) - val words = wrongWords() - return ops.flatMap { op -> modes.flatMap { m -> words.map { Arguments.of(it, m, op) } } } - } - - @JvmStatic - private fun wrongWordsGetResource(): List { - val modes = listOf(AppMode.TEST, AppMode.STUB) val words = wrongWords() - return modes.flatMap { m -> words.map { Arguments.of(it, m) } } + return ops.flatMap { op -> words.map { Arguments.of(it, op) } } } @JvmStatic - private fun wrongLangIds(): List { - val modes = listOf(AppMode.TEST, AppMode.STUB) - val ids = sequenceOf("", "xxxxxx", "xxx:", "en~", "42") - return modes.flatMap { m -> ids.map { Arguments.of(it, m) } } + private fun wrongLangIds(): List { + return listOf("", "xxxxxx", "xxx:", "en~", "42") } } @@ -161,9 +141,9 @@ internal class CardCorProcessorValidationTest { @ParameterizedTest(name = parameterizedTestName) @MethodSource(value = ["wrongWordsCreateUpdateCardRequest"]) - fun `test create-card & update-card - validate word`(word: String, mode: AppMode, operation: CardOperation) = + fun `test create-card & update-card - validate word`(word: String, operation: CardOperation) = runTest { - val context = testContext(operation, mode) + val context = testContext(operation) val cardId = if (operation == CardOperation.CREATE_CARD) CardId.NONE else CardId("42") context.requestCardEntity = testCard.copy(words = listOf(CardWordEntity(word = word)), cardId = cardId) processor.execute(context) @@ -171,16 +151,9 @@ internal class CardCorProcessorValidationTest { assertValidationError("card-word", error) } - @ParameterizedTest(name = parameterizedTestName) - @EnumSource( - value = AppMode::class, - names = [ - "TEST", - "STUB", - ] - ) - fun `test update-card - validate wrong several fields`(mode: AppMode) = runTest { - val context = testContext(CardOperation.UPDATE_CARD, mode) + @Test + fun `test update-card - validate wrong several fields`() = runTest { + val context = testContext(CardOperation.UPDATE_CARD) context.requestCardEntity = testCard.copy( dictionaryId = DictionaryId(""), words = listOf(CardWordEntity(word = "")), @@ -194,16 +167,9 @@ internal class CardCorProcessorValidationTest { assertValidationError("card-word", errors[2]) } - @ParameterizedTest(name = parameterizedTestName) - @EnumSource( - value = AppMode::class, - names = [ - "TEST", - "STUB", - ] - ) - fun `test create-card - validate wrong several fields`(mode: AppMode) = runTest { - val context = testContext(CardOperation.CREATE_CARD, mode) + @Test + fun `test create-card - validate wrong several fields`() = runTest { + val context = testContext(CardOperation.CREATE_CARD) context.requestCardEntity = testCard.copy( dictionaryId = DictionaryId("sss"), words = listOf(CardWordEntity(word = "")), @@ -258,16 +224,9 @@ internal class CardCorProcessorValidationTest { assertValidationError("card-filter-dictionary-ids", errors[1]) } - @ParameterizedTest(name = parameterizedTestName) - @EnumSource( - value = AppMode::class, - names = [ - "TEST", - "STUB", - ] - ) - fun `test search-cards - validate wrong several fields`(mode: AppMode) = runTest { - val context = testContext(CardOperation.SEARCH_CARDS, mode) + @Test + fun `test search-cards - validate wrong several fields`() = runTest { + val context = testContext(CardOperation.SEARCH_CARDS) context.requestCardFilter = testCardFilter.copy( length = -42, dictionaryIds = wrongIds().map { DictionaryId(it) } @@ -334,8 +293,8 @@ internal class CardCorProcessorValidationTest { @ParameterizedTest(name = parameterizedTestName) @MethodSource(value = ["wrongIdsToOperationsWithCardIdInRequest"]) - fun `test request-with-cardId - validate CardId`(id: String, m: AppMode, op: CardOperation) = runTest { - val context = testContext(op, m) + fun `test request-with-cardId - validate CardId`(id: String, op: CardOperation) = runTest { + val context = testContext(op) context.requestCardEntityId = CardId(id) processor.execute(context) val error = error(context) @@ -344,8 +303,8 @@ internal class CardCorProcessorValidationTest { @ParameterizedTest(name = parameterizedTestName) @MethodSource(value = ["wrongLangIds"]) - fun `test get resource - validate request LangId`(id: String, m: AppMode) = runTest { - val context = testContext(CardOperation.GET_RESOURCE, m) + fun `test get resource - validate request LangId`(id: String) = runTest { + val context = testContext(CardOperation.GET_RESOURCE) context.requestTTSResourceGet = TTSResourceGet(lang = LangId(id), word = "xxx") processor.execute(context) val error = error(context) @@ -353,9 +312,9 @@ internal class CardCorProcessorValidationTest { } @ParameterizedTest(name = parameterizedTestName) - @MethodSource(value = ["wrongWordsGetResource"]) - fun `test get resource - validate request word`(word: String, m: AppMode) = runTest { - val context = testContext(CardOperation.GET_RESOURCE, m) + @MethodSource(value = ["wrongWords"]) + fun `test get resource - validate request word`(word: String) = runTest { + val context = testContext(CardOperation.GET_RESOURCE) context.requestTTSResourceGet = TTSResourceGet(lang = LangId("EN"), word = word) processor.execute(context) val error = error(context) @@ -363,9 +322,9 @@ internal class CardCorProcessorValidationTest { } @ParameterizedTest(name = parameterizedTestName) - @MethodSource(value = ["wrongIdsWithMode"]) - fun `test get-all-cards - validate DictionaryId`(id: String, m: AppMode) = runTest { - val context = testContext(CardOperation.GET_ALL_CARDS, m) + @MethodSource(value = ["wrongIds"]) + fun `test get-all-cards - validate DictionaryId`(id: String) = runTest { + val context = testContext(CardOperation.GET_ALL_CARDS) context.requestDictionaryId = DictionaryId(id) processor.execute(context) val error = error(context) @@ -375,29 +334,27 @@ internal class CardCorProcessorValidationTest { @ParameterizedTest(name = parameterizedTestName) @EnumSource(value = CardOperation::class, names = ["NONE"], mode = EnumSource.Mode.EXCLUDE) fun `test get-user - validate uid`(operation: CardOperation) = runTest { - sequenceOf(AppMode.TEST, AppMode.STUB).forEach { m -> - val context = testContext(operation, m) - .copy( - requestAppAuthId = AppAuthId(""), - requestTTSResourceGet = TTSResourceGet("xxx", LangId("EN")), - requestCardLearnList = listOf(CardLearn(CardId("42"), details = mapOf(Stage.MOSAIC to 42))), - requestCardFilter = CardFilter(dictionaryIds = listOf(DictionaryId("42")), length = 42), - requestCardEntityId = CardId("42"), - requestDictionaryId = DictionaryId("42"), - requestCardEntity = CardEntity( - cardId = if (operation == CardOperation.UPDATE_CARD) CardId("42") else CardId.NONE, - dictionaryId = DictionaryId("42"), - words = listOf( - CardWordEntity( - word = "xxx", - translations = listOf(listOf("kkk")) - ) + val context = testContext(operation) + .copy( + requestAppAuthId = AppAuthId(""), + requestTTSResourceGet = TTSResourceGet("xxx", LangId("EN")), + requestCardLearnList = listOf(CardLearn(CardId("42"), details = mapOf(Stage.MOSAIC to 42))), + requestCardFilter = CardFilter(dictionaryIds = listOf(DictionaryId("42")), length = 42), + requestCardEntityId = CardId("42"), + requestDictionaryId = DictionaryId("42"), + requestCardEntity = CardEntity( + cardId = if (operation == CardOperation.UPDATE_CARD) CardId("42") else CardId.NONE, + dictionaryId = DictionaryId("42"), + words = listOf( + CardWordEntity( + word = "xxx", + translations = listOf(listOf("kkk")) ) ) ) - processor.execute(context) - val error = error(context) - assertValidationError("user-uid", error) - } + ) + processor.execute(context) + val error = error(context) + assertValidationError("user-uid", error) } } \ No newline at end of file diff --git a/core/src/test/kotlin/DictionaryCorProcessorRunTest.kt b/core/src/test/kotlin/DictionaryCorProcessorRunTest.kt index 957b5909..fa871bd0 100644 --- a/core/src/test/kotlin/DictionaryCorProcessorRunTest.kt +++ b/core/src/test/kotlin/DictionaryCorProcessorRunTest.kt @@ -7,7 +7,6 @@ import com.gitlab.sszuev.flashcards.core.mappers.toDbDictionary import com.gitlab.sszuev.flashcards.core.normalizers.normalize import com.gitlab.sszuev.flashcards.dbcommon.mocks.MockDbCardRepository import com.gitlab.sszuev.flashcards.dbcommon.mocks.MockDbDictionaryRepository -import com.gitlab.sszuev.flashcards.model.common.AppMode import com.gitlab.sszuev.flashcards.model.common.AppRequestId import com.gitlab.sszuev.flashcards.model.common.AppStatus import com.gitlab.sszuev.flashcards.model.domain.DictionaryId @@ -17,9 +16,6 @@ import com.gitlab.sszuev.flashcards.model.domain.LangId import com.gitlab.sszuev.flashcards.model.domain.ResourceEntity import com.gitlab.sszuev.flashcards.repositories.DbCardRepository import com.gitlab.sszuev.flashcards.repositories.DbDictionaryRepository -import com.gitlab.sszuev.flashcards.stubs.stubCard -import com.gitlab.sszuev.flashcards.stubs.stubDictionaries -import com.gitlab.sszuev.flashcards.stubs.stubDictionary import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @@ -37,12 +33,11 @@ internal class DictionaryCorProcessorRunTest { val context = DictionaryContext( operation = op, repositories = AppRepositories().copy( - testDictionaryRepository = dictionaryRepository, - testCardRepository = cardsRepository, + dictionaryRepository = dictionaryRepository, + cardRepository = cardsRepository, ) ) context.requestAppAuthId = testUserId - context.workMode = AppMode.TEST context.requestId = requestId(op) return context } diff --git a/core/src/test/kotlin/DictionaryCorProcessorStubTest.kt b/core/src/test/kotlin/DictionaryCorProcessorStubTest.kt deleted file mode 100644 index d5dd591e..00000000 --- a/core/src/test/kotlin/DictionaryCorProcessorStubTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.gitlab.sszuev.flashcards.core - -import com.gitlab.sszuev.flashcards.DictionaryContext -import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppMode -import com.gitlab.sszuev.flashcards.model.common.AppRequestId -import com.gitlab.sszuev.flashcards.model.common.AppStatus -import com.gitlab.sszuev.flashcards.model.common.AppStub -import com.gitlab.sszuev.flashcards.model.domain.DictionaryOperation -import com.gitlab.sszuev.flashcards.stubs.stubDictionaries -import com.gitlab.sszuev.flashcards.stubs.stubError -import kotlinx.coroutines.test.runTest -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test -import java.util.UUID - -internal class DictionaryCorProcessorStubTest { - companion object { - private val processor = DictionaryCorProcessor() - private val requestId = UUID.randomUUID().toString() - - @Suppress("SameParameterValue") - private fun testContext(op: DictionaryOperation, case: AppStub): DictionaryContext { - val context = DictionaryContext(operation = op) - context.workMode = AppMode.STUB - context.debugCase = case - context.requestId = AppRequestId(requestId) - return context - } - - private fun assertSuccess(context: DictionaryContext) { - Assertions.assertEquals(requestId, context.requestId.asString()) - Assertions.assertEquals(AppStatus.OK, context.status) - Assertions.assertTrue(context.errors.isEmpty()) - } - - private fun assertFail(context: DictionaryContext, expected: AppError = stubError) { - Assertions.assertEquals(requestId, context.requestId.asString()) - Assertions.assertEquals(AppStatus.FAIL, context.status) - Assertions.assertEquals(listOf(expected), context.errors) - } - } - - @Test - fun `test get-all-dictionary success`() = runTest { - val context = testContext(DictionaryOperation.GET_ALL_DICTIONARIES, AppStub.SUCCESS) - processor.execute(context) - assertSuccess(context) - Assertions.assertEquals(stubDictionaries, context.responseDictionaryEntityList) - } - - @Test - fun `test get-all-dictionaries error`() = runTest { - val context = testContext(DictionaryOperation.GET_ALL_DICTIONARIES, AppStub.UNKNOWN_ERROR) - processor.execute(context) - processor.execute(context) - assertFail(context, stubError) - Assertions.assertTrue(context.responseDictionaryEntityList.isEmpty()) - } -} \ No newline at end of file diff --git a/specs/src/main/kotlin/Stubs.kt b/core/src/test/kotlin/Stubs.kt similarity index 69% rename from specs/src/main/kotlin/Stubs.kt rename to core/src/test/kotlin/Stubs.kt index 5e7b8ce7..63f11a18 100644 --- a/specs/src/main/kotlin/Stubs.kt +++ b/core/src/test/kotlin/Stubs.kt @@ -1,23 +1,17 @@ -package com.gitlab.sszuev.flashcards.stubs +package com.gitlab.sszuev.flashcards.core import com.gitlab.sszuev.flashcards.model.common.AppAuthId -import com.gitlab.sszuev.flashcards.model.common.AppError -import com.gitlab.sszuev.flashcards.model.common.AppStub import com.gitlab.sszuev.flashcards.model.domain.CardEntity import com.gitlab.sszuev.flashcards.model.domain.CardId -import com.gitlab.sszuev.flashcards.model.domain.CardLearn import com.gitlab.sszuev.flashcards.model.domain.CardWordEntity import com.gitlab.sszuev.flashcards.model.domain.CardWordExampleEntity import com.gitlab.sszuev.flashcards.model.domain.DictionaryEntity import com.gitlab.sszuev.flashcards.model.domain.DictionaryId import com.gitlab.sszuev.flashcards.model.domain.LangEntity import com.gitlab.sszuev.flashcards.model.domain.LangId -import com.gitlab.sszuev.flashcards.model.domain.ResourceEntity import com.gitlab.sszuev.flashcards.model.domain.Stage import com.gitlab.sszuev.flashcards.model.domain.TTSResourceId -const val STUB_ERROR_GROUP = "StubErrors" - val stubDictionary = DictionaryEntity( dictionaryId = DictionaryId(42.toString()), name = "Stub-dictionary", @@ -28,19 +22,6 @@ val stubDictionary = DictionaryEntity( val stubDictionaries = listOf(stubDictionary) -val stubAudioResource = ResourceEntity( - resourceId = TTSResourceId(42.toString()), - data = ByteArray(42) { 42 }, -) - -val stubError = AppError( - field = "the-error-field", - exception = AssertionError("Test-error"), - message = "the-error-message", - code = "StubErrorCode", - group = STUB_ERROR_GROUP, -) - val stubCard = CardEntity( cardId = CardId(42.toString()), dictionaryId = DictionaryId(42.toString()), @@ -78,17 +59,3 @@ val stubCards = IntRange(1, 3) sound = TTSResourceId("sl:$word"), ) } - -val stubLearnCardDetails = CardLearn( - cardId = CardId(42.toString()), - details = mapOf(Stage.SELF_TEST to 42, Stage.WRITING to 5, Stage.OPTIONS to 4) -) - -fun stubErrorForCode(case: AppStub): AppError { - return AppError( - field = "field::$case", - message = "the-error-message-for-$case", - code = case.name, - group = STUB_ERROR_GROUP, - ) -} \ No newline at end of file diff --git a/frontend/src/main/resources/static/api.js b/frontend/src/main/resources/static/api.js index 783f1f2e..8592b2b0 100644 --- a/frontend/src/main/resources/static/api.js +++ b/frontend/src/main/resources/static/api.js @@ -53,8 +53,7 @@ async function initKeycloak() { function getDictionaries(onDone) { const data = { 'requestId': uuid(), - 'requestType': getAllDictionariesRequestType, - 'debug': {'mode': runMode} + 'requestType': getAllDictionariesRequestType } post(getAllDictionariesURI, data, function (res) { if (hasResponseErrors(res)) { @@ -71,8 +70,7 @@ function getCards(dictionaryId, onDone) { const data = { 'dictionaryId': dictionaryId, 'requestId': uuid(), - 'requestType': getAllCardsRequestType, - 'debug': {'mode': runMode} + 'requestType': getAllCardsRequestType } post(getAllCardsURI, data, function (res) { if (hasResponseErrors(res)) { @@ -94,8 +92,7 @@ function getNextCardDeck(dictionaryIds, length, onDone) { 'requestId': uuid(), 'requestType': searchCardsRequestType, 'random': true, - 'length': length, - 'debug': {'mode': runMode} + 'length': length } post(searchCardsURI, data, function (res) { if (hasResponseErrors(res)) { @@ -113,8 +110,7 @@ function uploadDictionary(arrayBuffer, onDone, onFail) { const data = { 'requestId': uuid(), 'requestType': uploadDictionaryRequestType, - 'resource': base64, - 'debug': {'mode': runMode}, + 'resource': base64 } post(uploadDictionaryURI, data, function (res) { if (hasResponseErrors(res)) { @@ -132,8 +128,7 @@ function downloadDictionary(dictionaryId, downloadFilename, onDone) { const data = { 'requestId': uuid(), 'requestType': downloadDictionaryRequestType, - 'dictionaryId': dictionaryId, - 'debug': {'mode': runMode}, + 'dictionaryId': dictionaryId } post(downloadDictionaryURI, data, function (res) { if (hasResponseErrors(res)) { @@ -159,8 +154,7 @@ function createDictionary(dictionaryEntity, onDone) { const data = { 'requestId': uuid(), 'requestType': createDictionaryRequestType, - 'dictionary': dictionaryEntity, - 'debug': {'mode': runMode}, + 'dictionary': dictionaryEntity } post(createDictionaryURI, data, function (res) { if (hasResponseErrors(res)) { @@ -177,8 +171,7 @@ function deleteDictionary(dictionaryId, onDone) { const data = { 'requestId': uuid(), 'requestType': deleteDictionaryRequestType, - 'dictionaryId': dictionaryId, - 'debug': {'mode': runMode}, + 'dictionaryId': dictionaryId } post(deleteDictionaryURI, data, function (res) { if (hasResponseErrors(res)) { @@ -193,8 +186,7 @@ function createCard(card, onDone) { const data = { 'requestId': uuid(), 'requestType': createCardRequestType, - 'card': card, - 'debug': {'mode': runMode}, + 'card': card } post(createCardURI, data, function (res) { if (hasResponseErrors(res)) { @@ -211,8 +203,7 @@ function updateCard(card, onDone) { const data = { 'requestId': uuid(), 'requestType': updateCardRequestType, - 'card': card, - 'debug': {'mode': runMode}, + 'card': card } post(updateCardURI, data, function (res) { if (hasResponseErrors(res)) { @@ -227,8 +218,7 @@ function deleteCard(cardId, onDone) { const data = { 'requestId': uuid(), 'requestType': deleteCardRequestType, - 'cardId': cardId, - 'debug': {'mode': runMode}, + 'cardId': cardId } post(deleteCardURI, data, function (res) { if (hasResponseErrors(res)) { @@ -245,8 +235,7 @@ function resetCard(cardId, onDone) { const data = { 'requestId': uuid(), 'requestType': resetCardRequestType, - 'cardId': cardId, - 'debug': {'mode': runMode}, + 'cardId': cardId } post(resetCardURI, data, function (res) { if (hasResponseErrors(res)) { @@ -263,7 +252,6 @@ function learnCard(learns, onDone) { const data = { 'requestId': uuid(), 'requestType': learnCardRequestType, - 'debug': {'mode': runMode}, 'cards': learns } post(learnCardURI, data, function (res) { @@ -287,8 +275,7 @@ function playAudio(resourcePath, callback) { 'requestId': uuid(), 'requestType': getAudioRequestType, 'lang': path[0], - 'word': path[1], - 'debug': {'mode': runMode}, + 'word': path[1] } post(getAudioURI, data, function (res) { if (hasResponseErrors(res)) { diff --git a/frontend/src/main/resources/templates/index.html b/frontend/src/main/resources/templates/index.html index 7e954c4f..f5fdbb74 100644 --- a/frontend/src/main/resources/templates/index.html +++ b/frontend/src/main/resources/templates/index.html @@ -20,7 +20,6 @@ const keycloakAuthURL = [[${keycloakAuthURL}]]; const keycloakAppRealm = [[${keycloakAppRealm}]]; const keycloakAppClient = [[${keycloakAppClient}]]; - const runMode = [[${runMode}]]; const numberOfWordsToShow = [[${numberOfWordsToShow}]]; const numberOfWordsPerStage = [[${numberOfWordsPerStage}]]; const numberOfRightAnswers = [[${numberOfRightAnswers}]]; diff --git a/mappers/src/main/kotlin/CommonMappers.kt b/mappers/src/main/kotlin/CommonMappers.kt index 75ed74ac..42c96169 100644 --- a/mappers/src/main/kotlin/CommonMappers.kt +++ b/mappers/src/main/kotlin/CommonMappers.kt @@ -2,9 +2,15 @@ package com.gitlab.sszuev.flashcards.mappers.v1 import com.gitlab.sszuev.flashcards.CardContext import com.gitlab.sszuev.flashcards.DictionaryContext -import com.gitlab.sszuev.flashcards.api.v1.models.* +import com.gitlab.sszuev.flashcards.api.v1.models.BaseRequest +import com.gitlab.sszuev.flashcards.api.v1.models.BaseResponse +import com.gitlab.sszuev.flashcards.api.v1.models.ErrorResource +import com.gitlab.sszuev.flashcards.api.v1.models.Result import com.gitlab.sszuev.flashcards.model.Id -import com.gitlab.sszuev.flashcards.model.common.* +import com.gitlab.sszuev.flashcards.model.common.AppContext +import com.gitlab.sszuev.flashcards.model.common.AppError +import com.gitlab.sszuev.flashcards.model.common.AppRequestId +import com.gitlab.sszuev.flashcards.model.common.AppStatus import com.gitlab.sszuev.flashcards.model.domain.CardId import com.gitlab.sszuev.flashcards.model.domain.CardOperation import com.gitlab.sszuev.flashcards.model.domain.DictionaryId @@ -28,36 +34,6 @@ internal fun toCardId(id: String?) = id?.let { CardId(it) } ?: CardId.NONE internal fun toDictionaryId(id: String?) = id?.let { DictionaryId(it) } ?: DictionaryId.NONE -internal fun DebugResource?.transportToWorkMode(): AppMode = when (this?.mode) { - RunMode.PROD -> AppMode.PROD - RunMode.TEST -> AppMode.TEST - RunMode.STUB -> AppMode.STUB - null -> AppMode.PROD -} - -internal fun DebugResource?.transportToStubCase(): AppStub = when (this?.stub) { - DebugStub.SUCCESS -> AppStub.SUCCESS - DebugStub.ERROR_UNKNOWN -> AppStub.UNKNOWN_ERROR - DebugStub.ERROR_UNEXPECTED_FIELD -> AppStub.ERROR_UNEXPECTED_FIELD - DebugStub.ERROR_WRONG_CARD_ID -> AppStub.ERROR_WRONG_CARD_ID - DebugStub.ERROR_CARD_WRONG_WORD -> AppStub.ERROR_CARD_WRONG_WORD - DebugStub.ERROR_CARD_WRONG_TRANSCRIPTION -> AppStub.ERROR_CARD_WRONG_TRANSCRIPTION - DebugStub.ERROR_CARD_WRONG_TRANSLATION -> AppStub.ERROR_CARD_WRONG_TRANSLATION - DebugStub.ERROR_CARD_WRONG_EXAMPLES -> AppStub.ERROR_CARD_WRONG_EXAMPLES - DebugStub.ERROR_CARD_WRONG_PART_OF_SPEECH -> AppStub.ERROR_CARD_WRONG_PART_OF_SPEECH - DebugStub.ERROR_CARD_WRONG_DETAILS -> AppStub.ERROR_CARD_WRONG_DETAILS - DebugStub.ERROR_CARD_WRONG_AUDIO_RESOURCE -> AppStub.ERROR_CARD_WRONG_AUDIO_RESOURCE - DebugStub.ERROR_AUDIO_RESOURCE_WRONG_RESOURCE_ID -> AppStub.ERROR_AUDIO_RESOURCE_WRONG_RESOURCE_ID - DebugStub.ERROR_AUDIO_RESOURCE_SERVER_ERROR -> AppStub.ERROR_AUDIO_RESOURCE_SERVER_ERROR - DebugStub.ERROR_AUDIO_RESOURCE_NOT_FOUND -> AppStub.ERROR_AUDIO_RESOURCE_NOT_FOUND - DebugStub.ERROR_WRONG_DICTIONARY_ID -> AppStub.ERROR_WRONG_DICTIONARY_ID - DebugStub.ERROR_CARDS_WRONG_FILTER_LENGTH -> AppStub.ERROR_CARDS_WRONG_FILTER_LENGTH - DebugStub.ERROR_LEARN_CARD_WRONG_CARD_ID -> AppStub.ERROR_LEARN_CARD_WRONG_CARD_ID - DebugStub.ERROR_LEARN_CARD_WRONG_STAGES -> AppStub.ERROR_LEARN_CARD_WRONG_STAGES - DebugStub.ERROR_LEARN_CARD_WRONG_DETAILS -> AppStub.ERROR_LEARN_CARD_WRONG_DETAILS - null -> AppStub.NONE -} - internal fun List.toErrorResourceList(): List? = this .map { it.toErrorResource() } .toList() diff --git a/mappers/src/main/kotlin/FromCardTransport.kt b/mappers/src/main/kotlin/FromCardTransport.kt index 097d1ab7..eab295a4 100644 --- a/mappers/src/main/kotlin/FromCardTransport.kt +++ b/mappers/src/main/kotlin/FromCardTransport.kt @@ -44,28 +44,20 @@ fun CardContext.fromCardTransport(request: BaseRequest) = when (request) { fun CardContext.fromGetAudioRequest(request: GetAudioRequest) { this.requestId = request.requestId() this.requestTTSResourceGet = TTSResourceGet(word = request.word ?: "", lang = LangId(request.lang ?: "")) - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() } fun CardContext.fromGetCardRequest(request: GetCardRequest) { this.requestId = request.requestId() this.requestCardEntityId = toCardId(request.cardId) - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() } fun CardContext.fromGetAllCardsRequest(request: GetAllCardsRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestDictionaryId = toDictionaryId(request.dictionaryId) } fun CardContext.fromSearchCardsRequest(request: SearchCardsRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestCardFilter = CardFilter( dictionaryIds = request.dictionaryIds?.map { toDictionaryId(it) } ?: listOf(), length = request.length ?: 0, @@ -76,36 +68,26 @@ fun CardContext.fromSearchCardsRequest(request: SearchCardsRequest) { fun CardContext.fromCreateCardRequest(request: CreateCardRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestCardEntity = request.card?.toCardEntity() ?: CardEntity.EMPTY } fun CardContext.fromUpdateCardRequest(request: UpdateCardRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestCardEntity = request.card?.toCardEntity() ?: CardEntity.EMPTY } fun CardContext.fromDeleteCardRequest(request: DeleteCardRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestCardEntityId = toCardId(request.cardId) } fun CardContext.fromLearnCardRequest(request: LearnCardsRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestCardLearnList = request.cards?.map { it.toCardLearn() } ?: emptyList() } fun CardContext.fromResetCardRequest(request: ResetCardRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestCardEntityId = toCardId(request.cardId) } diff --git a/mappers/src/main/kotlin/FromDictionaryTransport.kt b/mappers/src/main/kotlin/FromDictionaryTransport.kt index 7c4803cc..6c1f7e41 100644 --- a/mappers/src/main/kotlin/FromDictionaryTransport.kt +++ b/mappers/src/main/kotlin/FromDictionaryTransport.kt @@ -15,35 +15,25 @@ fun DictionaryContext.fromDictionaryTransport(request: BaseRequest) = when (requ fun DictionaryContext.fromGetAllDictionariesRequest(request: GetAllDictionariesRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() } fun DictionaryContext.fromCreateDictionaryRequest(request: CreateDictionaryRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestDictionaryEntity = request.dictionary?.toDictionaryEntity() ?: DictionaryEntity.EMPTY } fun DictionaryContext.fromDeleteDictionaryRequest(request: DeleteDictionaryRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestDictionaryId = toDictionaryId(request.dictionaryId) } fun DictionaryContext.fromDownloadDictionaryRequest(request: DownloadDictionaryRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestDictionaryId = toDictionaryId(request.dictionaryId) } fun DictionaryContext.fromUploadDictionaryRequest(request: UploadDictionaryRequest) { this.requestId = request.requestId() - this.workMode = request.debug.transportToWorkMode() - this.debugCase = request.debug.transportToStubCase() this.requestDictionaryResourceEntity = ResourceEntity(DictionaryId.NONE, request.resource ?: ByteArray(0)) } diff --git a/mappers/src/test/kotlin/FromCardTransportTest.kt b/mappers/src/test/kotlin/FromCardTransportTest.kt index df8917b4..114e3531 100644 --- a/mappers/src/test/kotlin/FromCardTransportTest.kt +++ b/mappers/src/test/kotlin/FromCardTransportTest.kt @@ -5,20 +5,15 @@ import com.gitlab.sszuev.flashcards.api.v1.models.CardResource import com.gitlab.sszuev.flashcards.api.v1.models.CardWordExampleResource import com.gitlab.sszuev.flashcards.api.v1.models.CardWordResource import com.gitlab.sszuev.flashcards.api.v1.models.CreateCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.DebugResource -import com.gitlab.sszuev.flashcards.api.v1.models.DebugStub import com.gitlab.sszuev.flashcards.api.v1.models.DeleteCardRequest import com.gitlab.sszuev.flashcards.api.v1.models.GetAllCardsRequest import com.gitlab.sszuev.flashcards.api.v1.models.GetCardRequest import com.gitlab.sszuev.flashcards.api.v1.models.LearnCardsRequest import com.gitlab.sszuev.flashcards.api.v1.models.LearnResource import com.gitlab.sszuev.flashcards.api.v1.models.ResetCardRequest -import com.gitlab.sszuev.flashcards.api.v1.models.RunMode import com.gitlab.sszuev.flashcards.api.v1.models.SearchCardsRequest import com.gitlab.sszuev.flashcards.mappers.v1.testutils.assertCard import com.gitlab.sszuev.flashcards.mappers.v1.testutils.assertCardId -import com.gitlab.sszuev.flashcards.model.common.AppMode -import com.gitlab.sszuev.flashcards.model.common.AppStub import com.gitlab.sszuev.flashcards.model.domain.DictionaryId import com.gitlab.sszuev.flashcards.model.domain.Stage import org.junit.jupiter.api.Assertions @@ -28,13 +23,9 @@ internal class FromCardTransportTest { companion object { private fun assertContext( - expectedStub: AppStub, - expectedMode: AppMode, expectedRequestId: String, actual: CardContext ) { - Assertions.assertEquals(expectedStub, actual.debugCase) - Assertions.assertEquals(expectedMode, actual.workMode) Assertions.assertEquals(expectedRequestId, actual.requestId.asString()) } } @@ -44,17 +35,11 @@ internal class FromCardTransportTest { val req = GetCardRequest( requestId = "request=42", cardId = "card=42", - debug = DebugResource( - mode = RunMode.STUB, - stub = DebugStub.SUCCESS - ), ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.SUCCESS, - expectedMode = AppMode.STUB, expectedRequestId = "request=42", actual = context ) @@ -66,17 +51,11 @@ internal class FromCardTransportTest { val req = GetAllCardsRequest( requestId = "request=42", dictionaryId = "dictionary=42", - debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.SUCCESS - ), ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.SUCCESS, - expectedMode = AppMode.TEST, expectedRequestId = "request=42", actual = context ) @@ -87,10 +66,6 @@ internal class FromCardTransportTest { fun `test fromSearchCardsRequest`() { val req = SearchCardsRequest( requestId = "req", - debug = DebugResource( - mode = RunMode.PROD, - stub = DebugStub.ERROR_UNKNOWN - ), length = 42, random = true, unknown = true, @@ -100,8 +75,6 @@ internal class FromCardTransportTest { context.fromCardTransport(req) assertContext( - expectedStub = AppStub.UNKNOWN_ERROR, - expectedMode = AppMode.PROD, expectedRequestId = "req", actual = context ) @@ -144,18 +117,12 @@ internal class FromCardTransportTest { ) val req = CreateCardRequest( requestId = "req3", - debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.SUCCESS - ), card = card, ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.SUCCESS, - expectedMode = AppMode.TEST, expectedRequestId = "req3", actual = context ) @@ -181,21 +148,16 @@ internal class FromCardTransportTest { ) ), answered = 42, - stats = mapOf("options" to 42, "self-test" to 21), ) + stats = mapOf("options" to 42, "self-test" to 21), + ) val req = CreateCardRequest( requestId = "req4", - debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.ERROR_UNKNOWN - ), card = card ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.UNKNOWN_ERROR, - expectedMode = AppMode.TEST, expectedRequestId = "req4", actual = context ) @@ -207,17 +169,11 @@ internal class FromCardTransportTest { val req = DeleteCardRequest( requestId = "req5", cardId = "card5", - debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.ERROR_UNKNOWN - ), ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.UNKNOWN_ERROR, - expectedMode = AppMode.TEST, expectedRequestId = "req5", actual = context ) @@ -242,17 +198,11 @@ internal class FromCardTransportTest { details = mapOf("options" to 42) ), ), - debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.ERROR_UNKNOWN - ), ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.UNKNOWN_ERROR, - expectedMode = AppMode.TEST, expectedRequestId = "req6", actual = context ) @@ -273,17 +223,11 @@ internal class FromCardTransportTest { val req = ResetCardRequest( requestId = "req7", cardId = "card7", - debug = DebugResource( - mode = RunMode.STUB, - stub = DebugStub.ERROR_UNKNOWN - ), ) val context = CardContext() context.fromCardTransport(req) assertContext( - expectedStub = AppStub.UNKNOWN_ERROR, - expectedMode = AppMode.STUB, expectedRequestId = "req7", actual = context ) diff --git a/mappers/src/test/kotlin/FromDictionaryTransportTest.kt b/mappers/src/test/kotlin/FromDictionaryTransportTest.kt index 532697bb..dabe3694 100644 --- a/mappers/src/test/kotlin/FromDictionaryTransportTest.kt +++ b/mappers/src/test/kotlin/FromDictionaryTransportTest.kt @@ -1,10 +1,11 @@ package com.gitlab.sszuev.flashcards.mappers.v1 import com.gitlab.sszuev.flashcards.DictionaryContext -import com.gitlab.sszuev.flashcards.api.v1.models.* +import com.gitlab.sszuev.flashcards.api.v1.models.CreateDictionaryRequest +import com.gitlab.sszuev.flashcards.api.v1.models.DictionaryResource +import com.gitlab.sszuev.flashcards.api.v1.models.GetAllDictionariesRequest +import com.gitlab.sszuev.flashcards.api.v1.models.UploadDictionaryRequest import com.gitlab.sszuev.flashcards.mappers.v1.testutils.assertDictionary -import com.gitlab.sszuev.flashcards.model.common.AppMode -import com.gitlab.sszuev.flashcards.model.common.AppStub import com.gitlab.sszuev.flashcards.model.domain.DictionaryId import com.gitlab.sszuev.flashcards.model.domain.ResourceEntity import org.junit.jupiter.api.Assertions @@ -16,13 +17,9 @@ internal class FromDictionaryTransportTest { @Suppress("SameParameterValue") private fun assertContext( - expectedStub: AppStub, - expectedMode: AppMode, expectedRequestId: String, actual: DictionaryContext ) { - Assertions.assertEquals(expectedStub, actual.debugCase) - Assertions.assertEquals(expectedMode, actual.workMode) Assertions.assertEquals(expectedRequestId, actual.requestId.asString()) } } @@ -31,17 +28,11 @@ internal class FromDictionaryTransportTest { fun `test fromGetAllDictionariesRequest`() { val req = GetAllDictionariesRequest( requestId = "request=42", - debug = DebugResource( - mode = RunMode.STUB, - stub = DebugStub.SUCCESS - ), ) val context = DictionaryContext() context.fromDictionaryTransport(req) assertContext( - expectedStub = AppStub.SUCCESS, - expectedMode = AppMode.STUB, expectedRequestId = "request=42", actual = context ) @@ -51,19 +42,16 @@ internal class FromDictionaryTransportTest { fun `test fromUploadDictionariesRequest`() { val req = UploadDictionaryRequest( requestId = "request=42", - debug = DebugResource( - mode = RunMode.STUB, - stub = DebugStub.SUCCESS - ), resource = byteArrayOf(42), ) val context = DictionaryContext() context.fromDictionaryTransport(req) - Assertions.assertEquals(context.requestDictionaryResourceEntity, ResourceEntity(DictionaryId.NONE, byteArrayOf(42))) + Assertions.assertEquals( + context.requestDictionaryResourceEntity, + ResourceEntity(DictionaryId.NONE, byteArrayOf(42)) + ) assertContext( - expectedStub = AppStub.SUCCESS, - expectedMode = AppMode.STUB, expectedRequestId = "request=42", actual = context ) @@ -73,10 +61,6 @@ internal class FromDictionaryTransportTest { fun `test fromCreateDictionaryRequest`() { val req = CreateDictionaryRequest( requestId = "request=42", - debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.SUCCESS - ), dictionary = DictionaryResource( name = "xxx", sourceLang = "1", @@ -90,8 +74,6 @@ internal class FromDictionaryTransportTest { context.fromDictionaryTransport(req) assertContext( - expectedStub = AppStub.SUCCESS, - expectedMode = AppMode.TEST, expectedRequestId = "request=42", actual = context ) diff --git a/openapi/src/test/kotlin/CardSerializationTest.kt b/openapi/src/test/kotlin/CardSerializationTest.kt index 02c210c6..88b24859 100644 --- a/openapi/src/test/kotlin/CardSerializationTest.kt +++ b/openapi/src/test/kotlin/CardSerializationTest.kt @@ -1,9 +1,7 @@ package com.gitlab.sszuev.flashcards.api -import com.gitlab.sszuev.flashcards.api.testutils.assertDebug import com.gitlab.sszuev.flashcards.api.testutils.assertDictionary import com.gitlab.sszuev.flashcards.api.testutils.assertError -import com.gitlab.sszuev.flashcards.api.testutils.debug import com.gitlab.sszuev.flashcards.api.testutils.deserializeRequest import com.gitlab.sszuev.flashcards.api.testutils.deserializeResponse import com.gitlab.sszuev.flashcards.api.testutils.dictionary @@ -111,7 +109,6 @@ internal class CardSerializationTest { private fun assertCard(json: String) { Assertions.assertTrue(json.contains(cardJson)) - assertDebug(json) } private fun assertUpdate(json: String) { @@ -126,7 +123,6 @@ internal class CardSerializationTest { val req1 = CreateCardRequest( card = card, requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertEquals( @@ -134,10 +130,6 @@ internal class CardSerializationTest { { "requestType": "createCard", "requestId": "request=42", - "debug": { - "mode": "test", - "stub": "error_unknown" - }, "card": { "cardId": "42", "dictionaryId": "100500", @@ -178,7 +170,8 @@ internal class CardSerializationTest { "changedAt": -60830251080.000000000 } } - """.normalize(), json) + """.normalize(), json + ) val req2 = deserializeRequest(json) Assertions.assertNotSame(req1, req2) Assertions.assertEquals(req1.copy(requestType = "createCard"), req2) @@ -189,7 +182,6 @@ internal class CardSerializationTest { val req1 = UpdateCardRequest( card = card, requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"updateCard\"")) @@ -208,7 +200,6 @@ internal class CardSerializationTest { length = 42, dictionaryIds = listOf("100500", "4200"), requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"searchCards\"")) @@ -237,7 +228,6 @@ internal class CardSerializationTest { val req1 = GetAllCardsRequest( dictionaryId = "42", requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"getAllCards\"")) @@ -266,7 +256,6 @@ internal class CardSerializationTest { val req1 = GetCardRequest( cardId = "card-42", requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"getCard\"")) @@ -281,7 +270,6 @@ internal class CardSerializationTest { val req1 = ResetCardRequest( cardId = "card-42", requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"resetCard\"")) @@ -296,7 +284,6 @@ internal class CardSerializationTest { val req1 = DeleteCardRequest( cardId = "card-42", requestId = "request=42", - debug = debug ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"deleteCard\"")) diff --git a/openapi/src/test/kotlin/DictionarySerializationTest.kt b/openapi/src/test/kotlin/DictionarySerializationTest.kt index 180ccb87..2822af93 100644 --- a/openapi/src/test/kotlin/DictionarySerializationTest.kt +++ b/openapi/src/test/kotlin/DictionarySerializationTest.kt @@ -1,9 +1,7 @@ package com.gitlab.sszuev.flashcards.api -import com.gitlab.sszuev.flashcards.api.testutils.assertDebug import com.gitlab.sszuev.flashcards.api.testutils.assertDictionary import com.gitlab.sszuev.flashcards.api.testutils.assertError -import com.gitlab.sszuev.flashcards.api.testutils.debug import com.gitlab.sszuev.flashcards.api.testutils.deserializeRequest import com.gitlab.sszuev.flashcards.api.testutils.deserializeResponse import com.gitlab.sszuev.flashcards.api.testutils.dictionary @@ -60,14 +58,12 @@ internal class DictionarySerializationTest { val req1 = DeleteDictionaryRequest( requestId = "request=42", dictionaryId = "dictionary=42", - debug = debug, ) val json = serialize(req1) Assertions.assertTrue(json.contains("\"requestType\":\"deleteDictionary\"")) Assertions.assertTrue(json.contains("\"requestId\":\"request=42\"")) Assertions.assertTrue(json.contains("\"dictionaryId\":\"dictionary=42\"")) - assertDebug(json) val req2 = deserializeRequest(json) Assertions.assertNotSame(req1, req2) diff --git a/openapi/src/test/kotlin/testutils/ApiObjects.kt b/openapi/src/test/kotlin/testutils/ApiObjects.kt index 8cff1870..61620cdd 100644 --- a/openapi/src/test/kotlin/testutils/ApiObjects.kt +++ b/openapi/src/test/kotlin/testutils/ApiObjects.kt @@ -20,11 +20,6 @@ internal val error = ErrorResource( message = "mmm" ) -internal val debug = DebugResource( - mode = RunMode.TEST, - stub = DebugStub.ERROR_UNKNOWN -) - internal fun assertError(json: String) { Assertions.assertTrue(json.contains("\"code\":\"XXX\"")) Assertions.assertTrue(json.contains("\"group\":\"QQQ\"")) @@ -32,11 +27,6 @@ internal fun assertError(json: String) { Assertions.assertTrue(json.contains("\"message\":\"mmm\"")) } -internal fun assertDebug(json: String) { - Assertions.assertTrue(json.contains("\"mode\":\"test\"")) - Assertions.assertTrue(json.contains("\"stub\":\"error_unknown\"")) -} - internal fun assertDictionary(json: String) { Assertions.assertTrue(json.contains("\"dictionaryId\":\"42\"")) Assertions.assertTrue(json.contains("\"name\":\"XXX\"")) diff --git a/settings.gradle.kts b/settings.gradle.kts index 6f81e618..391bec03 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,7 +16,6 @@ include("openapi") include("common") include("mappers") include("app-ktor") -include("specs") include("cor-lib") include("core") include("tts-server") diff --git a/specs/build.gradle.kts b/specs/build.gradle.kts deleted file mode 100644 index 1f5a20d8..00000000 --- a/specs/build.gradle.kts +++ /dev/null @@ -1,10 +0,0 @@ -plugins { - kotlin("jvm") -} - -group = rootProject.group -version = rootProject.version - -dependencies { - implementation(project(":common")) -} \ No newline at end of file diff --git a/specs/spec-v1.yml b/specs/spec-v1.yml index 4a156b91..2a5c6b9a 100644 --- a/specs/spec-v1.yml +++ b/specs/spec-v1.yml @@ -319,7 +319,6 @@ components: description: Request to get audio resource (byte array) allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: lang: @@ -341,7 +340,6 @@ components: description: Request to read dictionaries allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object GetAllDictionariesResponse: @@ -359,7 +357,6 @@ components: description: Create dictionary request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: dictionary: @@ -378,7 +375,6 @@ components: description: Delete dictionary request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: dictionaryId: @@ -394,7 +390,6 @@ components: description: Download dictionary request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: dictionaryId: @@ -414,7 +409,6 @@ components: description: Upload dictionary request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: resource: @@ -434,7 +428,6 @@ components: description: Search cards request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: random: @@ -468,7 +461,6 @@ components: description: Request to get all cards by dictionaryId allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: dictionaryId: @@ -490,7 +482,6 @@ components: description: Get card by id request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: cardId: @@ -509,7 +500,6 @@ components: description: Create card request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: card: @@ -528,7 +518,6 @@ components: description: Update card request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: card: @@ -547,7 +536,6 @@ components: description: Learn card request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: cards: @@ -570,7 +558,6 @@ components: description: Delete card request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: cardId: @@ -587,7 +574,6 @@ components: description: Reset card status request allOf: - $ref: '#/components/schemas/BaseRequest' - - $ref: '#/components/schemas/DebugRequest' - type: object properties: cardId: @@ -631,12 +617,6 @@ components: deleteCard: '#/components/schemas/DeleteCardRequest' resetCard: '#/components/schemas/ResetCardRequest' - DebugRequest: - type: object - properties: - debug: - $ref: '#/components/schemas/DebugResource' - BaseResponse: type: object description: The base response - abstraction that holds response type and request id @@ -782,48 +762,9 @@ components: message: type: string - DebugResource: - type: object - properties: - mode: - $ref: '#/components/schemas/RunMode' - stub: - $ref: '#/components/schemas/DebugStub' - Result: description: Type of result type: string enum: - success - - error - - DebugStub: - type: string - description: Stubs - enum: - - success - - error_unexpected_field - - error_wrong_dictionary_id - - error_wrong_card_id - - error_card_wrong_word - - error_card_wrong_transcription - - error_card_wrong_translation - - error_card_wrong_examples - - error_card_wrong_part_of_speech - - error_card_wrong_details - - error_card_wrong_audio_resource - - error_audio_resource_wrong_resource_id - - error_audio_resource_server_error - - error_audio_resource_not_found - - error_cards_wrong_filter_length - - error_learn_card_wrong_card_id - - error_learn_card_wrong_stages - - error_learn_card_wrong_details - - error_unknown - - RunMode: - type: string - enum: - - prod - - test - - stub + - error \ No newline at end of file