Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/integrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const mock = vi.hoisted(() => {
}
const workspaceHandle = {
workspaceId: 'account-workspace-id',
client: vi.fn(() => relayClient)
client: vi.fn(() => relayClient),
refreshToken: vi.fn(async () => undefined)
}
const relayWorkspaceManager = {
withHandle: vi.fn(async (fn: (handle: typeof workspaceHandle) => Promise<unknown>) => fn(workspaceHandle)),
Expand Down Expand Up @@ -180,6 +181,7 @@ const mock = vi.hoisted(() => {
readFileCalls,
relayClient,
relayWorkspaceManager,
workspaceHandle,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Exposing joinWorkspace as a mock function on the hoisted mock object allows individual tests to assert on its calls or customize its behavior (e.g., mocking failures or custom return values).

    workspaceHandle,
    joinWorkspace: vi.fn(async () => workspaceHandle),

brokerManager: {
listAgents: vi.fn(async () => []),
sendMessage: vi.fn(async () => undefined),
Expand All @@ -196,6 +198,18 @@ const mock = vi.hoisted(() => {
}
})

// readRemoteFile/listRemoteDirectory now resolve a reader handle via
// RelayfileSetup.joinWorkspace (integrations.ts getIntegrationRemoteReaderHandle).
// Mock the SDK so that path returns the in-memory handle instead of doing a
// real network join.
vi.mock('@relayfile/sdk', () => ({
RelayfileSetup: class {
async joinWorkspace() {
return mock.workspaceHandle
}
}
}))
Comment on lines +205 to +211

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

By mocking RelayfileSetup as a mock function that returns an object with the joinWorkspace mock, we make the SDK integration fully assertable and controllable in tests.

vi.mock('@relayfile/sdk', () => ({
  RelayfileSetup: vi.fn().mockImplementation(() => ({
    joinWorkspace: mock.joinWorkspace
  }))
}))


vi.mock('electron', () => ({
BrowserWindow: mock.browserWindow,
shell: {
Expand Down
Loading