feat: WhatsApp contract between mobile-api, the service and the counter

Shared DTOs on both sides with identical JSON keys, the service API
constants with the access convention (the service enforces company,
owner and admin), Snowflake ids as strings towards the portal, and the
counter's WhatsApp contact type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-02 11:03:56 +08:00
1 parent 3ac3e108ff
commit 6d63cc74d1
32 files changed
+332 -1

No files matched your search

@@ -0,0 +1,70 @@
package com.solvway.mobile.api.dto.whatsapp;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** The service and mobile-api sides must serialise to the same key sets. */
class DtoJsonTest {
// same shape as Spring Boot's default mapper: java.time as ISO strings
private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
private Set<String> keys(Object o) {
JsonNode n = mapper.valueToTree(o);
Set<String> k = new TreeSet<>();
n.fieldNames().forEachRemaining(k::add);
return k;
}
@Test
void conversationViewKeys() throws Exception {
LocalDateTime t = LocalDateTime.of(2026, 12, 1, 10, 0);
ConversationView v = new ConversationView("u", 1L, "27820000000", "Ann", 2L, "Lead Ann", 3L, "Bob", true, t, t, "hi", true, 4);
assertEquals(new TreeSet<>(List.of("uuid", "companyId", "contactWaId", "contactName", "leadUuid", "leadName", "ownerUserId",
"ownerName", "ownerManual", "lastInboundAt", "lastMessageAt", "lastMessagePreview", "windowOpen",
"unreadCount")), keys(v));
assertEquals("2026-12-01T10:00:00", mapper.valueToTree(v).get("lastInboundAt").asText());
assertEquals(v, mapper.readValue(mapper.writeValueAsString(v), ConversationView.class));
}
@Test
void snowflakeIdsAreWrittenAsStrings() throws Exception {
ConversationView v = new ConversationView("u", 1L, "w", "n", 1234567890123456789L, "l", null, null, false, null, null, null, false, 0);
assertEquals("1234567890123456789", mapper.valueToTree(v).get("leadUuid").asText());
assertEquals(true, mapper.valueToTree(v).get("leadUuid").isTextual());
assertEquals(true, mapper.valueToTree(new StartChatRequest(1L, 2L)).get("eventLeadUuid").isTextual());
assertEquals(1234567890123456789L, mapper.readValue("{\"leadUuid\":1234567890123456789}", ConversationView.class).leadUuid());
assertEquals(1L, mapper.readValue("{\"leadUuid\":\"1\"}", StartChatRequest.class).leadUuid());
}
@Test
void messageViewKeys() throws Exception {
LocalDateTime t = LocalDateTime.of(2026, 12, 1, 10, 0);
MessageView v = new MessageView("u", "in", "text", "hi", "tpl", "image/png", "a.png", new BigDecimal("1.5"),
new BigDecimal("2.5"), "Spot", "sent", "131047", "Re-engagement", 3L, t, t);
assertEquals(new TreeSet<>(List.of("uuid", "direction", "type", "body", "templateName", "mediaMime",
"mediaFilename", "locationLat", "locationLng", "locationName", "status", "errorCode", "errorTitle",
"sentByUserId", "createdAt", "statusAt")), keys(v));
assertEquals(v, mapper.readValue(mapper.writeValueAsString(v), MessageView.class));
}
@Test
void webhookIngestRequestKeys() throws Exception {
WebhookIngestRequest r = new WebhookIngestRequest(List.of("INS"), mapper.readTree("{\"entry\":[]}"));
assertEquals(new TreeSet<>(List.of("matchedCompanyCodes", "payload")), keys(r));
assertEquals(r, mapper.readValue(mapper.writeValueAsString(r), WebhookIngestRequest.class));
}
}