2021-12-19 10:42:16 +01:00
|
|
|
/* eslint-disable no-await-in-loop */
|
2021-12-19 21:42:40 +01:00
|
|
|
|
2022-01-25 22:24:09 +01:00
|
|
|
import { Player } from "../../../src/Player";
|
|
|
|
import { determineAllPossibilitiesForTabCompletion } from "../../../src/Terminal/determineAllPossibilitiesForTabCompletion";
|
|
|
|
import { Server } from "../../../src/Server/Server";
|
|
|
|
import { AddToAllServers, prestigeAllServers } from "../../../src/Server/AllServers";
|
2022-11-20 18:07:22 +01:00
|
|
|
import { LocationName } from "../../../src/utils/enums";
|
2022-01-25 22:24:09 +01:00
|
|
|
import { CodingContract } from "../../../src/CodingContracts";
|
2022-10-01 21:03:47 +02:00
|
|
|
import { initDarkWebItems } from "../../../src/DarkWeb/DarkWebItems";
|
2021-12-19 10:42:16 +01:00
|
|
|
|
2021-08-27 05:22:24 +02:00
|
|
|
describe("determineAllPossibilitiesForTabCompletion", function () {
|
2021-09-05 01:09:30 +02:00
|
|
|
let closeServer: Server;
|
|
|
|
let farServer: Server;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
prestigeAllServers();
|
2022-10-01 21:03:47 +02:00
|
|
|
initDarkWebItems();
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.init();
|
|
|
|
|
|
|
|
closeServer = new Server({
|
|
|
|
ip: "8.8.8.8",
|
|
|
|
hostname: "near",
|
|
|
|
hackDifficulty: 1,
|
|
|
|
moneyAvailable: 70000,
|
|
|
|
numOpenPortsRequired: 0,
|
|
|
|
organizationName: LocationName.NewTokyoNoodleBar,
|
|
|
|
requiredHackingSkill: 1,
|
|
|
|
serverGrowth: 3000,
|
2021-08-27 05:22:24 +02:00
|
|
|
});
|
2021-09-05 01:09:30 +02:00
|
|
|
farServer = new Server({
|
|
|
|
ip: "4.4.4.4",
|
|
|
|
hostname: "far",
|
|
|
|
hackDifficulty: 1,
|
|
|
|
moneyAvailable: 70000,
|
|
|
|
numOpenPortsRequired: 0,
|
2022-10-01 21:03:47 +02:00
|
|
|
organizationName: LocationName.Sector12JoesGuns,
|
2021-09-05 01:09:30 +02:00
|
|
|
requiredHackingSkill: 1,
|
|
|
|
serverGrowth: 3000,
|
2021-08-27 05:22:24 +02:00
|
|
|
});
|
2022-04-12 20:06:24 +02:00
|
|
|
Player.getHomeComputer().serversOnNetwork.push(closeServer.hostname);
|
|
|
|
closeServer.serversOnNetwork.push(Player.getHomeComputer().hostname);
|
|
|
|
closeServer.serversOnNetwork.push(farServer.hostname);
|
|
|
|
farServer.serversOnNetwork.push(closeServer.hostname);
|
2021-09-05 01:09:30 +02:00
|
|
|
AddToAllServers(closeServer);
|
|
|
|
AddToAllServers(farServer);
|
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the connect command", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("connect ", 0);
|
2021-12-19 10:42:16 +01:00
|
|
|
expect(options).toEqual(["near"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the buy command", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("buy ", 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options.sort()).toEqual(
|
|
|
|
[
|
|
|
|
"BruteSSH.exe",
|
|
|
|
"FTPCrack.exe",
|
|
|
|
"relaySMTP.exe",
|
|
|
|
"HTTPWorm.exe",
|
|
|
|
"SQLInject.exe",
|
|
|
|
"DeepscanV1.exe",
|
|
|
|
"DeepscanV2.exe",
|
|
|
|
"AutoLink.exe",
|
|
|
|
"ServerProfiler.exe",
|
|
|
|
"Formulas.exe",
|
|
|
|
].sort(),
|
|
|
|
);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the scp command", async () => {
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
|
|
|
|
Player.getHomeComputer().messages.push("af.lit");
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
|
|
|
const options1 = await determineAllPossibilitiesForTabCompletion("scp ", 0);
|
2021-12-19 10:42:16 +01:00
|
|
|
expect(options1).toEqual(["/www/script.js", "af.lit", "note.txt", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2022-10-01 21:03:47 +02:00
|
|
|
const options2 = await determineAllPossibilitiesForTabCompletion("scp note.txt ", 1);
|
2021-12-19 10:42:16 +01:00
|
|
|
expect(options2).toEqual(["home", "near", "far"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the kill, tail, mem, and check commands", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
2021-09-05 01:09:30 +02:00
|
|
|
for (const command of ["kill", "tail", "mem", "check"]) {
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion(`${command} `, 0);
|
2021-12-19 10:42:16 +01:00
|
|
|
expect(options).toEqual(["/www/script.js", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the nano commands", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("nano ", 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options).toEqual(["/www/script.js", "note.txt", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the rm command", async () => {
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
|
2021-10-14 08:07:05 +02:00
|
|
|
Player.getHomeComputer().messages.push("asl.msg");
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().messages.push("af.lit");
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("rm ", 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options).toEqual(["/www/script.js", "NUKE.exe", "af.lit", "note.txt", "linklist.cct", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the run command", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct"));
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("run ", 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options).toEqual(["/www/script.js", "NUKE.exe", "linklist.cct", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the cat command", async () => {
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark");
|
2021-10-14 08:07:05 +02:00
|
|
|
Player.getHomeComputer().messages.push("asl.msg");
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().messages.push("af.lit");
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("cat ", 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options).toEqual(["asl.msg", "af.lit", "/www/note.txt", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the download and mv commands", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark");
|
|
|
|
for (const command of ["download", "mv"]) {
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion(`${command} `, 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options).toEqual(["/www/script.js", "note.txt", "www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the cd command", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("cd ", 0);
|
2021-12-19 10:42:16 +01:00
|
|
|
expect(options).toEqual(["www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes the ls and cd commands", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
2021-09-05 01:09:30 +02:00
|
|
|
for (const command of ["ls", "cd"]) {
|
2022-10-01 21:03:47 +02:00
|
|
|
const options = await determineAllPossibilitiesForTabCompletion(`${command} `, 0);
|
2021-12-19 10:42:16 +01:00
|
|
|
expect(options).toEqual(["www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-19 10:42:16 +01:00
|
|
|
it("completes commands starting with ./", async () => {
|
2022-10-01 21:03:47 +02:00
|
|
|
Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark");
|
|
|
|
const options = await determineAllPossibilitiesForTabCompletion("run ./", 0);
|
2022-01-05 01:09:34 +01:00
|
|
|
expect(options).toEqual([".//www/script.js", "NUKE.exe", "./www/"]);
|
2021-09-05 01:09:30 +02:00
|
|
|
});
|
2021-08-27 05:22:24 +02:00
|
|
|
});
|