fix(email): ignore recipient headers in entity suggestions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
import { selectCandidates, validateSuggestions, type EntityCandidate } from "../src/modules/email/email.entity-suggestions"
|
||||
import { buildSuggestionMail, selectCandidates, validateSuggestions, type EntityCandidate } from "../src/modules/email/email.entity-suggestions"
|
||||
|
||||
const customer: EntityCandidate = { entityType: "customers", entityId: 1, entityName: "Muster GmbH", entityTypeLabel: "Kunde", email: "kontakt@muster.de" }
|
||||
const project: EntityCandidate = { entityType: "projects", entityId: 1, entityName: "Umbau", entityTypeLabel: "Projekt", number: "P-2026-123" }
|
||||
@@ -35,3 +35,22 @@ test("does not treat a partial address as an exact match", () => {
|
||||
const exact = { ...customer, entityId: 2, email: "abc-kontakt@muster.de" }
|
||||
assert.equal(selectCandidates([customer, exact], "abc-kontakt@muster.de")[0], exact)
|
||||
})
|
||||
|
||||
|
||||
test("recipient and CC headers neither reach the model nor affect candidate ranking", () => {
|
||||
const ownCustomer = { ...customer, entityId: 999, entityName: "Mailbox Owner", email: "owner@example.org" }
|
||||
const message = { subject: "Anfrage P-2026-123", from: [{ address: "kontakt@muster.de" }], body: { text: "Bitte Angebot erstellen." } }
|
||||
const withoutRecipients = buildSuggestionMail(message)
|
||||
const withRecipients = buildSuggestionMail({ ...message,
|
||||
to: [{ name: ownCustomer.entityName, address: ownCustomer.email }],
|
||||
cc: [{ name: "Muster GmbH", address: "cc@example.org" }],
|
||||
})
|
||||
assert.deepEqual(withRecipients, withoutRecipients)
|
||||
assert.equal("to" in withRecipients, false)
|
||||
assert.equal("cc" in withRecipients, false)
|
||||
const candidates = [ownCustomer, customer, project]
|
||||
const ranked = selectCandidates(candidates, JSON.stringify(withRecipients))
|
||||
assert.deepEqual(ranked, selectCandidates(candidates, JSON.stringify(withoutRecipients)))
|
||||
assert.equal(ranked[0], customer)
|
||||
assert.equal(ranked[1], project)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user