forked from PluralFlux/PluralFlux
edited bot to have top level main function
This commit is contained in:
11
src/bot.js
11
src/bot.js
@@ -82,7 +82,7 @@ function printGuilds() {
|
|||||||
const debouncePrintGuilds = utils.debounce(printGuilds, 2000);
|
const debouncePrintGuilds = utils.debounce(printGuilds, 2000);
|
||||||
export const debounceLogin = utils.debounce(client.login, 60000);
|
export const debounceLogin = utils.debounce(client.login, 60000);
|
||||||
|
|
||||||
(async () => {
|
export const login = async function() {
|
||||||
try {
|
try {
|
||||||
await client.login(token);
|
await client.login(token);
|
||||||
// await db.check_connection();
|
// await db.check_connection();
|
||||||
@@ -90,4 +90,11 @@ export const debounceLogin = utils.debounce(client.login, 60000);
|
|||||||
console.error('Login failed:', err);
|
console.error('Login failed:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
function main()
|
||||||
|
{
|
||||||
|
login();
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
@@ -65,6 +65,7 @@ const {webhookHelper} = require("../src/helpers/webhookHelper.js");
|
|||||||
|
|
||||||
const {utils} = require("../src/helpers/utils.js");
|
const {utils} = require("../src/helpers/utils.js");
|
||||||
let {handleMessageCreate, client} = require("../src/bot.js");
|
let {handleMessageCreate, client} = require("../src/bot.js");
|
||||||
|
const {login} = require("../src/bot");
|
||||||
|
|
||||||
describe('bot', () => {
|
describe('bot', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -290,9 +291,11 @@ describe('bot', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('calls client.login with correct argument', () => {
|
test('login calls client.login with correct argument', async() => {
|
||||||
// Act
|
// Arrange
|
||||||
client.login = jest.fn().mockResolvedValue();
|
client.login = jest.fn().mockResolvedValue();
|
||||||
|
// Act
|
||||||
|
await login();
|
||||||
// Assert
|
// Assert
|
||||||
expect(client.login).toHaveBeenCalledTimes(1);
|
expect(client.login).toHaveBeenCalledTimes(1);
|
||||||
expect(client.login).toHaveBeenCalledWith(process.env.FLUXER_BOT_TOKEN)
|
expect(client.login).toHaveBeenCalledWith(process.env.FLUXER_BOT_TOKEN)
|
||||||
|
|||||||
Reference in New Issue
Block a user