diff --git a/backend/mr-api/mr-api.yaml b/backend/mr-api/mr-api.yaml index 15bf23657..d43e77a0b 100644 --- a/backend/mr-api/mr-api.yaml +++ b/backend/mr-api/mr-api.yaml @@ -2,7 +2,7 @@ openapi: 3.0.1 info: title: ManagementResourceApi description: This describes the API clients use for accessing features. This reflects the API from 1.6.1 onwards. - version: "1.2.2" + version: "1.2.3" # CRUD for portfolios, environments, features, service account, people, and groups (edited) # roles are fixed # then people<->group association diff --git a/backend/mr-db-sql/src/main/kotlin/io/featurehub/db/services/ApplicationRolloutStrategySqlApi.kt b/backend/mr-db-sql/src/main/kotlin/io/featurehub/db/services/ApplicationRolloutStrategySqlApi.kt index 0b928fae0..e84300359 100644 --- a/backend/mr-db-sql/src/main/kotlin/io/featurehub/db/services/ApplicationRolloutStrategySqlApi.kt +++ b/backend/mr-db-sql/src/main/kotlin/io/featurehub/db/services/ApplicationRolloutStrategySqlApi.kt @@ -16,7 +16,7 @@ import java.time.LocalDateTime import java.util.* class ApplicationRolloutStrategySqlApi @Inject constructor( - private val database: Database, private val conversions: Conversions, private val cacheSource: CacheSource + private val conversions: Conversions, private val cacheSource: CacheSource ) : ApplicationRolloutStrategyApi { override fun createStrategy( @@ -97,7 +97,7 @@ class ApplicationRolloutStrategySqlApi @Inject constructor( @Transactional private fun save(rs: DbApplicationRolloutStrategy) { - database.save(rs) + rs.save() } @@ -115,7 +115,7 @@ class ApplicationRolloutStrategySqlApi @Inject constructor( if (strategy.application.id == app.id) { // check if we are renaming it and if so, are we using a duplicate name update.name?.let { newName -> - if (!strategy.name.equals(update.name, ignoreCase = true)) { + if (!strategy.name.equals(newName, ignoreCase = true)) { // is there something using the existing name? val existing = QDbApplicationRolloutStrategy().application .eq(app).name @@ -127,6 +127,9 @@ class ApplicationRolloutStrategySqlApi @Inject constructor( throw ApplicationRolloutStrategyApi.DuplicateNameException() } } + + strategy.name = newName + strategy.strategy.name = newName } update.percentage?.let { percent -> diff --git a/backend/mr-db-sql/src/test/groovy/io/featurehub/db/services/ApplicationStrategySpec.groovy b/backend/mr-db-sql/src/test/groovy/io/featurehub/db/services/ApplicationStrategySpec.groovy new file mode 100644 index 000000000..20a3bdf90 --- /dev/null +++ b/backend/mr-db-sql/src/test/groovy/io/featurehub/db/services/ApplicationStrategySpec.groovy @@ -0,0 +1,45 @@ +package io.featurehub.db.services + +import io.featurehub.db.api.Opts +import io.featurehub.mr.model.CreateApplicationRolloutStrategy +import io.featurehub.mr.model.RolloutStrategyAttribute +import io.featurehub.mr.model.RolloutStrategyAttributeConditional +import io.featurehub.mr.model.RolloutStrategyFieldType +import io.featurehub.mr.model.UpdateApplicationRolloutStrategy + +class ApplicationStrategySpec extends Base3Spec { + ApplicationRolloutStrategySqlApi appStrategyApi + + def setup() { + appStrategyApi = new ApplicationRolloutStrategySqlApi(convertUtils, cacheSource) + } + + def "i can create, update and delete an application strategy"() { + given: "i have an app strategy" + def create = new CreateApplicationRolloutStrategy() + .name("phred").disabled(false) + .percentage(20000) + .attributes([new RolloutStrategyAttribute().id("abcde") + .type(RolloutStrategyFieldType.BOOLEAN) + .values([true]) + .fieldName("jxtq") + .conditional(RolloutStrategyAttributeConditional.ENDS_WITH)]) + when: "i save it" + def strat = appStrategyApi.createStrategy(app1.id, create, superuser, Opts.empty()) + then: + strat.name == "phred" + strat.percentage == 20000 + when: "i update it with the same name, its ok" + def updated = appStrategyApi.updateStrategy(app1.id, strat.id, + new UpdateApplicationRolloutStrategy().name("phred22") + .attributes([new RolloutStrategyAttribute().id("abcde") + .type(RolloutStrategyFieldType.BOOLEAN) + .values([false]) + .fieldName("jxtq") + .conditional(RolloutStrategyAttributeConditional.ENDS_WITH)]) + .percentage(10000), superuser, Opts.empty()) + then: + updated.name == "phred22" + updated.percentage == 10000 + } +} diff --git a/infra/api-bucket/files/releases.json b/infra/api-bucket/files/releases.json index 4077f618f..80c6baf76 100644 --- a/infra/api-bucket/files/releases.json +++ b/infra/api-bucket/files/releases.json @@ -1,5 +1,5 @@ { - "latest": "1.8.0", + "latest": "1.8.1", "versions": [ { @@ -26,6 +26,7 @@ { "version": "1.6.0" }, { "version": "1.7.0" }, { "version": "1.7.1" }, - { "version": "1.8.0" } + { "version": "1.8.0" }, + { "version": "1.8.1" } ] }