-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathvercel-api.test.ts
More file actions
99 lines (86 loc) · 2.96 KB
/
vercel-api.test.ts
File metadata and controls
99 lines (86 loc) · 2.96 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import type { ActionConfig } from '../types'
import { beforeAll, describe, expect, it } from 'vitest'
import { VercelApiClient } from '../vercel-api'
import { TEST_PROJECT, TEST_TEAM, VERCEL_TOKEN, vercelFetch } from './helpers'
function createConfig(overrides: Partial<ActionConfig> = {}): ActionConfig {
return {
githubToken: '',
githubComment: false,
workingDirectory: '',
vercelToken: VERCEL_TOKEN,
vercelArgs: '',
vercelOrgId: '',
vercelProjectId: '',
vercelProjectName: '',
vercelBin: '',
aliasDomains: [],
vercelScope: TEST_TEAM,
...overrides,
}
}
let aliasSupported = true
describe('vercelApiClient (integration)', () => {
beforeAll(async () => {
// Probe whether the alias endpoint is available in this emulator version
const probeRes = await vercelFetch(`/v2/deployments/probe-alias-support/aliases`, {
method: 'POST',
body: JSON.stringify({ alias: 'probe.example.com' }),
})
if (probeRes.status === 404) {
aliasSupported = false
}
})
describe('inspect', () => {
it('should return project name from a deployment', async () => {
const createRes = await vercelFetch(`/v13/deployments?slug=${TEST_TEAM}`, {
method: 'POST',
body: JSON.stringify({
name: TEST_PROJECT,
target: 'preview',
files: [{ file: 'index.html', data: '<h1>Hello</h1>' }],
}),
})
const created = await createRes.json()
const client = new VercelApiClient(createConfig(), process.env.EMULATE_VERCEL_URL)
const result = await client.inspect(created.id)
expect(result.name).toBe(TEST_PROJECT)
})
it('should return null name for non-existent deployment', async () => {
const client = new VercelApiClient(createConfig(), process.env.EMULATE_VERCEL_URL)
const result = await client.inspect('non-existent-id')
expect(result.name).toBeNull()
})
})
describe('assignAlias', () => {
it('should assign an alias to a deployment', async () => {
if (!aliasSupported) {
return
}
const createRes = await vercelFetch(`/v13/deployments?slug=${TEST_TEAM}`, {
method: 'POST',
body: JSON.stringify({
name: TEST_PROJECT,
target: 'preview',
files: [{ file: 'index.html', data: '<h1>Hello</h1>' }],
}),
})
const created = await createRes.json()
const client = new VercelApiClient(createConfig(), process.env.EMULATE_VERCEL_URL)
await client.assignAlias(created.id, 'my-alias.example.com')
})
})
describe('deploy', () => {
it('should throw not-implemented error', async () => {
const client = new VercelApiClient(createConfig(), process.env.EMULATE_VERCEL_URL)
await expect(
client.deploy(createConfig(), {
ref: 'main',
sha: 'abc',
commit: 'test',
commitOrg: 'org',
commitRepo: 'repo',
}),
).rejects.toThrow('not yet implemented')
})
})
})