feat(appconfig): implement UpdateApplication (#7209)

* feat(appconfig): implement UpdateApplication

* fix: address AppConfig update review findings

* fix: incorporate AppConfig maintainer feedback

---------

Co-authored-by: Ovidiu (Ovi) <462561+ovidiubute@users.noreply.github.com>
This commit is contained in:
Ovidiu (Ovi)andOvidiu authored and GitHub committed 2026-11-02 07:41:06 -04:00
1 parent 42bc856258
commit 1b87483483
6 files changed
+155 -2

No files matched your search

@@ -1154,6 +1154,72 @@ class AppConfigIntegrationTest {
.body("values.promo._variants[0].name", equalTo("uk"));
}
@Test @Order(56)
void updateApplicationPreservesOmittedFields() {
String applicationId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"update-app\",\"Description\":\"original\"}")
.when().post("/applications")
.then().statusCode(201)
.extract().path("Id");
given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"updated-app\"}")
.when().patch("/applications/" + applicationId)
.then().statusCode(200)
.body("Id", equalTo(applicationId))
.body("Name", equalTo("updated-app"))
.body("Description", equalTo("original"));
given()
.contentType(ContentType.JSON)
.body("{\"Description\":\"updated\"}")
.when().patch("/applications/updated-app")
.then().statusCode(200)
.body("Id", equalTo(applicationId))
.body("Name", equalTo("updated-app"))
.body("Description", equalTo("updated"));
given()
.when().delete("/applications/" + applicationId)
.then().statusCode(204);
}
@Test @Order(57)
void updateApplicationRejectsNonStringFieldsWithoutChangingTheApplication() {
String applicationId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"validation-app\",\"Description\":\"original\"}")
.when().post("/applications")
.then().statusCode(201)
.extract().path("Id");
given()
.contentType(ContentType.JSON)
.body("{\"Name\":123}")
.when().patch("/applications/" + applicationId)
.then().statusCode(400)
.body("__type", equalTo("BadRequestException"));
given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"should-not-stick\",\"Description\":false}")
.when().patch("/applications/" + applicationId)
.then().statusCode(400)
.body("__type", equalTo("BadRequestException"));
given()
.when().get("/applications/" + applicationId)
.then().statusCode(200)
.body("Name", equalTo("validation-app"))
.body("Description", equalTo("original"));
given()
.when().delete("/applications/" + applicationId)
.then().statusCode(204);
}
/** Polls a new session on a feature flag profile with variants, deployed on first use. */
private static ValidatableResponse getLatestVariantFlagsAccepting(String accept) {
if (variantFlagsSessionBody == null) {
@@ -93,6 +93,8 @@ class AppConfigServiceTest {
Application application = new Application();
application.setId("app");
application.setName("orders");
application.setDescription("Order processing");
applicationStore.put("app", application);
when(applicationStore.get("app")).thenReturn(Optional.of(application));
Environment environment = new Environment();
@@ -107,6 +109,33 @@ class AppConfigServiceTest {
service = new AppConfigService(storageFactory, mock(EmulatorConfig.class));
}
@Test
void updateApplicationPreservesOmittedFields() {
Application updated = service.updateApplication("app", Map.of("Name", "orders-v2"));
assertEquals("orders-v2", updated.getName());
assertEquals("Order processing", updated.getDescription());
verify(applicationStore).put("app", updated);
}
@Test
void updateApplicationRejectsNonStringFieldsWithoutWriting() {
clearInvocations(applicationStore);
AwsException nameError = assertThrows(AwsException.class,
() -> service.updateApplication("app", Map.of("Name", 123)));
AwsException descriptionError = assertThrows(AwsException.class,
() -> service.updateApplication("app", Map.of("Name", "renamed", "Description", false)));
assertEquals("BadRequestException", nameError.getErrorCode());
assertEquals(400, nameError.getHttpStatus());
assertEquals("BadRequestException", descriptionError.getErrorCode());
assertEquals(400, descriptionError.getHttpStatus());
assertEquals("orders", service.getApplication("app").getName());
assertEquals("Order processing", service.getApplication("app").getDescription());
verify(applicationStore, never()).put(anyString(), any(Application.class));
}
@Test
void onlyHostedProfilesReceiveTheOmittedTypeDefault() {
assertEquals("AWS.Freeform", service.createConfigurationProfile("app",