Kartenlinks für Jobs speichern und im Anruf-Popup öffnen

This commit is contained in:
Sven committed 2026-11-02 15:14:27 +01:00
1 parent 55e5d34e83
commit 7b3c187985
9 files changed
+150 -13

No files matched your search

@@ -34,6 +34,7 @@ import org.springframework.data.mongodb.core.mapping.Field;
* @param id Kennung des Fremdsystems, zugleich Schlüssel der Sammlung
* @param receivedAt Eingangszeit im Backend, beim letzten Eingang dieses Jobs
* @param url Sprungadresse des Fremdsystems zur Auftragsansicht
* @param mapUrl optionale Kartenadresse des Jobs ({@code map_url})
* @param state Zustand des Jobs im Fremdsystem
* @param ordertime Auftragszeit, z. B. "2026-08-13T13:35:27"
* @param orderdate Auftragsdatum, z. B. "2026-08-13"
@@ -53,6 +54,7 @@ public record JobEntry(
@Id long id,
Instant receivedAt,
String url,
@JsonProperty("map_url") @Field("map_url") String mapUrl,
Integer state,
String ordertime,
String orderdate,
@@ -142,7 +144,7 @@ public record JobEntry(
/** Füllt die Klasse aus der Webhook-Nutzlast und stempelt die Eingangszeit. */
public static JobEntry from(JsonNode json, ObjectMapper mapper, Instant receivedAt) {
JobEntry job = mapper.convertValue(json, JobEntry.class);
return new JobEntry(job.id(), receivedAt, job.url(), job.state(), job.ordertime(),
return new JobEntry(job.id(), receivedAt, job.url(), job.mapUrl(), job.state(), job.ordertime(),
job.orderdate(), job.modified(), job.finished(), job.vehicle(), job.service(),
job.canceled(), job.global(), job.customer(), job.courier(), job.tours());
}
@@ -35,12 +35,14 @@ class JobControllerTests {
void returnsStoredJob() throws Exception {
when(archive.job(21891263L)).thenReturn(new JobEntry(21891263L, null,
"https://test.sb.assecutor.de/admin/jb_detail.php?job_id=21891263",
"https://vhs.assecutor.org/?jb=21891263&cr=13385",
1, "2026-08-13T13:35:27", null, null, null, null, null, null, null, null, null, null));
mvc.perform(get("/api/jobs/21891263"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(21891263))
.andExpect(jsonPath("$.url").value("https://test.sb.assecutor.de/admin/jb_detail.php?job_id=21891263"));
.andExpect(jsonPath("$.url").value("https://test.sb.assecutor.de/admin/jb_detail.php?job_id=21891263"))
.andExpect(jsonPath("$.map_url").value("https://vhs.assecutor.org/?jb=21891263&cr=13385"));
}
@Test
@@ -7,7 +7,12 @@ import java.time.Instant;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import org.bson.Document;
import org.junit.jupiter.api.Test;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import de.appcreation.swyxweb.storage.JobEntry;
@@ -26,6 +31,7 @@ class JobEntryTests {
"type": "job",
"id": 21891263,
"url": "https://test.sb.assecutor.de/admin/jb_detail.php?job_id=21891263",
"map_url": "https://vhs.assecutor.org/?jb=21891263&cr=13385",
"state": 9,
"ordertime": "2026-08-13T13:35:27",
"orderdate": "2026-08-13",
@@ -68,6 +74,7 @@ class JobEntryTests {
assertThat(job.id()).isEqualTo(21891263L);
assertThat(job.receivedAt()).isEqualTo(receivedAt);
assertThat(job.url()).isEqualTo("https://test.sb.assecutor.de/admin/jb_detail.php?job_id=21891263");
assertThat(job.mapUrl()).isEqualTo("https://vhs.assecutor.org/?jb=21891263&cr=13385");
assertThat(job.state()).isEqualTo(9);
assertThat(job.ordertime()).isEqualTo("2026-08-13T13:35:27");
assertThat(job.orderdate()).isEqualTo("2026-08-13");
@@ -114,6 +121,45 @@ class JobEntryTests {
JobEntry job = JobEntry.from(json, mapper, Instant.parse("2026-08-28T10:00:00Z"));
assertThat(job.courier().phone()).isEqualTo("+4917xxxxxxx");
assertThat(job.mapUrl()).isNull();
assertThat(job.tours().getFirst().phone()).isEqualTo("+4942037010xx");
}
/** Prüft den echten MongoDB-Konverter, ohne eine externe Datenbank zu verändern. */
@Test
void storesAndReadsMapUrlUnderItsDatabaseFieldName() throws Exception {
MappingMongoConverter converter = mongoConverter();
JobEntry job = JobEntry.from(mapper.readTree(SAMPLE), mapper, Instant.parse("2026-08-28T10:00:00Z"));
Document document = new Document();
converter.write(job, document);
assertThat(document).containsEntry("_id", job.id())
.containsEntry("map_url", "https://vhs.assecutor.org/?jb=21891263&cr=13385")
.doesNotContainKey("mapUrl");
assertThat(converter.read(JobEntry.class, document)).isEqualTo(job);
}
@Test
void readsExistingDatabaseJobsWithoutMapUrl() throws Exception {
MappingMongoConverter converter = mongoConverter();
Document document = new Document("_id", 21891233L).append("state", 1);
JobEntry job = converter.read(JobEntry.class, document);
assertThat(job.id()).isEqualTo(21891233L);
assertThat(job.mapUrl()).isNull();
assertThat(converter.read(JobEntry.class, document.append("map_url", null)).mapUrl()).isNull();
}
private MappingMongoConverter mongoConverter() throws Exception {
MongoCustomConversions conversions = MongoCustomConversions.create(adapter -> {});
MongoMappingContext context = new MongoMappingContext();
context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
context.afterPropertiesSet();
MappingMongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, context);
converter.setCustomConversions(conversions);
converter.afterPropertiesSet();
return converter;
}
}
@@ -14,6 +14,8 @@ import de.appcreation.swyxweb.webhook.WebhookService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@@ -134,6 +136,21 @@ class WebhookControllerTests {
verify(archive).saveAddresses(argThat(entries -> entries.size() == 1));
}
@ParameterizedTest
@ValueSource(strings = {"/api/webhook", "/api/webhook/jobs"})
void passesMapUrlToJobStorage(String endpoint) throws Exception {
mvc.perform(post(endpoint)
.contentType(MediaType.APPLICATION_JSON)
.content("""
{"type":"job","id":21891233,
"map_url":"https://vhs.assecutor.org/?jb=21891233&cr=13385"}
"""))
.andExpect(status().isOk());
verify(archive).saveJob(argThat(job -> job.id() == 21891233L
&& "https://vhs.assecutor.org/?jb=21891233&cr=13385".equals(job.mapUrl())));
}
/** Ohne Token in der Konfiguration darf der Kopf fehlen. */
@Test
void tokenIsNotRequiredWhenUnset() throws Exception {