Add stateful and stateless enterprise selection
This commit is contained in:
1 parent
d383b3aad8
commit
0959cef1cc
22 files changed
+609
-187
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { CorpConfig } from "./types.js";
|
||||
import { CorpContext } from "./manager.js";
|
||||
import { CorpContext, resolveCorpConfig } from "./manager.js";
|
||||
|
||||
function corp(id: string, name = id): CorpConfig {
|
||||
return {
|
||||
@@ -26,7 +26,7 @@ function corp(id: string, name = id): CorpConfig {
|
||||
|
||||
describe("CorpContext", () => {
|
||||
test("refresh adds newly loaded corps", () => {
|
||||
const context = new CorpContext([corp("corp-a")]);
|
||||
const context = new CorpContext([corp("corp-a")], { stateful: true });
|
||||
|
||||
context.refresh([corp("corp-a"), corp("corp-b")]);
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("CorpContext", () => {
|
||||
});
|
||||
|
||||
test("refresh keeps the selected corp when it still exists", () => {
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")]);
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")], { stateful: true });
|
||||
expect(context.switchCorp("corp-b")).toBe(true);
|
||||
|
||||
context.refresh([corp("corp-a"), corp("corp-b", "Corp B updated")]);
|
||||
@@ -43,12 +43,51 @@ describe("CorpContext", () => {
|
||||
expect(context.getCurrent()?.name).toBe("Corp B updated");
|
||||
});
|
||||
|
||||
test("refresh falls back when the selected corp disappears", () => {
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")]);
|
||||
test("clears the default when the selected corp disappears", () => {
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")], { stateful: true });
|
||||
expect(context.switchCorp("corp-b")).toBe(true);
|
||||
|
||||
context.refresh([corp("corp-c")]);
|
||||
|
||||
expect(context.getCurrent()?.id).toBe("corp-c");
|
||||
expect(context.getCurrent()).toBeNull();
|
||||
});
|
||||
|
||||
test("does not keep a current corp in stateless mode", () => {
|
||||
const context = new CorpContext([corp("corp-a"), corp("corp-b")]);
|
||||
|
||||
expect(context.getCurrent()).toBeNull();
|
||||
expect(context.switchCorp("corp-b")).toBe(false);
|
||||
expect(context.resolve("corp-b")?.id).toBe("corp-b");
|
||||
});
|
||||
|
||||
test("uses the configured default corp in stateful mode", () => {
|
||||
const context = new CorpContext(
|
||||
[corp("corp-a"), corp("corp-b")],
|
||||
{ stateful: true, defaultCorpId: "corp-b" }
|
||||
);
|
||||
|
||||
expect(context.getCurrent()?.id).toBe("corp-b");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveCorpConfig", () => {
|
||||
test("requires an explicit corp in stateless mode", () => {
|
||||
expect(() => resolveCorpConfig([corp("corp-a")], { stateful: false })).toThrow(
|
||||
"Every enterprise command requires --corp <corpId>"
|
||||
);
|
||||
});
|
||||
|
||||
test("resolves an explicit corp in stateless mode", () => {
|
||||
expect(resolveCorpConfig(
|
||||
[corp("corp-a"), corp("corp-b")],
|
||||
{ stateful: false, corpId: "corp-b" }
|
||||
).id).toBe("corp-b");
|
||||
});
|
||||
|
||||
test("resolves the configured default corp in stateful mode", () => {
|
||||
expect(resolveCorpConfig(
|
||||
[corp("corp-a"), corp("corp-b")],
|
||||
{ stateful: true, defaultCorpId: "corp-b" }
|
||||
).id).toBe("corp-b");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user