Changeset View
Changeset View
Standalone View
Standalone View
apps/ecash-herald/test/telegramTests.js
// Copyright (c) 2023 The Bitcoin developers | // Copyright (c) 2023 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
'use strict'; | 'use strict'; | ||||
const assert = require('assert'); | const assert = require('assert'); | ||||
const { | const { | ||||
prepareStringForTelegramHTML, | prepareStringForTelegramHTML, | ||||
splitOverflowTgMsg, | splitOverflowTgMsg, | ||||
sendBlockSummary, | sendBlockSummary, | ||||
} = require('../src/telegram'); | } = require('../src/telegram'); | ||||
const { telegramHtmlStrings } = require('./mocks/templates'); | const { telegramHtmlStrings } = require('./mocks/templates'); | ||||
const { | const { | ||||
overflowMsg, | overflowMsg, | ||||
overflowMsgSplit, | |||||
overflowMsgTwo, | overflowMsgTwo, | ||||
overflowMsgSplit, | |||||
overflowMsgSplitTwo, | overflowMsgSplitTwo, | ||||
overflowMsgSuccess, | overflowMsgSuccess, | ||||
nonOverflowMsg, | nonOverflowMsg, | ||||
nonOverflowMsgSuccess, | nonOverflowMsgSuccess, | ||||
} = require('./mocks/telegramMsgs'); | } = require('./mocks/telegramMsgs'); | ||||
const blocks = require('./mocks/blocks'); | const blocks = require('./mocks/blocks'); | ||||
const { MockTelegramBot, mockChannelId } = require('./mocks/telegramBotMock'); | const { MockTelegramBot, mockChannelId } = require('./mocks/telegramBotMock'); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | describe('ecash-herald telegram.js functions', function () { | ||||
}); | }); | ||||
it(`None of the prepared telegram messages exceed the character limit of 4096`, function () { | it(`None of the prepared telegram messages exceed the character limit of 4096`, function () { | ||||
const TG_MSG_MAX_LENGTH = 4096; | const TG_MSG_MAX_LENGTH = 4096; | ||||
for (let i = 0; i < blocks.length; i += 1) { | for (let i = 0; i < blocks.length; i += 1) { | ||||
const thisBlock = blocks[i]; | const thisBlock = blocks[i]; | ||||
const { blockSummaryTgMsgs } = thisBlock; | const { blockSummaryTgMsgs } = thisBlock; | ||||
for (let j = 0; j < blockSummaryTgMsgs.length; j += 1) { | for (let j = 0; j < blockSummaryTgMsgs.length; j += 1) { | ||||
console.log(blockSummaryTgMsgs[j].length); | |||||
assert.strictEqual( | assert.strictEqual( | ||||
blockSummaryTgMsgs[j].length <= TG_MSG_MAX_LENGTH, | blockSummaryTgMsgs[j].length <= TG_MSG_MAX_LENGTH, | ||||
true, | true, | ||||
`Message is too long: ${blockSummaryTgMsgs[j].length} > ${TG_MSG_MAX_LENGTH}`, | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
}); | }); |