Removes Testing Profile/Account Creation
It was just too damn slow... 25+ seconds for *two*. Profile information will have to be partial-mocked using the sections and properties that the tested method will use, and casted as the parameter type (`IPmcData`, for example).
This commit is contained in:
parent
7bd8b9e994
commit
d85e649511
@ -3,23 +3,14 @@ import { container, DependencyContainer } from "tsyringe";
|
|||||||
|
|
||||||
// For the Vitest Custom Environment.
|
// For the Vitest Custom Environment.
|
||||||
import type { Environment } from "vitest";
|
import type { Environment } from "vitest";
|
||||||
import { populateGlobal } from "vitest/environments";
|
|
||||||
import { Container } from "@spt-aki/di/Container";
|
import { Container } from "@spt-aki/di/Container";
|
||||||
|
|
||||||
// Required for importing the database.
|
// Required for importing the database.
|
||||||
|
import path from "node:path";
|
||||||
import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
|
import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
|
||||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||||
import { ImporterUtil } from "@spt-aki/utils/ImporterUtil";
|
import { ImporterUtil } from "@spt-aki/utils/ImporterUtil";
|
||||||
|
|
||||||
// Required for creating a temporary test account/profile.
|
|
||||||
import path from "node:path";
|
|
||||||
import { SaveServer } from "@spt-aki/servers/SaveServer";
|
|
||||||
import { LauncherController } from "@spt-aki/controllers/LauncherController";
|
|
||||||
import { IRegisterData } from "@spt-aki/models/eft/launcher/IRegisterData";
|
|
||||||
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
|
||||||
import { ProfileController } from "@spt-aki/controllers/ProfileController";
|
|
||||||
import { IProfileCreateRequestData } from "@spt-aki/models/eft/profile/IProfileCreateRequestData";
|
|
||||||
|
|
||||||
export default <Environment> {
|
export default <Environment> {
|
||||||
name: "spt-aki-server",
|
name: "spt-aki-server",
|
||||||
transformMode: "ssr",
|
transformMode: "ssr",
|
||||||
@ -32,18 +23,9 @@ export default <Environment> {
|
|||||||
// Import the database.
|
// Import the database.
|
||||||
await importDatabase(container);
|
await importDatabase(container);
|
||||||
|
|
||||||
// Create a temporary test account/profile.
|
|
||||||
const sessionId = await createTestAccount();
|
|
||||||
|
|
||||||
// Populate the global scope with the session ID of the test account/profile.
|
|
||||||
populateGlobal(global, { sessionId: sessionId });
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async teardown()
|
async teardown()
|
||||||
{
|
{}
|
||||||
// Delete the temporary test account/profile.
|
|
||||||
await deleteTestAccount(sessionId);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -66,55 +48,3 @@ async function importDatabase(container: DependencyContainer): Promise<void>
|
|||||||
// Save the data to memory.
|
// Save the data to memory.
|
||||||
databaseServer.setTables(dataToImport);
|
databaseServer.setTables(dataToImport);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a temporary test account/profile for testing purposes. Is deleted after testing is completed. The account is
|
|
||||||
* created with a random username, and the profile is created with the same username.
|
|
||||||
*
|
|
||||||
* @returns The session id of the created profile.
|
|
||||||
*/
|
|
||||||
async function createTestAccount(): Promise<string>
|
|
||||||
{
|
|
||||||
const launcherController = container.resolve<LauncherController>("LauncherController");
|
|
||||||
const randomUtil = container.resolve<RandomUtil>("RandomUtil");
|
|
||||||
const profileController = container.resolve<ProfileController>("ProfileController");
|
|
||||||
|
|
||||||
const username = `DarkHelmet-Test-${randomUtil.randInt(999999)}`;
|
|
||||||
|
|
||||||
// Register a new account.
|
|
||||||
const registerData: IRegisterData = {
|
|
||||||
edition: "Standard",
|
|
||||||
username: username,
|
|
||||||
password: "12345" // Get it? Heh
|
|
||||||
};
|
|
||||||
const sessionId = launcherController.register(registerData);
|
|
||||||
|
|
||||||
// It *could* happen. I guess.
|
|
||||||
if (!sessionId)
|
|
||||||
{
|
|
||||||
throw new Error("Failed to register a test account. Account already exists with this random username. Crazy.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new profile for the account.
|
|
||||||
const profileCreateRequestData: IProfileCreateRequestData = {
|
|
||||||
side: "Usec",
|
|
||||||
nickname: username,
|
|
||||||
headId: "5cde96047d6c8b20b577f016",
|
|
||||||
voiceId: "5fc1223595572123ae7384a3"
|
|
||||||
};
|
|
||||||
profileController.createProfile(profileCreateRequestData, sessionId);
|
|
||||||
|
|
||||||
return sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the temporary test account/profile.
|
|
||||||
*
|
|
||||||
* @param $sessionId Session id of the profile to delete.
|
|
||||||
* @returns true when deleted, false when profile not found.
|
|
||||||
*/
|
|
||||||
async function deleteTestAccount($sessionId: string): Promise<boolean>
|
|
||||||
{
|
|
||||||
const saveServer = container.resolve<SaveServer>("SaveServer");
|
|
||||||
return saveServer.removeProfile($sessionId);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user