import { describe, expect } from 'vitest' import constants, { FLAG_CONFIG, FLAG_DRY_RUN, FLAG_HELP, FLAG_ORG, } from '../../../src/constants.mts' import { cmdit, spawnSocketCli } from '../../../test/utils.mts' describe('socket repository update', async () => { const { binCliPath } = constants cmdit( ['repository', 'update', FLAG_HELP, FLAG_CONFIG, '{}'], `should support ${FLAG_HELP}`, async cmd => { const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd) expect(stdout).toMatchInlineSnapshot( ` "Update a repository in an organization Usage $ socket repository update [options] API Token Requirements - Quota: 1 unit - Permissions: repo:update Options --default-branch Repository default branch --homepage Repository url --interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no. --json Output as JSON --markdown Output as Markdown --org Force override the organization slug, overrides the default org from config --repo-description Repository description --visibility Repository visibility (Default Private) Examples $ socket repository update test-repo $ socket repository update test-repo --homepage https://example.com" `, ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | CLI: |__ | * | _| '_| -_| _| | token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: " `) expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket repository update`', ) }, ) cmdit( ['repository', 'update', FLAG_DRY_RUN, FLAG_CONFIG, '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd) expect(stdout).toMatchInlineSnapshot(`""`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | CLI: |__ | * | _| '_| -_| _| | token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: \\u203c Unable to determine the target org. Trying to auto-discover it now... i Note: Run \`socket login\` to set a default org. Use the --org flag to override the default org. \\xd7 Skipping auto-discovery of org in dry-run mode \\xd7 Input error: Please review the input requirements and try again \\xd7 Org name by default setting, --org, or auto-discovered (missing) \\xd7 Repository name as first argument (missing)" `) expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) }, ) cmdit( [ 'repository', 'update', 'reponame', FLAG_DRY_RUN, FLAG_CONFIG, '{"apiToken":"fakeToken"}', ], 'should report missing org name', async cmd => { const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd) expect(stdout).toMatchInlineSnapshot(`""`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | CLI: |__ | * | _| '_| -_| _| | token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: \\u203c Unable to determine the target org. Trying to auto-discover it now... i Note: Run \`socket login\` to set a default org. Use the --org flag to override the default org. \\xd7 Skipping auto-discovery of org in dry-run mode \\xd7 Input error: Please review the input requirements and try again \\xd7 Org name by default setting, --org, or auto-discovered (missing) \\u221a Repository name as first argument" `) expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) }, ) cmdit( [ 'repository', 'update', FLAG_DRY_RUN, FLAG_CONFIG, '{"apiToken":"fakeToken", "defaultOrg": "fakeOrg"}', ], 'should only report missing repo name with default org', async cmd => { const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd) expect(stdout).toMatchInlineSnapshot(`""`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | CLI: |__ | * | _| '_| -_| _| | token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: \\xd7 Input error: Please review the input requirements and try again \\xd7 Repository name as first argument (missing)" `) expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) }, ) cmdit( [ 'repository', 'update', FLAG_ORG, 'forcedorg', FLAG_DRY_RUN, FLAG_CONFIG, '{"apiToken":"fakeToken"}', ], 'should only report missing repo name with --org flag', async cmd => { const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd) expect(stdout).toMatchInlineSnapshot(`""`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | CLI: |__ | * | _| '_| -_| _| | token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: \\xd7 Input error: Please review the input requirements and try again \\xd7 Repository name as first argument (missing)" `) expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) }, ) cmdit( [ 'repository', 'update', 'fakerepo', FLAG_DRY_RUN, FLAG_CONFIG, '{"apiToken":"fakeToken", "defaultOrg": "fakeOrg"}', ], 'should run to dryrun', async cmd => { const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd) expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | CLI: |__ | * | _| '_| -_| _| | token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: " `) expect(code, 'dry-run should exit with code 0 on success').toBe(0) }, ) })