Skip to content

Commit 248b68b

Browse files
authored
Merge pull request #40 from cloudflare/maximo/add-initial-mocks-for-cloudflare-api-client
Add initial mocks for Cloudflare api client
2 parents 6cc5ddc + 08defbf commit 248b68b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { vi } from 'vitest'
2+
3+
import type { Account } from 'cloudflare/resources/accounts/accounts.mjs'
4+
5+
/**
6+
* Creates a mocked implementation of the Cloudflare client
7+
*/
8+
export const cloudflareClientMockImplementation = () => {
9+
return {
10+
accounts: {
11+
list: vi.fn(async () => {
12+
return {
13+
success: true,
14+
result: [
15+
{
16+
id: 'mock-account-id',
17+
name: 'mock-account-name',
18+
},
19+
] satisfies Account[],
20+
}
21+
}),
22+
},
23+
}
24+
}

packages/mcp-common/tests/logs.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { env, fetchMock } from 'cloudflare:test'
2-
import { afterEach, beforeAll, describe, expect, it } from 'vitest'
2+
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
33

44
import { handleWorkerLogs, handleWorkerLogsKeys } from '../src/api/logs'
5+
import { cloudflareClientMockImplementation } from '../src/utils/cloudflare-mock'
56

67
beforeAll(() => {
8+
vi.mock('cloudflare', () => {
9+
return {
10+
Cloudflare: vi.fn().mockImplementation(() => {
11+
return cloudflareClientMockImplementation()
12+
}),
13+
}
14+
})
715
// Enable outbound request mocking...
816
fetchMock.activate()
917
// ...and throw errors if an outbound request isn't mocked

0 commit comments

Comments
 (0)