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

TEIS-3104: fixes from demo

parent c1be4a63
......@@ -5,7 +5,6 @@ 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;
......@@ -14,18 +13,17 @@ 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
class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
private static final FeatureFlagId FLAG_ID = X_TEST_1;
private static final FeatureFlagId FLAG_ID_2 = X_TEST_2;
private static final String FLAG_ID = "X-TEST-1";
private static final String FLAG_ID_2 = "X-TEST-2";
@Autowired
FeatureFlagGwListener listener;
......@@ -49,7 +47,7 @@ class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID.getFlagId());
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isTrue();
}
......@@ -61,7 +59,7 @@ class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID.getFlagId());
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag");
assertThat(response.getPayload().isEnabled()).isFalse();
}
......@@ -73,7 +71,7 @@ class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2.getFlagId());
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag 2");
assertThat(response.getPayload().isEnabled()).isTrue();
}
......@@ -86,7 +84,7 @@ class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
response = listener.update(request);
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2.getFlagId());
assertThat(response.getPayload().getId()).isEqualTo(FLAG_ID_2);
assertThat(response.getPayload().getDescription()).isEqualTo("Test Feature flag 2");
assertThat(response.getPayload().isEnabled()).isFalse();
}
......@@ -101,10 +99,21 @@ class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().stream()
.anyMatch(violation -> violation.getFieldName().contains("update.dto.id")
&& violation.getCode().equals("NotNull")))
&& violation.getCode().equals("NotBlank")))
.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
void missingRequiredPrivilege_forbidden() {
requestMetaDTO.setPrivileges(List.of(TI_MANAGE_VIOLATION.name()));
......
......@@ -31,7 +31,7 @@ public class FeatureFlagBusinessService {
@Transactional
public FeatureFlagDto update(@Valid UpdateFeatureFlagDto dto) {
FeatureFlagEntity entity = dataService.getById(dto.getId().getFlagId());
FeatureFlagEntity entity = dataService.getById(dto.getId());
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