Skip to content

Commit

Permalink
[OPIK-541] Allow empty string as project description (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisTkachenko authored Dec 5, 2024
1 parent d6237a2 commit c9b5cdf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public record Project(
Project.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) UUID id,
@JsonView({Project.View.Public.class, View.Write.class}) @NotBlank String name,
@JsonView({Project.View.Public.class,
View.Write.class}) @Pattern(regexp = NULL_OR_NOT_BLANK, message = "must not be blank") String description,
View.Write.class}) String description,
@JsonView({Project.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant createdAt,
@JsonView({Project.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) String createdBy,
@JsonView({Project.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant lastUpdatedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
public record ProjectUpdate(
// Not Blank makes the field required, while this pattern allows null values and validates the string if it is not null
@Pattern(regexp = NULL_OR_NOT_BLANK, message = "must not be blank") String name,
@Pattern(regexp = NULL_OR_NOT_BLANK, message = "must not be blank") String description) {
String description) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.clickhouse.ClickHouseContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.lifecycle.Startables;
Expand Down Expand Up @@ -1441,9 +1442,10 @@ void setUp() {
.build());
}

@Test
@ParameterizedTest
@ValueSource(strings = {"Simple Test 2", ""})
@DisplayName("Success")
void update() {
void update(String descriptionUpdate) {
String name = "Test Project: " + UUID.randomUUID();

try (var actualResponse = client.target(URL_TEMPLATE.formatted(baseURI))
Expand All @@ -1452,7 +1454,7 @@ void update() {
.header(HttpHeaders.AUTHORIZATION, API_KEY)
.header(WORKSPACE_HEADER, TEST_WORKSPACE)
.method(HttpMethod.PATCH,
Entity.json(ProjectUpdate.builder().name(name).description("Simple Test 2").build()))) {
Entity.json(ProjectUpdate.builder().name(name).description(descriptionUpdate).build()))) {

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(204);
assertThat(actualResponse.hasEntity()).isFalse();
Expand All @@ -1468,7 +1470,7 @@ void update() {
var actualEntity = actualResponse.readEntity(Project.class);

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(200);
assertThat(actualEntity.description()).isEqualTo("Simple Test 2");
assertThat(actualEntity.description()).isEqualTo(descriptionUpdate);
assertThat(actualEntity.name()).isEqualTo(name);
}
}
Expand Down Expand Up @@ -1554,24 +1556,6 @@ void update__whenNameIsNull__thenAcceptDescriptionUpdate() {
}
}

@Test
@DisplayName("when description is blank, then reject the update")
void update__whenDescriptionIsBlank__thenRejectTheUpdate() {

try (var actualResponse = client.target(URL_TEMPLATE.formatted(baseURI))
.path(projectId.toString())
.request()
.header(HttpHeaders.AUTHORIZATION, API_KEY)
.header(WORKSPACE_HEADER, TEST_WORKSPACE)
.method(HttpMethod.PATCH,
Entity.json(ProjectUpdate.builder().name("Test Project").description("").build()))) {

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(422);
assertThat(actualResponse.readEntity(ErrorMessage.class).errors())
.contains("description must not be blank");
}
}

@Test
@DisplayName("when name is blank, then reject the update")
void update__whenNameIsBlank__thenRejectTheUpdate() {
Expand Down

0 comments on commit c9b5cdf

Please sign in to comment.