mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
MISC: Standardize behavior of connect CLI and Singularity API (#1933)
This commit is contained in:
@@ -8,6 +8,8 @@ import { SpecialServers } from "../../../src/Server/data/SpecialServers";
|
||||
import { Factions } from "../../../src/Faction/Factions";
|
||||
import { PlayerOwnedAugmentation } from "../../../src/Augmentation/PlayerOwnedAugmentation";
|
||||
import { getNS, initGameEnvironment, setupBasicTestingEnvironment } from "./Utilities";
|
||||
import { Terminal } from "../../../src/Terminal";
|
||||
import type { NSFull } from "../../../src/NetscriptFunctions";
|
||||
|
||||
function setNumBlackOpsComplete(value: number): void {
|
||||
if (!Player.bladeburner) {
|
||||
@@ -297,3 +299,62 @@ describe("purchaseAugmentation", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("connect", () => {
|
||||
beforeEach(() => {
|
||||
setupBasicTestingEnvironment();
|
||||
Player.sourceFiles.set(9, 3);
|
||||
prestigeSourceFile(true);
|
||||
Player.money = 1e100;
|
||||
});
|
||||
|
||||
describe("Success", () => {
|
||||
const expectConnectSuccessfully = (ns: NSFull, targetHostname: string) => {
|
||||
const currentServerBeforeConnecting = Player.getCurrentServer();
|
||||
expect(ns.singularity.connect(targetHostname)).toStrictEqual(true);
|
||||
expect(currentServerBeforeConnecting.isConnectedTo).toStrictEqual(false);
|
||||
|
||||
const currentServerAfterConnecting = Player.getCurrentServer();
|
||||
expect(currentServerAfterConnecting.hostname).toStrictEqual(targetHostname);
|
||||
expect(currentServerAfterConnecting.isConnectedTo).toStrictEqual(true);
|
||||
};
|
||||
test("Built-in adjacent server", () => {
|
||||
expectConnectSuccessfully(getNS(), "n00dles");
|
||||
});
|
||||
test("Home", () => {
|
||||
Terminal.connectToServer(SpecialServers.DaedalusServer);
|
||||
expectConnectSuccessfully(getNS(), "home");
|
||||
});
|
||||
test("Private server", () => {
|
||||
const ns = getNS();
|
||||
ns.purchaseServer("pserver-0", 8);
|
||||
Terminal.connectToServer(SpecialServers.DaedalusServer);
|
||||
expectConnectSuccessfully(ns, "pserver-0");
|
||||
});
|
||||
test("Hacknet server", () => {
|
||||
const ns = getNS();
|
||||
ns.hacknet.purchaseNode();
|
||||
Terminal.connectToServer(SpecialServers.DaedalusServer);
|
||||
expectConnectSuccessfully(ns, "hacknet-server-0");
|
||||
});
|
||||
test("Backdoored server", () => {
|
||||
const ns = getNS();
|
||||
Terminal.connectToServer(SpecialServers.DaedalusServer);
|
||||
GetServerOrThrow("n00dles").backdoorInstalled = true;
|
||||
expectConnectSuccessfully(ns, "n00dles");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Failure", () => {
|
||||
test("Non-existent server", () => {
|
||||
const ns = getNS();
|
||||
expect(() => ns.singularity.connect("abc")).toThrow();
|
||||
expect(Player.getCurrentServer().hostname).not.toStrictEqual("abc");
|
||||
});
|
||||
test("Non-adjacent server", () => {
|
||||
const ns = getNS();
|
||||
expect(ns.singularity.connect(SpecialServers.DaedalusServer)).toStrictEqual(false);
|
||||
expect(Player.getCurrentServer().hostname).not.toStrictEqual(SpecialServers.DaedalusServer);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user