|
| 1 | +import path from 'node:path' |
| 2 | + |
| 3 | +import { describe, expect } from 'vitest' |
| 4 | + |
| 5 | +import constants from '../../../dist/constants.js' |
| 6 | +import { cmdit, invokeNpm } from '../../../test/utils' |
| 7 | + |
| 8 | +const { CLI } = constants |
| 9 | + |
| 10 | +describe('socket config get', async () => { |
| 11 | + // Lazily access constants.rootBinPath. |
| 12 | + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) |
| 13 | + |
| 14 | + cmdit(['config', 'get', '--help'], 'should support --help', async cmd => { |
| 15 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 16 | + expect(stdout).toMatchInlineSnapshot( |
| 17 | + ` |
| 18 | + "Get the value of a local CLI config item |
| 19 | +
|
| 20 | + Usage |
| 21 | + $ socket config get <org slug> |
| 22 | +
|
| 23 | + Options |
| 24 | + --dryRun Do input validation for a command and exit 0 when input is ok |
| 25 | + --help Print this help. |
| 26 | + --json Output result as json |
| 27 | + --markdown Output result as markdown |
| 28 | +
|
| 29 | + Keys: |
| 30 | +
|
| 31 | + - apiBaseUrl -- Base URL of the API endpoint |
| 32 | + - apiToken -- The API token required to access most API endpoints |
| 33 | + - apiProxy -- A proxy through which to access the API |
| 34 | + - enforcedOrgs -- Orgs in this list have their security policies enforced on this machine |
| 35 | +
|
| 36 | + Examples |
| 37 | + $ socket config get FakeOrg --repoName=test-repo" |
| 38 | + ` |
| 39 | + ) |
| 40 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 41 | + " |
| 42 | + _____ _ _ /--------------- |
| 43 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 44 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 45 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: <redacted>" |
| 46 | + `) |
| 47 | + |
| 48 | + expect(code, 'help should exit with code 2').toBe(2) |
| 49 | + expect(stderr, 'header should include command (without params)').toContain( |
| 50 | + '`socket config get`' |
| 51 | + ) |
| 52 | + }) |
| 53 | + |
| 54 | + cmdit( |
| 55 | + ['config', 'get', '--dry-run'], |
| 56 | + 'should require args with just dry-run', |
| 57 | + async cmd => { |
| 58 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 59 | + expect(stdout).toMatchInlineSnapshot(`""`) |
| 60 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 61 | + " |
| 62 | + _____ _ _ /--------------- |
| 63 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 64 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 65 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: <redacted> |
| 66 | +
|
| 67 | + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: |
| 68 | +
|
| 69 | + - Config key should be the first arg \\x1b[31m(missing!)\\x1b[39m" |
| 70 | + `) |
| 71 | + |
| 72 | + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) |
| 73 | + } |
| 74 | + ) |
| 75 | + |
| 76 | + cmdit( |
| 77 | + ['config', 'get', 'test', '--dry-run'], |
| 78 | + 'should require args with just dry-run', |
| 79 | + async cmd => { |
| 80 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 81 | + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) |
| 82 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 83 | + " |
| 84 | + _____ _ _ /--------------- |
| 85 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 86 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 87 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: <redacted>" |
| 88 | + `) |
| 89 | + |
| 90 | + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) |
| 91 | + } |
| 92 | + ) |
| 93 | +}) |
0 commit comments