- Old tests fixed

- Added a static Fixuture class for test mockups
This commit is contained in:
2026-08-28 16:52:59 +02:00
parent 310218663d
commit 1ee2a2fe7a
13 changed files with 161 additions and 306 deletions
+12 -45
View File
@@ -1,65 +1,32 @@
import type { UserInfo } from "@core/session_manager";
import { createInitialSessionState, getCurrentSession, login, logout } from "@core/session_manager";
import { createInitialShellState } from "@core/shell_state";
import { buildTestFS } from "@tests/helpers/filesystems_fixture";
import { depth7Tree } from "@tests/helpers/tree_fixture";
import { Fixture } from "@tests/helpers/state_fixture";
import { describe, expect, test } from "vitest";
const root: UserInfo = {
username: "root",
uid: 0,
gid: 0,
group: [0],
home: 0,
};
const testU: UserInfo = {
username: "test",
uid: 1,
gid: 1,
group: [1],
home: 1,
};
const fs = buildTestFS(depth7Tree);
const users = new Map();
users.set(0, root);
users.set(1, testU);
const state = createInitialShellState(fs, users, root);
const state = Fixture.State;
const passMap = new Map();
passMap.set(0, "123");
passMap.set(1, "321");
passMap.set(1000, "321");
test("createInitialSessionState - successfully creates a new session state", () => {
const state = createInitialSessionState(root);
const state = createInitialSessionState(Fixture.user);
expect(state.cwd).toEqual(root.home);
expect(state.pwd).toEqual(root.home);
expect(state.cwd).toEqual(Fixture.user.home);
expect(state.pwd).toEqual(Fixture.user.home);
expect(state.exitCode).toEqual(0);
expect(state.user).toBe(root);
expect(state.user).toBe(Fixture.user);
expect(Object.isFrozen(state)).toBe(true);
});
describe("login", () => {
test("it successfully starts a new session under the user test", () => {
const newState = login(state, "test", "321", passMap);
const newState = login(state, "user", "321", passMap);
const pop = getCurrentSession(newState);
expect(pop.user).toEqual(testU);
expect(pop.user).toEqual(Fixture.user2);
});
test("fails to start a new session. Cause: no password mapped to the uid", () => {
const nopass: UserInfo = {
username: "no pass",
uid: 2,
gid: 1,
group: [1],
home: 1,
};
users.set(2, nopass);
//TODO: Fix to expect the correct object;
expect(() => login(state, "no pass", "321", passMap)).toThrow();
});
@@ -77,14 +44,14 @@ describe("login", () => {
describe("logout", () => {
test("returns the state with the current user poped from the stack", () => {
const newState = login(state, "test", "321", passMap);
const newState = login(state, "user", "321", passMap);
const newPop = getCurrentSession(newState);
expect(newPop.user).toEqual(testU);
expect(newPop.user).toEqual(Fixture.user2);
const newNewState = logout(state);
const pop = getCurrentSession(newNewState);
expect(pop.user).toEqual(root);
expect(pop.user).toEqual(Fixture.user);
});
});