Commit c1be4a63 authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'TEIS-3104-1' into 'develop'

TEIS-3104: fixes from demo: updated update feature flag method

Closes TEIS-3104

See merge request teis/admin-service!82
parents 9909a661 5c672b20
theGroup=ee.sm.ti.teis
theVersion=1.26.0
theVersion=1.27.0-SNAPSHOT
pluginVersion=1.5.0
commonsVersion=1.36.0
commonApiGatewayVersion=1.36.0
commonsVersion=1.37.0-SNAPSHOT
commonApiGatewayVersion=1.37.0-SNAPSHOT
......@@ -5,6 +5,7 @@ import ee.sm.ti.teis.commongateway.admin.UpdateFeatureFlagDto;
import ee.sm.ti.teis.commongateway.admin.UpdateFeatureFlagRequest;
import ee.sm.ti.teis.commongateway.admin.UpdateFeatureFlagResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.FeatureFlagId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,17 +14,18 @@ import javax.transaction.Transactional;
import java.util.List;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.FeatureFlagId.X_TEST_1;
import static ee.sm.ti.teis.types.enums.FeatureFlagId.X_TEST_2;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PARAMETERS;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_VIOLATION;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.org.apache.commons.lang.RandomStringUtils.random;
@Transactional
public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
private static final String FLAG_ID = "X-TEST-1";
private static final String FLAG_ID_2 = "X-TEST-2";
private static final FeatureFlagId FLAG_ID = X_TEST_1;
private static final FeatureFlagId FLAG_ID_2 = X_TEST_2;
@Autowired
FeatureFlagGwListener listener;
......@@ -47,7 +49,7 @@ public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID.getFlagId());
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isTrue();
}
......@@ -59,7 +61,7 @@ public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID.getFlagId());
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isFalse();
}
......@@ -71,7 +73,7 @@ public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2.getFlagId());
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag 2");
assertThat(response.getPayload().isEnabled()).isTrue();
}
......@@ -84,7 +86,7 @@ public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2.getFlagId());
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag 2");
assertThat(response.getPayload().isEnabled()).isFalse();
}
......@@ -99,23 +101,12 @@ public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().stream()
.anyMatch(violation -> violation.getFieldName().contains("update.dto.id")
&& violation.getCode().equals("NotBlank")))
&& violation.getCode().equals("NotNull")))
.isTrue();
}
@Test
void update_idNotExists_notFound() {
dto.setId(random(2, "abc"));
request.setPayload(dto, requestMetaDTO);
response = listener.update(request);
assertResponseNotFound(response.getError());
assertThat(response.getError().getMessage()).isEqualTo("Feature Flag not found.");
}
@Test
public void missingRequiredPrivilege_forbidden() {
void missingRequiredPrivilege_forbidden() {
requestMetaDTO.setPrivileges(List.of(TI_MANAGE_VIOLATION.name()));
request.setPayload(dto, requestMetaDTO);
......@@ -125,7 +116,7 @@ public class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
}
@Test
public void wrongUserType_forbidden() {
void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
request.setPayload(dto, requestMetaDTO);
......
......@@ -31,7 +31,7 @@ public class FeatureFlagBusinessService {
@Transactional
public FeatureFlagDto update(@Valid UpdateFeatureFlagDto dto) {
FeatureFlagEntity entity = dataService.getById(dto.getId());
FeatureFlagEntity entity = dataService.getById(dto.getId().getFlagId());
entity.setEnabled(dto.isEnabled());
entity = dataService.save(entity);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment