fix(whatsapp): preserve history across reauthorization
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
isWeakWhatsAppDisplayName,
|
||||
reusableWhatsAppConversations,
|
||||
whatsappCustomerStableId,
|
||||
} from '../src/whatsapp-identity.js'
|
||||
|
||||
test('WhatsApp customer id remains stable after gateway reauthorization', () => {
|
||||
assert.equal(
|
||||
whatsappCustomerStableId('15551234567@s.whatsapp.net'),
|
||||
whatsappCustomerStableId('15551234567@s.whatsapp.net'),
|
||||
)
|
||||
assert.match(whatsappCustomerStableId('15551234567@s.whatsapp.net'), /^wa-customer-[a-f0-9]{24}$/)
|
||||
})
|
||||
|
||||
test('the latest inactive conversation is reused while another active account stays isolated', () => {
|
||||
const jid = '15551234567@s.whatsapp.net'
|
||||
const conversations = [
|
||||
{ id: 'old:newest', channel: 'whatsapp', channelId: 'old', whatsappJid: jid, customerId: 'abigail', lastMessage: { createdAt: '2026-07-31T07:51:37.000Z' } },
|
||||
{ id: 'older:history', channel: 'whatsapp', channelId: 'older', whatsappJid: jid, customerId: 'legacy', lastMessage: { createdAt: '2026-07-29T17:25:42.000Z' } },
|
||||
{ id: 'other:active', channel: 'whatsapp', channelId: 'other', whatsappJid: jid, customerId: 'other-account', lastMessage: { createdAt: '2026-08-01T00:00:00.000Z' } },
|
||||
]
|
||||
const result = reusableWhatsAppConversations(conversations, new Set(['current', 'other']), 'current', jid)
|
||||
assert.deepEqual(result.map((item) => item.customerId), ['abigail', 'legacy'])
|
||||
})
|
||||
|
||||
test('a saved contact name is not replaced by a phone-number fallback', () => {
|
||||
const jid = '15551234567@s.whatsapp.net'
|
||||
assert.equal(isWeakWhatsAppDisplayName('Abigail', jid), false)
|
||||
assert.equal(isWeakWhatsAppDisplayName('+1 555 123 4567', jid), true)
|
||||
})
|
||||
Reference in New Issue
Block a user