Doist / Doist/twist-cli

test: adopt cli-core buildTokenStore + matchAccount in auth/account tests

Open
#252 0 comments 1 reaction 1 assignee View on GitHub

@scottlovegrove is already working on this.

Since May 25, 2026.

enhancement
Dominant language
TypeScript
Stars
3
Forks
1
Avg merge
2h 4m
Merged PRs (30d)
14

Description

Background

cli-core#49 published shared test scaffolding via @doist/cli-core/testing. twist adopted the mechanical part — createTestProgram + captureConsole — in #251, but deliberately scoped out the stateful token-store fake (matching todoist-cli#361's scope).

This issue tracks the remaining, non-mechanical half.

What

Replace the hand-rolled interaction mocks in src/commands/account/account.test.ts (and where applicable src/commands/auth/auth.test.ts, src/lib/auth.test.ts) with cli-core's stateful fake:

  • buildTokenStore({ entries, matchAccount }) / buildSingleEntryStore(...) — returns a real in-memory TokenStore + spies + mutable state.entries.
  • Ingen account fixtures (alanGrant / ellieSattler / ianMalcolm) instead of hand-built account objects.

Today these tests hand-roll a storeMocks object of bare vi.fn()s and re-implement ref resolution inline (setDefault/clear via mockImplementation(async (ref) => …), account.test.ts:51-56). That logic can drift from production.

Why this is twist-specific

matchAccount was added to buildTokenStore in cli-core#49 specifically for twist — twist resolves refs by numeric id + case-insensitive label, not cli-core's default id/email/label. twist is the only conceivable caller of matchAccount in any repo (cli-core and todoist both use the default). If twist never adopts, matchAccount is a parameter no code anywhere passes — see the "delete it as YAGNI" alternative below.

Watch-out (don't regress)

Current tests assert the exact ref string reaching the store, e.g. expect(storeMocks.setDefault).toHaveBeenCalledWith('alan grant') (account.test.ts:233). That proves twist's command layer normalizes (lowercases) the ref before calling the store. A stateful fake + matchAccount can absorb that normalization — keep an explicit assertion that the command layer normalizes, so we test prod's matcher, not our mirror of it.

Decision fork

  • AdoptmatchAccount gets its first real caller; twist converges onto shared infra; bespoke inline resolution logic deleted.
  • Decline → flag back to cli-core to remove matchAccount as YAGNI (keep buildTokenStore; cli-core uses it internally).

Recommended: fold into the next PR that already touches account.test.ts/auth.test.ts rather than a dedicated rewrite.

Refs: Doist/cli-core#49, #251

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.