From 8db68a95cab4181a43a2cce5eaadd657cef84e62 Mon Sep 17 00:00:00 2001 From: liquidnya <7364785+liquidnya@users.noreply.github.com> Date: Thu, 16 Jun 2022 12:05:00 +0200 Subject: [PATCH 1/4] Change tests to write settings.json intead of mock Fix tests --- tests/chat-logs/chat-logs.test.js | 12 +++++------- tests/chat-logs/logs/add.test.log | 4 ++-- tests/chat-logs/logs/broadcaster-only.test.log | 2 +- tests/chat-logs/logs/current-level-persists.test.log | 2 +- tests/chat-logs/logs/custom-codes.test.log | 2 +- tests/chat-logs/logs/dismiss.test.log | 2 +- tests/chat-logs/logs/frozen-time.test.log | 2 +- tests/chat-logs/logs/invalid-level-code.test.log | 2 +- tests/chat-logs/logs/level-order-restart.test.log | 2 +- tests/chat-logs/logs/odds.test.log | 2 +- tests/chat-logs/logs/open-close-clear.test.log | 2 +- tests/chat-logs/logs/random.test.log | 2 +- tests/chat-logs/logs/remove.test.log | 2 +- tests/chat-logs/logs/username-argument-dip.test.log | 2 +- .../chat-logs/logs/username-argument-remove.test.log | 2 +- tests/chat-logs/logs/weight-crash.test.log | 2 +- tests/chat-logs/logs/weight-remove.test.log | 2 +- 17 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/chat-logs/chat-logs.test.js b/tests/chat-logs/chat-logs.test.js index 4a8f458..9bc016e 100644 --- a/tests/chat-logs/chat-logs.test.js +++ b/tests/chat-logs/chat-logs.test.js @@ -19,7 +19,7 @@ const defaultTestChatters = { }; const defaultTestSettings = { username: 'queso_queue_test_username', - password: '', + password: 'oauth:test', channel: 'queso_queue_test_channel', max_size: 50, level_timeout: 10, @@ -156,15 +156,13 @@ function requireIndex(mockFs = undefined, mockSettings = undefined, mockTime = u jest.mock('fs', () => mockFs); fs = require('fs'); - // setup settings mock - jest.mock('../../settings.js', () => { return {}; }); - - // import settings and replace them - settings = require('../../settings.js'); + // write settings.json file if (mockSettings === undefined) { mockSettings = defaultTestSettings; } - replaceSettings(settings, mockSettings); + mockFs.writeFileSync('./settings.json', JSON.stringify(mockSettings)); + // import settings + settings = require('../../settings.js'); // import libraries chatbot = require('../../chatbot.js'); diff --git a/tests/chat-logs/logs/add.test.log b/tests/chat-logs/logs/add.test.log index fcd6c11..76a7398 100644 --- a/tests/chat-logs/logs/add.test.log +++ b/tests/chat-logs/logs/add.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log @@ -38,7 +38,7 @@ chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"], [02:23:35] @^FurretWalkBot: !add invalid level code [02:23:36] @^helperblock: FurretWalkBot, that is an invalid level code. -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":1,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":1,"level_timeout":10,"level_selection":[],"message_cooldown":5} [02:24:35] ~%?liquidnya: !add NB0-1MD-SLG [02:24:35] @^helperblock: liquidnya, NB0-1MD-SLG has been added to the queue. diff --git a/tests/chat-logs/logs/broadcaster-only.test.log b/tests/chat-logs/logs/broadcaster-only.test.log index 0841ac8..7d92e0c 100644 --- a/tests/chat-logs/logs/broadcaster-only.test.log +++ b/tests/chat-logs/logs/broadcaster-only.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":["next", "random"],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":["next", "random"],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/current-level-persists.test.log b/tests/chat-logs/logs/current-level-persists.test.log index c495af0..0ddb905 100644 --- a/tests/chat-logs/logs/current-level-persists.test.log +++ b/tests/chat-logs/logs/current-level-persists.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/custom-codes.test.log b/tests/chat-logs/logs/custom-codes.test.log index 20e95ce..329377a 100644 --- a/tests/chat-logs/logs/custom-codes.test.log +++ b/tests/chat-logs/logs/custom-codes.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5,"custom_codes_enabled":true} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5,"custom_codes_enabled":true} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/dismiss.test.log b/tests/chat-logs/logs/dismiss.test.log index 98245b3..91ea524 100644 --- a/tests/chat-logs/logs/dismiss.test.log +++ b/tests/chat-logs/logs/dismiss.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":["next", "random"],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":["next", "random"],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/frozen-time.test.log b/tests/chat-logs/logs/frozen-time.test.log index 2426c06..7872170 100644 --- a/tests/chat-logs/logs/frozen-time.test.log +++ b/tests/chat-logs/logs/frozen-time.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/invalid-level-code.test.log b/tests/chat-logs/logs/invalid-level-code.test.log index 02f69a0..b4a5efe 100644 --- a/tests/chat-logs/logs/invalid-level-code.test.log +++ b/tests/chat-logs/logs/invalid-level-code.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/level-order-restart.test.log b/tests/chat-logs/logs/level-order-restart.test.log index 7242bff..8671cf4 100644 --- a/tests/chat-logs/logs/level-order-restart.test.log +++ b/tests/chat-logs/logs/level-order-restart.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":["next", "random"],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":["next", "random"],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/odds.test.log b/tests/chat-logs/logs/odds.test.log index a3fa044..18920ca 100644 --- a/tests/chat-logs/logs/odds.test.log +++ b/tests/chat-logs/logs/odds.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/open-close-clear.test.log b/tests/chat-logs/logs/open-close-clear.test.log index c2cd3d9..64ff4d8 100644 --- a/tests/chat-logs/logs/open-close-clear.test.log +++ b/tests/chat-logs/logs/open-close-clear.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/random.test.log b/tests/chat-logs/logs/random.test.log index 09b8cb7..9896c9b 100644 --- a/tests/chat-logs/logs/random.test.log +++ b/tests/chat-logs/logs/random.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/remove.test.log b/tests/chat-logs/logs/remove.test.log index c206e4a..434a0b2 100644 --- a/tests/chat-logs/logs/remove.test.log +++ b/tests/chat-logs/logs/remove.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/username-argument-dip.test.log b/tests/chat-logs/logs/username-argument-dip.test.log index 86875f4..5284e45 100644 --- a/tests/chat-logs/logs/username-argument-dip.test.log +++ b/tests/chat-logs/logs/username-argument-dip.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/username-argument-remove.test.log b/tests/chat-logs/logs/username-argument-remove.test.log index 6b1c3b5..1313492 100644 --- a/tests/chat-logs/logs/username-argument-remove.test.log +++ b/tests/chat-logs/logs/username-argument-remove.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/weight-crash.test.log b/tests/chat-logs/logs/weight-crash.test.log index 98b7109..eca45ec 100644 --- a/tests/chat-logs/logs/weight-crash.test.log +++ b/tests/chat-logs/logs/weight-crash.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log diff --git a/tests/chat-logs/logs/weight-remove.test.log b/tests/chat-logs/logs/weight-remove.test.log index 0851325..2ecb07e 100644 --- a/tests/chat-logs/logs/weight-remove.test.log +++ b/tests/chat-logs/logs/weight-remove.test.log @@ -1,5 +1,5 @@ # "username" will decide which of the messages are from the bot -settings {"username":"helperblock","password":"","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} +settings {"username":"helperblock","password":"oauth:test","channel":"liquidnya","max_size":50,"level_timeout":10,"level_selection":[],"message_cooldown":5} # chatters chatters {"_links":{},"chatter_count":4,"chatters":{"broadcaster":["liquidnya"],"vips":[],"moderators":["furretwalkbot","streamelements"],"staff":[],"admins":[],"global_mods":[],"viewers":["viewerlevels"]}} # chatty chat log From 9c3236c053b62fd19064f812083a6f77c4bd2cb6 Mon Sep 17 00:00:00 2001 From: liquidnya <7364785+liquidnya@users.noreply.github.com> Date: Thu, 16 Jun 2022 12:06:53 +0200 Subject: [PATCH 2/4] Add TODO comment --- tests/chat-logs/chat-logs.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/chat-logs/chat-logs.test.js b/tests/chat-logs/chat-logs.test.js index 9bc016e..a96b54c 100644 --- a/tests/chat-logs/chat-logs.test.js +++ b/tests/chat-logs/chat-logs.test.js @@ -320,6 +320,8 @@ for (const file of testFiles) { } else if (command == 'accuracy') { accuracy = parseInt(rest); } else if (command == 'settings') { + // TODO: ideally new settings would be written to settings.json + // and settings.js could be reloaded instead to validate settings replaceSettings(test.settings, JSON.parse(rest)); } else if (command == 'chatters') { setChatters(JSON.parse(rest)); From 3d689b7d4a32c5d27221143259b9dd6f3edb9d5f Mon Sep 17 00:00:00 2001 From: liquidnya <7364785+liquidnya@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:53:07 +0200 Subject: [PATCH 3/4] Make settings example clearer --- settings.example.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/settings.example.json b/settings.example.json index 0b066cb..cf3b483 100644 --- a/settings.example.json +++ b/settings.example.json @@ -1,7 +1,7 @@ { - "username": "coolguy (required)", - "channel": "coolguy (required)", - "password": "oauth supersecretplease(required)", + "username": "coolbot (required, lowercase username of the bot account)", + "channel": "coolstreamer (required, lowercase username of your chat)", + "password": "oauth supersecretplease (required)", "start_open": true, "enable_absolute_position": true, "custom_codes_enabled": true, From eea71eac8f4e84a8a3bf1fb54233c4f48c87d4cf Mon Sep 17 00:00:00 2001 From: liquidnya <7364785+liquidnya@users.noreply.github.com> Date: Thu, 16 Jun 2022 12:17:05 +0200 Subject: [PATCH 4/4] Add validation for channel --- settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.js b/settings.js index bd36d91..4e14cfd 100644 --- a/settings.js +++ b/settings.js @@ -31,7 +31,7 @@ const settings = JSON.parse( const settings_validations = { username: (name) => typeof name === "string", password: (pass) => typeof pass === "string" && pass.startsWith("oauth"), - channel: (channel) => typeof channel === "string", + channel: (channel) => typeof channel === "string" && /^[a-z0-9_]{3,}$/.test(channel), // channel needs to be a valid twitch username (this is used in the chatters URL in twitch.js) start_open: (open) => typeof open === "boolean", enable_absolute_position: (absolute_position) => typeof absolute_position === "boolean", custom_codes_enabled: cc => typeof cc === "boolean",