From c8b985369fdd67e8d121cbe886599cf8fa0457b0 Mon Sep 17 00:00:00 2001 From: James Maes Date: Fri, 25 Sep 2026 20:44:51 -0500 Subject: [PATCH] test: assert webhook post body keeps null-valued fields Guards the toJsonCustomized migration so receivers still see null fields. Part of QRun-IO/qqq-all#1 --- ...bhookEventTypeCustomizerInterfaceTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/test/java/com/kingsrook/qbits/webhooks/actions/WebhookEventTypeCustomizerInterfaceTest.java diff --git a/src/test/java/com/kingsrook/qbits/webhooks/actions/WebhookEventTypeCustomizerInterfaceTest.java b/src/test/java/com/kingsrook/qbits/webhooks/actions/WebhookEventTypeCustomizerInterfaceTest.java new file mode 100644 index 0000000..5ff98c6 --- /dev/null +++ b/src/test/java/com/kingsrook/qbits/webhooks/actions/WebhookEventTypeCustomizerInterfaceTest.java @@ -0,0 +1,66 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2025. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qbits.webhooks.actions; + + +import com.kingsrook.qbits.webhooks.BaseTest; +import com.kingsrook.qbits.webhooks.WebhooksTestApplication; +import com.kingsrook.qbits.webhooks.model.WebhookEventContent; +import com.kingsrook.qqq.backend.core.exceptions.QException; +import com.kingsrook.qqq.backend.core.model.data.QRecord; +import org.json.JSONObject; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +/******************************************************************************* + ** Unit test for WebhookEventTypeCustomizerInterface + *******************************************************************************/ +class WebhookEventTypeCustomizerInterfaceTest extends BaseTest +{ + + /******************************************************************************* + ** the post body sent to receivers must keep fields whose value is null, so a + ** receiver can tell "field is null" from "field not in this api version". + *******************************************************************************/ + @Test + void testBuildEventContentKeepsNullValues() throws QException + { + String eventTypeName = "personAdHoc"; + registerAdHocEventType(eventTypeName); + + QRecord person = new QRecord() + .withTableName(WebhooksTestApplication.TABLE_NAME_PERSON) + .withValue("id", 1) + .withValue("firstName", "Jean Luc"); + + WebhookEventContent content = new DefaultWebhookEventTypeCustomizer() + .buildEventContent(person, eventTypeName, WebhooksTestApplication.API_NAME, WebhooksTestApplication.API_V1); + + JSONObject record = new JSONObject(content.getPostBody()).getJSONObject("record"); + assertEquals("Jean Luc", record.getString("firstName")); + assertTrue(record.has("lastName"), "null-valued field should be present in the post body"); + assertTrue(record.isNull("lastName")); + } + +}