|
1 | 1 | import nock from 'nock'
|
2 | 2 | import { describe, it } from '@jest/globals'
|
3 |
| -import { FLY_API_GRAPHQL } from '../src/client' |
| 3 | +import { FLY_API_HOSTNAME } from '../src/client' |
4 | 4 | import { createClient } from '../src/main'
|
| 5 | +import { AppResponse, AppStatus } from '../src/lib/app' |
5 | 6 |
|
6 |
| -const fly = createClient('test-token') |
| 7 | +const fly = createClient(process.env.FLY_API_TOKEN || 'test-token') |
7 | 8 |
|
8 | 9 | describe('app', () => {
|
9 |
| - const organizationId = 'personal' |
| 10 | + const app: AppResponse = { |
| 11 | + name: 'fly-app', |
| 12 | + status: AppStatus.deployed, |
| 13 | + organization: { |
| 14 | + name: 'fly-org', |
| 15 | + slug: 'personal', |
| 16 | + }, |
| 17 | + } |
10 | 18 |
|
11 |
| - it('creates app', async () => { |
12 |
| - nock(FLY_API_GRAPHQL) |
13 |
| - .post('/graphql') |
| 19 | + it('lists apps', async () => { |
| 20 | + const org_slug = app.organization.slug |
| 21 | + nock(FLY_API_HOSTNAME) |
| 22 | + .get('/v1/apps') |
| 23 | + .query({ org_slug }) |
14 | 24 | .reply(200, {
|
15 |
| - data: { |
16 |
| - createApp: { |
17 |
| - app: { |
18 |
| - id: 'ctwntjgykzxhfncfwrfo', |
19 |
| - name: 'ctwntjgykzxhfncfwrfo', |
20 |
| - organization: { slug: 'supabase-dev' }, |
21 |
| - config: { |
22 |
| - definition: { |
23 |
| - kill_timeout: 5, |
24 |
| - kill_signal: 'SIGINT', |
25 |
| - processes: [], |
26 |
| - experimental: { auto_rollback: true }, |
27 |
| - services: [ |
28 |
| - { |
29 |
| - processes: ['app'], |
30 |
| - protocol: 'tcp', |
31 |
| - internal_port: 8080, |
32 |
| - concurrency: { |
33 |
| - soft_limit: 20, |
34 |
| - hard_limit: 25, |
35 |
| - type: 'connections', |
36 |
| - }, |
37 |
| - ports: [ |
38 |
| - { port: 80, handlers: ['http'], force_https: true }, |
39 |
| - { port: 443, handlers: ['tls', 'http'] }, |
40 |
| - ], |
41 |
| - tcp_checks: [ |
42 |
| - { |
43 |
| - interval: '15s', |
44 |
| - timeout: '2s', |
45 |
| - grace_period: '1s', |
46 |
| - restart_limit: 0, |
47 |
| - }, |
48 |
| - ], |
49 |
| - http_checks: [], |
50 |
| - script_checks: [], |
51 |
| - }, |
52 |
| - ], |
53 |
| - env: {}, |
54 |
| - }, |
55 |
| - }, |
56 |
| - regions: [{ name: 'Hong Kong, Hong Kong', code: 'hkg' }], |
57 |
| - }, |
| 25 | + total_apps: 1, |
| 26 | + apps: [ |
| 27 | + { |
| 28 | + name: app.name, |
| 29 | + machine_count: 1, |
| 30 | + network: 'default', |
58 | 31 | },
|
59 |
| - }, |
| 32 | + ], |
60 | 33 | })
|
61 |
| - const data = await fly.App.createApp({ |
62 |
| - name: 'ctwntjgykzxhfncfwrfo', |
63 |
| - organizationId, |
64 |
| - }) |
| 34 | + const data = await fly.App.listApps(org_slug) |
| 35 | + console.dir(data, { depth: 10 }) |
| 36 | + }) |
| 37 | + |
| 38 | + it('get app', async () => { |
| 39 | + const app_name = app.name |
| 40 | + nock(FLY_API_HOSTNAME).get(`/v1/apps/${app_name}`).reply(200, app) |
| 41 | + const data = await fly.App.getApp(app_name) |
| 42 | + console.dir(data, { depth: 10 }) |
| 43 | + }) |
| 44 | + |
| 45 | + it('creates app', async () => { |
| 46 | + const body = { |
| 47 | + org_slug: app.organization.slug, |
| 48 | + app_name: app.name, |
| 49 | + } |
| 50 | + nock(FLY_API_HOSTNAME).post('/v1/apps', body).reply(201) |
| 51 | + const data = await fly.App.createApp(body) |
65 | 52 | console.dir(data, { depth: 10 })
|
66 | 53 | })
|
67 | 54 |
|
68 | 55 | it('deletes app', async () => {
|
69 |
| - nock(FLY_API_GRAPHQL) |
70 |
| - .post('/graphql') |
71 |
| - .reply(200, { |
72 |
| - data: { |
73 |
| - deleteApp: { |
74 |
| - organization: { |
75 |
| - id: organizationId, |
76 |
| - }, |
77 |
| - }, |
78 |
| - }, |
79 |
| - }) |
80 |
| - const data = await fly.App.deleteApp('ctwntjgykzxhfncfwrfo') |
| 56 | + const app_name = app.name |
| 57 | + nock(FLY_API_HOSTNAME).delete(`/v1/apps/${app_name}`).reply(202) |
| 58 | + const data = await fly.App.deleteApp(app_name) |
81 | 59 | console.dir(data, { depth: 10 })
|
82 | 60 | })
|
83 | 61 | })
|
0 commit comments