setup.test.ts83 lines · main
| 1 | import assert from 'node:assert/strict'; |
| 2 | import { describe, it } from 'node:test'; |
| 3 | |
| 4 | import { |
| 5 | decideBranch, |
| 6 | looksLikeProjectRef, |
| 7 | parseConnectProjectArgs, |
| 8 | parseSetupArgs, |
| 9 | } from './setup.js'; |
| 10 | |
| 11 | describe('decideBranch', () => { |
| 12 | it('missing briven.json → wizard', () => { |
| 13 | assert.equal(decideBranch({ hasBrivenJson: false, hasUserToken: true }), 'wizard'); |
| 14 | }); |
| 15 | it('missing token → auth then watch', () => { |
| 16 | assert.equal(decideBranch({ hasBrivenJson: true, hasUserToken: false }), 'auth-then-watch'); |
| 17 | }); |
| 18 | it('both present → watch', () => { |
| 19 | assert.equal(decideBranch({ hasBrivenJson: true, hasUserToken: true }), 'watch'); |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | describe('parseSetupArgs (new project only)', () => { |
| 24 | it('defaults', () => { |
| 25 | const a = parseSetupArgs([]); |
| 26 | assert.equal(a.template, 'blank'); |
| 27 | assert.equal(a.yes, false); |
| 28 | assert.equal(a.name, undefined); |
| 29 | assert.equal(a.project, undefined); |
| 30 | }); |
| 31 | |
| 32 | it('parses --name and --template', () => { |
| 33 | const a = parseSetupArgs(['--name', 'my-app', '--template', 'todo-app', '--region', 'us-east']); |
| 34 | assert.equal(a.name, 'my-app'); |
| 35 | assert.equal(a.template, 'todo-app'); |
| 36 | assert.equal(a.region, 'us-east'); |
| 37 | }); |
| 38 | |
| 39 | it('still parses --project so setup can redirect to connect', () => { |
| 40 | const a = parseSetupArgs(['--project=p_abc', '-y']); |
| 41 | assert.equal(a.project, 'p_abc'); |
| 42 | assert.equal(a.yes, true); |
| 43 | }); |
| 44 | |
| 45 | it('positional name → create new project', () => { |
| 46 | const a = parseSetupArgs(['my-cool-app']); |
| 47 | assert.equal(a.name, 'my-cool-app'); |
| 48 | assert.equal(a.project, undefined); |
| 49 | }); |
| 50 | |
| 51 | it('positional p_ id is treated as a name token (runSetup redirects to connect)', () => { |
| 52 | const a = parseSetupArgs(['p_01HZabc123']); |
| 53 | assert.equal(a.name, 'p_01HZabc123'); |
| 54 | assert.equal(a.project, undefined); |
| 55 | assert.equal(looksLikeProjectRef(a.name!), true); |
| 56 | }); |
| 57 | |
| 58 | it('explicit --name wins over positional', () => { |
| 59 | const a = parseSetupArgs(['ignored', '--name', 'real-name']); |
| 60 | assert.equal(a.name, 'real-name'); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | describe('parseConnectProjectArgs (existing project)', () => { |
| 65 | it('defaults', () => { |
| 66 | const a = parseConnectProjectArgs([]); |
| 67 | assert.equal(a.project, undefined); |
| 68 | assert.equal(a.yes, false); |
| 69 | assert.equal(a.force, false); |
| 70 | }); |
| 71 | |
| 72 | it('positional p_ id → project', () => { |
| 73 | const a = parseConnectProjectArgs(['p_01HZabc123']); |
| 74 | assert.equal(a.project, 'p_01HZabc123'); |
| 75 | }); |
| 76 | |
| 77 | it('parses --project and --force', () => { |
| 78 | const a = parseConnectProjectArgs(['--project', 'my-slug', '--force', '-y']); |
| 79 | assert.equal(a.project, 'my-slug'); |
| 80 | assert.equal(a.force, true); |
| 81 | assert.equal(a.yes, true); |
| 82 | }); |
| 83 | }); |