-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathadvanced-api-routes.test.ts
44 lines (36 loc) · 1.54 KB
/
advanced-api-routes.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { getLogger } from 'lambda-local'
import { v4 } from 'uuid'
import { beforeEach, expect, it, vi } from 'vitest'
import { type FixtureTestContext } from '../utils/contexts.js'
import { createFixture, runPlugin } from '../utils/fixture.js'
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
getLogger().level = 'alert'
beforeEach<FixtureTestContext>(async (ctx) => {
// set for each test a new deployID and siteID
ctx.deployID = generateRandomObjectID()
ctx.siteID = v4()
vi.stubEnv('SITE_ID', ctx.siteID)
vi.stubEnv('DEPLOY_ID', ctx.deployID)
vi.stubEnv('NETLIFY_PURGE_API_TOKEN', 'fake-token')
// hide debug logs in tests
// vi.spyOn(console, 'debug').mockImplementation(() => {})
await startMockBlobStore(ctx)
})
it<FixtureTestContext>('test', async (ctx) => {
await createFixture('advanced-api-routes', ctx)
const runPluginPromise = runPlugin(ctx)
await expect(runPluginPromise).rejects.toThrow(
'@netlify/plugin-next@5 does not support advanced API routes. The following API routes should be migrated to Netlify background or scheduled functions:',
)
// list API routes to migrate
await expect(runPluginPromise).rejects.toThrow(
'/api/hello-scheduled (type: "experimental-scheduled")',
)
await expect(runPluginPromise).rejects.toThrow(
'/api/hello-background (type: "experimental-background")',
)
// links to migration example
await expect(runPluginPromise).rejects.toThrow(
'Refer to https://ntl.fyi/next-scheduled-bg-function-migration as migration example.',
)
})