This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
69 lines (58 loc) · 2.3 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Run with: `yarn test`
// Executes all our major commands w/ some sample data
// duplicates lots of logic from bot.js...
// is there a javascripty way to fake `client.on(msg)`?
// or should we just refactor each handler to be their own functions?
// TODO should test against missing or malformed config items too
require("dotenv").config();
process.env.TEST = true;
process.env.CONFIG_PATH = "testConfig.json";
function testHeader(name) {
console.log(`\n******************** ${name} ********************\n`);
}
const tests = async () => {
const HeliumAPI = require('./helium-api');
const Bot = require('./bot');
const guildID = '123456789'; // FIXME
testHeader("help");
let output = Bot.formatHelp();
console.log(output);
testHeader("config");
output = Bot.formatConfig(guildID);
console.log(output);
testHeader("hotspot stats");
const hotspots = await HeliumAPI.getHotspotStats(guildID);
if(!hotspots || hotspots.length == 0){ throw("No hotspots configured") };
output = Bot.formatHotspotStats(hotspots);
console.log(output);
testHeader("validator stats");
const validators = await HeliumAPI.getValidatorStats(guildID);
if(!validators || validators.length == 0){ throw("No validators configured") };
output = Bot.formatValidatorStats(validators);
console.log(output);
const testHotspot = 'slow-burgundy-mandrill'; // the OG
testHeader(`hotspot activity ${testHotspot}`);
const activity = await HeliumAPI.getHotspotActivity(testHotspot);
if(!activity || activity.length == 0){ throw("No activity data") };
output = await Bot.formatHotspotActivity(activity);
console.log(output);
// test support for all possible hotspot names
testHeader('hotspot names => addresses');
const testNames = [
'11Kj6LV5M51PzPjBVbtgESL625SsrzdPoi59PDPQ2xdeozNuRuq',
'slow-burgundy-mandrill',
'slow burgundy mandrill',
' slow burgundy mandrill '
];
for(hotspot of testNames){
const address = await HeliumAPI.getAddressForHotspot(hotspot);
console.log(`${hotspot} => ${address}`);
if(address != testNames[0]) {
throw(`Expected ${hotspot} to resolve to ${testNames[0]}`);
}
}
};
// run everything
tests()
.then(() => { console.log("\n✅ Great success"); process.exit(0) })
.catch((e) => { console.log("\n❌ Errors! Test run failed. e => ", e); process.exit(1) });