mirror of
https://github.com/ancsemi/Haven.git
synced 2026-10-26 08:38:20 +00:00
Bot and webhook messages keep their name in the reply banner. Reply enrichment in channel history, live sends, threads and the webhook HTTP path now shares one helper that formats authors the same way message rendering does. Fixes #5564. Thanks to @delenda-delenda.
126 lines
2.8 KiB
JavaScript
126 lines
2.8 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Reply banner author formatting (#5564).
|
|
* Bot/webhook parents have user_id NULL; the name lives on webhook_username.
|
|
*/
|
|
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
|
|
const {
|
|
replyAuthorUsername,
|
|
toReplyContext,
|
|
} = require('../src/socketHandlers/helpers');
|
|
|
|
test('webhook bot uses [BOT] webhook_username', () => {
|
|
assert.equal(
|
|
replyAuthorUsername({
|
|
is_webhook: 1,
|
|
webhook_username: 'LOLbot',
|
|
username: '[Deleted User]',
|
|
}),
|
|
'[BOT] LOLbot'
|
|
);
|
|
});
|
|
|
|
test('webhook without a name falls back to [BOT] Bot', () => {
|
|
assert.equal(
|
|
replyAuthorUsername({ is_webhook: 1, webhook_username: null, username: null }),
|
|
'[BOT] Bot'
|
|
);
|
|
});
|
|
|
|
test('imported messages use webhook_username without the BOT prefix', () => {
|
|
assert.equal(
|
|
replyAuthorUsername({
|
|
is_webhook: 0,
|
|
imported_from: 'discord',
|
|
webhook_username: 'Alice',
|
|
username: '[Deleted User]',
|
|
}),
|
|
'Alice'
|
|
);
|
|
assert.equal(
|
|
replyAuthorUsername({
|
|
imported_from: 'discord',
|
|
webhook_username: null,
|
|
username: '[Deleted User]',
|
|
}),
|
|
'Unknown'
|
|
);
|
|
});
|
|
|
|
test('persona username wins over the real account name', () => {
|
|
assert.equal(
|
|
replyAuthorUsername({
|
|
persona_username: 'SecretSelf',
|
|
username: 'realuser',
|
|
}),
|
|
'SecretSelf'
|
|
);
|
|
});
|
|
|
|
test('regular users keep their COALESCE username', () => {
|
|
assert.equal(
|
|
replyAuthorUsername({ username: 'andrew', user_id: 3 }),
|
|
'andrew'
|
|
);
|
|
});
|
|
|
|
test('missing user row becomes [Deleted User]', () => {
|
|
assert.equal(replyAuthorUsername({ username: null, user_id: null }), '[Deleted User]');
|
|
assert.equal(replyAuthorUsername(null), '[Deleted User]');
|
|
});
|
|
|
|
test('webhook wins over persona and imported fields', () => {
|
|
// Webhook rows are a different message type; persona must not override.
|
|
assert.equal(
|
|
replyAuthorUsername({
|
|
is_webhook: 1,
|
|
webhook_username: 'LOLbot',
|
|
persona_username: 'ShouldNotWin',
|
|
imported_from: 'discord',
|
|
username: 'realuser',
|
|
}),
|
|
'[BOT] LOLbot'
|
|
);
|
|
});
|
|
|
|
test('toReplyContext maps a SQL row into the banner shape', () => {
|
|
assert.equal(toReplyContext(null), null);
|
|
assert.deepEqual(
|
|
toReplyContext({
|
|
id: 42,
|
|
content: 'ping',
|
|
user_id: null,
|
|
is_webhook: 1,
|
|
webhook_username: 'LOLbot',
|
|
username: '[Deleted User]',
|
|
}),
|
|
{
|
|
id: 42,
|
|
content: 'ping',
|
|
user_id: null,
|
|
username: '[BOT] LOLbot',
|
|
}
|
|
);
|
|
});
|
|
|
|
test('toReplyContext for a normal user keeps user_id and display name', () => {
|
|
assert.deepEqual(
|
|
toReplyContext({
|
|
id: 7,
|
|
content: 'hello',
|
|
user_id: 3,
|
|
is_webhook: 0,
|
|
username: 'andrew',
|
|
}),
|
|
{
|
|
id: 7,
|
|
content: 'hello',
|
|
user_id: 3,
|
|
username: 'andrew',
|
|
}
|
|
);
|
|
});
|