Skip to content

Commit 9ae7c1a

Browse files
committed
test(memory): use the shared env and outbox mocks for cleanup enqueue
1 parent e42d58a commit 9ae7c1a

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

‎apps/sim/lib/mothership/memories/cleanup-outbox.test.ts‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
/**
22
* @vitest-environment node
33
*/
4+
import { resetEnvMock, setEnv } from '@sim/testing/mocks/env.mock'
5+
import { mothershipAgentUrlMock } from '@sim/testing/mocks/mothership-agent-url.mock'
6+
import { mothershipGoFetchMock } from '@sim/testing/mocks/mothership-go-fetch.mock'
7+
import { outboxServiceMock, outboxServiceMockFns } from '@sim/testing/mocks/outbox-service.mock'
48
import { beforeEach, describe, expect, it, vi } from 'vitest'
59

6-
const { mockEnv, mockEnqueue } = vi.hoisted(() => ({
7-
mockEnv: { COPILOT_API_KEY: undefined as string | undefined } as Record<
8-
string,
9-
string | undefined
10-
>,
11-
mockEnqueue: vi.fn(),
12-
}))
13-
14-
vi.mock('@/lib/core/config/env', () => ({ env: mockEnv }))
15-
vi.mock('@/lib/core/outbox/service', () => ({ enqueueOutboxEvent: mockEnqueue }))
10+
vi.mock('@/lib/core/outbox/service', () => outboxServiceMock)
1611
vi.mock('@/lib/mothership/constants', () => ({ SIM_AGENT_API_URL: 'https://agent.example.test' }))
17-
vi.mock('@/lib/mothership/request/go/fetch', () => ({ fetchGo: vi.fn() }))
12+
vi.mock('@/lib/mothership/request/go/fetch', () => mothershipGoFetchMock)
1813
vi.mock('@/lib/mothership/request/headers', () => ({ mothershipRequestHeaders: () => ({}) }))
19-
vi.mock('@/lib/mothership/server/agent-url', () => ({ getMothershipSourceEnvHeaders: () => ({}) }))
14+
vi.mock('@/lib/mothership/server/agent-url', () => mothershipAgentUrlMock)
2015

2116
import { enqueueMemoryCleanup } from '@/lib/mothership/memories/cleanup-outbox'
2217

18+
const { mockEnqueueOutboxEvent } = outboxServiceMockFns
2319
const executor = { insert: vi.fn() }
2420
const targets = [
2521
{ kind: 'private_owner' as const, userId: 'user-1' },
@@ -28,20 +24,25 @@ const targets = [
2824

2925
describe('enqueueMemoryCleanup', () => {
3026
beforeEach(() => {
31-
vi.clearAllMocks()
32-
mockEnv.COPILOT_API_KEY = undefined
27+
resetEnvMock()
28+
setEnv({
29+
COPILOT_API_KEY: undefined,
30+
COPILOT_DEV_URL: undefined,
31+
COPILOT_STAGING_URL: undefined,
32+
COPILOT_PROD_URL: undefined,
33+
})
3334
})
3435

3536
it('queues nothing when this Sim has no worker credential', async () => {
3637
await enqueueMemoryCleanup(executor, targets)
37-
expect(mockEnqueue).not.toHaveBeenCalled()
38+
expect(mockEnqueueOutboxEvent).not.toHaveBeenCalled()
3839
})
3940

4041
it('queues one credential-bound event per destination and target', async () => {
41-
mockEnv.COPILOT_API_KEY = 'configured-key'
42+
setEnv({ COPILOT_API_KEY: 'configured-key' })
4243
await enqueueMemoryCleanup(executor, targets)
43-
expect(mockEnqueue).toHaveBeenCalledTimes(targets.length)
44-
for (const [, , payload] of mockEnqueue.mock.calls)
44+
expect(mockEnqueueOutboxEvent).toHaveBeenCalledTimes(targets.length)
45+
for (const [, , payload] of mockEnqueueOutboxEvent.mock.calls)
4546
expect(payload).toMatchObject({
4647
baseUrl: 'https://agent.example.test',
4748
credentialFingerprint: expect.any(String),

0 commit comments

Comments
 (0)