Skip to content

Commit 393f609

Browse files
committed
Drop unnecessary type casts; add tests for persisted defaults
1 parent 51a1e32 commit 393f609

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/adapters/onboarding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ export const basecampOnboardingAdapter: ChannelOnboardingAdapter = {
379379
basecamp: {
380380
...section,
381381
enabled: true,
382-
dmPolicy: (section as any)?.dmPolicy ?? "pairing",
383-
engage: (section as any)?.engage ?? DEFAULT_ENGAGE,
382+
dmPolicy: section.dmPolicy ?? "pairing",
383+
engage: section.engage ?? DEFAULT_ENGAGE,
384384
...(channelOauth ? { oauth: channelOauth } : {}),
385385
accounts: {
386386
...accounts,

tests/onboarding.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,47 @@ describe("basecampOnboardingAdapter", () => {
306306
expect(account.oauthClientSecret).toBeUndefined();
307307
// Channel-level oauth should be set from prompted creds
308308
expect(result.cfg.channels.basecamp.oauth?.clientId).toBe("test-client-id");
309+
// Defaults persisted for fresh onboarding
310+
expect(result.cfg.channels.basecamp.dmPolicy).toBe("pairing");
311+
expect(result.cfg.channels.basecamp.engage).toEqual(["dm", "mention", "assignment", "checkin"]);
312+
});
313+
314+
it("re-running configure preserves existing dmPolicy and engage values", async () => {
315+
mockCliProfileListFull.mockRejectedValue(new Error("not installed"));
316+
mockResolveTokenFilePath.mockReturnValue("/tmp/tokens/default.json");
317+
mockInteractiveLogin.mockResolvedValue({
318+
accessToken: "tok",
319+
refreshToken: "ref",
320+
tokenType: "Bearer",
321+
});
322+
mockDiscoverIdentity.mockResolvedValue({
323+
identity: { id: 42, firstName: "Bot", lastName: "", emailAddress: "b@t.com" },
324+
accounts: [{ id: 100, name: "Co", product: "bc3" }],
325+
});
326+
327+
const prompter = createPrompter({
328+
selectAnswers: ["done"],
329+
});
330+
331+
const existingCfg = cfg({
332+
dmPolicy: "disabled",
333+
engage: ["dm"],
334+
oauth: { clientId: "aabbccdd00112233445566778899aabbccddeeff" },
335+
accounts: { default: { personId: "42", oauthTokenFile: "/tmp/tokens/default.json" } },
336+
});
337+
338+
const result = await basecampOnboardingAdapter.configure({
339+
cfg: existingCfg,
340+
runtime: {} as any,
341+
prompter,
342+
accountOverrides: {},
343+
shouldPromptAccountIds: false,
344+
forceAllowFrom: false,
345+
});
346+
347+
// Existing values must survive — not overwritten with defaults
348+
expect(result.cfg.channels.basecamp.dmPolicy).toBe("disabled");
349+
expect(result.cfg.channels.basecamp.engage).toEqual(["dm"]);
309350
});
310351

311352
it("uses existing channel-level OAuth clientId without prompting", async () => {

0 commit comments

Comments
 (0)