Skip to content

Commit 31a213e

Browse files
Skn0ttsarahetter
andauthored
chore: mock API to test account id (#5859)
Co-authored-by: Sarah Etter <[email protected]>
1 parent 6a7942a commit 31a213e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: tests/integration/commands/dev/v2-api.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ import { describe, expect, test } from 'vitest'
66
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
77
import got from '../../utils/got.cjs'
88

9+
const siteInfo = {
10+
account_id: 'mock-account-id',
11+
account_slug: 'mock-account',
12+
id: 'mock-site-id',
13+
name: 'mock-site-name',
14+
}
15+
const routes = [
16+
{ path: 'sites/*/service-instances', response: [] },
17+
{ path: 'sites/*', response: siteInfo },
18+
{
19+
path: 'accounts',
20+
response: [{ id: siteInfo.account_id, slug: siteInfo.account_slug }],
21+
},
22+
]
23+
924
describe.runIf(gte(version, '18.13.0'))('v2 api', () => {
10-
setupFixtureTests('dev-server-with-v2-functions', { devServer: true }, () => {
25+
setupFixtureTests('dev-server-with-v2-functions', { devServer: true, mockApi: { routes } }, () => {
1126
test<FixtureTestContext>('should successfully be able to run v2 functions', async ({ devServer }) => {
1227
const response = await got(`http://localhost:${devServer.port}/.netlify/functions/ping`, {
1328
throwHttpErrors: false,
@@ -54,6 +69,8 @@ describe.runIf(gte(version, '18.13.0'))('v2 api', () => {
5469
expect(context.geo.city).toEqual('Mock City')
5570

5671
expect(context.cookies).toEqual({ foo: 'bar' })
72+
73+
expect(context.account.id).toEqual('mock-account-id')
5774
})
5875

5976
test<FixtureTestContext>('logging works', async ({ devServer }) => {

Diff for: tests/integration/utils/fixture.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,18 @@ export async function setupFixtureTests(
144144
if (options.mockApi) mockApi = await startMockApi(options.mockApi)
145145
fixture = await Fixture.create(fixturePath, { apiUrl: mockApi?.apiUrl })
146146

147-
if (options.devServer)
148-
devServer = await startDevServer({ cwd: fixture.directory, args: ['--offline', '--country', 'DE'] })
147+
if (options.devServer) {
148+
devServer = await startDevServer({
149+
cwd: fixture.directory,
150+
offline: !mockApi,
151+
args: ['--country', 'DE'],
152+
env: {
153+
NETLIFY_API_URL: mockApi?.apiUrl,
154+
NETLIFY_SITE_ID: 'foo',
155+
NETLIFY_AUTH_TOKEN: 'fake-token',
156+
},
157+
})
158+
}
149159

150160
await options.setup?.({ devServer, fixture, mockApi })
151161
}, HOOK_TIMEOUT)

0 commit comments

Comments
 (0)