From c9b5cdfbe94ab915cd1d5bc4c5eb5fb491729670 Mon Sep 17 00:00:00 2001 From: BorisTkachenko <35521895+BorisTkachenko@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:53:18 +0100 Subject: [PATCH] [OPIK-541] Allow empty string as project description (#825) --- .../main/java/com/comet/opik/api/Project.java | 2 +- .../com/comet/opik/api/ProjectUpdate.java | 2 +- .../v1/priv/ProjectsResourceTest.java | 28 ++++--------------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/apps/opik-backend/src/main/java/com/comet/opik/api/Project.java b/apps/opik-backend/src/main/java/com/comet/opik/api/Project.java index 386f27e14f..4cb407a237 100644 --- a/apps/opik-backend/src/main/java/com/comet/opik/api/Project.java +++ b/apps/opik-backend/src/main/java/com/comet/opik/api/Project.java @@ -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, diff --git a/apps/opik-backend/src/main/java/com/comet/opik/api/ProjectUpdate.java b/apps/opik-backend/src/main/java/com/comet/opik/api/ProjectUpdate.java index a95f073431..26932918ec 100644 --- a/apps/opik-backend/src/main/java/com/comet/opik/api/ProjectUpdate.java +++ b/apps/opik-backend/src/main/java/com/comet/opik/api/ProjectUpdate.java @@ -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) { } diff --git a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectsResourceTest.java b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectsResourceTest.java index b02305a307..4f7a444a45 100644 --- a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectsResourceTest.java +++ b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectsResourceTest.java @@ -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; @@ -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)) @@ -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(); @@ -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); } } @@ -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() {