Skip to content

test: adopt cli-core buildTokenStore in auth tests #362

@scottlovegrove

Description

@scottlovegrove

Background

cli-core#49 published shared test scaffolding via @doist/cli-core/testing. todoist adopted the mechanical part — createTestProgram + the console/stream spies — in #361, but deliberately scoped out the stateful token-store fake:

Skipped buildTokenStore/account fixtures — todoist's auth tests are module-level vi.fn() interaction mocks, the wrong shape for cli-core's stateful store fake.

This issue tracks revisiting that.

What

Replace the hand-rolled interaction mocks in src/commands/auth/auth.test.ts (setMock/clearMock/activeMock/listMock bare vi.fn()s wired via createTodoistTokenStore: () => ({ active: activeMock, … }), auth.test.ts:6-19) with cli-core's stateful fake:

  • buildTokenStore({ entries }) / buildSingleEntryStore(...) — real in-memory TokenStore + spies + mutable state.entries.
  • Ingen account fixtures (alanGrant / ellieSattler / ianMalcolm).

todoist accounts resolve by id/email/label — cli-core's default matcher — so no matchAccount override is needed (unlike twist).

Note on the "wrong shape" reasoning

The skip rationale is somewhat circular: the stateful fake exists precisely to replace the interaction-mock shape. "Our tests are the wrong shape" really means "we haven't rewritten them yet." Worth a deliberate call rather than perpetual deferral.

Cost / benefit

  • Test-only refactor — no product behavior change.
  • Upside: deletes bespoke mock plumbing, shares fixtures, converges onto shared infra as the CLI family grows on cli-core auth.
  • Recommended: fold into the next PR that already touches the auth tests, rather than a dedicated rewrite.

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions