Skip to content

test(infrastructure): add unit tests for background services and handlers - #125

Merged
Exotic209093 merged 1 commit into
mainfrom
worktree-wf_e4b0f9de-5d7-8
Sep 9, 2026
Merged

Exotic209093 merged 1 commit into
mainfrom
worktree-wf_e4b0f9de-5d7-8

Conversation

@Exotic209093

Copy link
Copy Markdown
Owner

Summary

Addresses #40, #105 - test-infrastructure

  • Add tests for background auth handlers
  • Add tests for background services lifecycle
  • Add tests for background storage handlers
  • Improve test coverage for extension background layer

🤖 Generated with Claude Code

…lers

Addresses #40, #105 - test-infrastructure

- Add tests for background auth handlers
- Add tests for background services lifecycle
- Add tests for background storage handlers
- Improve test coverage for extension background layer

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T15:44:16.514063Z 0d49fd5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d49fd5565

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Import background module to register handlers on the MessageBus.
// The module creates singleton service instances and registers all
// messageBus.on() handlers at import time.
import '../../src/background/index';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stub worker-only Chrome APIs before importing the worker

Importing the full background module during Jest evaluation immediately executes chrome.commands.onCommand.addListener and later chrome.alarms.onAlarm.addListener, but tests/mocks/chromeMock.ts defines neither commands nor alarms. Consequently this suite, and the storage-handler suite with the same import, aborts before any test runs with an undefined-property error; extend the Chrome mock or isolate the handler registration from service-worker startup.

Useful? React with 👍 / 👎.

Comment on lines +49 to +51
const listeners = (chrome.runtime.onMessage.addListener as jest.Mock).mock.calls;
// The last registered listener is the background handler (singleton MessageBus).
const listener = listeners[listeners.length - 1]?.[0];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Select the MessageBus listener instead of the last listener

Even after the missing Chrome APIs are stubbed, the last runtime.onMessage listener registered by src/background/index.ts is the raw scheduler-control listener at line 2452, not the MessageBus listener created near startup. Every auth message passed here therefore returns false and is converted to NOT_HANDLED; the duplicated helper in background-storage-handlers.test.ts has the same problem. Capture the MessageBus listener explicitly rather than relying on registration order.

Useful? React with 👍 / 👎.

Comment on lines +131 to +132
const storedOrg = await storage.getOrg(mockOrg.orgId);
expect(storedOrg).toBeUndefined();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Expect the storage service's null sentinel

When the logout handler successfully removes this org, StorageService.getOrg() returns null for a missing entry (orgs[orgId] ?? null), not undefined. Thus this assertion fails in the exact successful-logout scenario the test is intended to verify; assert null or use a nullish matcher.

Useful? React with 👍 / 👎.

Comment on lines +189 to +192
(chrome.tabs.query as jest.Mock).mockImplementation(
(_queryInfo: unknown, callback: (tabs: unknown[]) => void) => {
callback([]);
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return a promise from the tabs.query mock

SalesforceAuth.getActiveSalesforceTab() calls the promise form await chrome.tabs.query(queryInfo) without a callback, so this mock invokes undefined as a function and auth.login() rejects with a TypeError rather than the expected AuthError. Use mockResolvedValue([]) (or otherwise support the promise overload) so the test reaches the no-Salesforce-tab branch.

Useful? React with 👍 / 👎.

@Exotic209093
Exotic209093 merged commit e6a396b into main Sep 9, 2026
1 check failed
@Exotic209093
Exotic209093 deleted the worktree-wf_e4b0f9de-5d7-8 branch September 9, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant