import test from 'brittle'
import { run, usage } from '../lib/commands/repo.js'
// `pgh repo create` dispatch. The trap worth pinning: run() ends with
// return client.call('repo-info', { name: sub })
// so ANY unmatched subcommand is silently treated as a repo name to show. A
// misplaced `create` case wouldn't error — it would quietly become
// "show me the repo called create".
function fakeClient () {
const calls = []
return { calls, async call (method, params) { calls.push({ method, params }); return { ok: true } } }
}
test('repo create sends create-repo with the name and default branch main', async (t) => {
const c = fakeClient()
await run(c, ['create', 'myapp'])
t.is(c.calls.length, 1, 'one rpc')
t.is(c.calls[0].method, 'create-repo', 'called create-repo')
t.alike(c.calls[0].params, { name: 'myapp', branch: 'main' }, 'name + default branch')
})
test('repo create honours --branch', async (t) => {
const c = fakeClient()
await run(c, ['create', 'legacy', '--branch', 'master'])
t.alike(c.calls[0].params, { name: 'legacy', branch: 'master' }, 'branch parsed from flag')
})
test('repo create does NOT fall through to repo-info', async (t) => {
const c = fakeClient()
await run(c, ['create', 'myapp'])
t.absent(c.calls.some((x) => x.method === 'repo-info'), 'never hit the bare-name fallthrough')
})
test('repo create without a name errors instead of creating something', async (t) => {
const c = fakeClient()
await t.exception(() => run(c, ['create']), /usage: pgh repo create/, 'rejected')
t.is(c.calls.length, 0, 'no rpc issued')
})
test('a bare name still shows the repo (fallthrough intact)', async (t) => {
const c = fakeClient()
await run(c, ['somerepo'])
t.is(c.calls[0].method, 'repo-info', 'unmatched subcommand = show that repo')
t.alike(c.calls[0].params, { name: 'somerepo' }, 'treated as a name')
})
test('create is documented in usage', (t) => {
t.ok(/pgh repo create/.test(usage), 'usage mentions create')
})