From 607ee17a8605774ef40cdd55e003832c68e309ff Mon Sep 17 00:00:00 2001 From: devlikepro Date: Mon, 20 Jan 2025 08:27:49 +0700 Subject: [PATCH] [core] perf tests --- tests/perf/send.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/perf/send.js diff --git a/tests/perf/send.js b/tests/perf/send.js new file mode 100644 index 00000000..83d62604 --- /dev/null +++ b/tests/perf/send.js @@ -0,0 +1,59 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const axios = require('axios'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const yargs = require('yargs/yargs'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { hideBin } = require('yargs/helpers'); + +// Parse CLI arguments +const argv = yargs(hideBin(process.argv)) + .option('number', { + alias: 'n', + type: 'number', + description: 'Number of messages to send', + default: 10, + }) + .option('chat-id', { + alias: 'to', + type: 'number', + description: 'Chat ID to send messages to', + demandOption: true, + }) + .option('session', { + type: 'string', + description: 'Session ID to use', + demandOption: true, + }) + .option('api-key', { + alias: 'k', + type: 'string', + description: 'API key for authentication', + demandOption: true, + }) + .help().argv; + +const sendTextMessage = async (session, numMessages, chatId, apiKey) => { + const url = 'http://localhost:3000/api/sendText/'; + for (let i = 1; i <= numMessages; i++) { + console.log(`Sending message ${i}`); + const response = await axios.post( + url, + { + chatId: chatId.toString(), + session: session, + text: `Message - ${i}`, + }, + { + headers: { + Accept: 'application/json', + 'X-Api-Key': apiKey, + 'Content-Type': 'application/json', + }, + }, + ); + console.log(`Message ${i} sent successfully:`, response.data); + } +}; + +// Run the script +sendTextMessage(argv.session, argv.number, argv['chat-id'], argv['api-key']);