|
| 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 organization list', async () => { |
| 11 | + // Lazily access constants.rootBinPath. |
| 12 | + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) |
| 13 | + |
| 14 | + cmdit( |
| 15 | + ['organization', 'policy', 'security', '--help'], |
| 16 | + 'should support --help', |
| 17 | + async cmd => { |
| 18 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 19 | + expect(stdout).toMatchInlineSnapshot( |
| 20 | + ` |
| 21 | + "Retrieve the security policy of an organization. |
| 22 | +
|
| 23 | + Usage |
| 24 | + $ socket organization policy security <org slug> |
| 25 | +
|
| 26 | + Options |
| 27 | + --dryRun Do input validation for a command and exit 0 when input is ok |
| 28 | + --help Print this help. |
| 29 | + --json Output result as json |
| 30 | + --markdown Output result as markdown |
| 31 | +
|
| 32 | + Your API token will need the \`security-policy:read\` permission otherwise |
| 33 | + the request will fail with an authentication error. |
| 34 | +
|
| 35 | + Examples |
| 36 | + $ socket organization policy security mycorp |
| 37 | + $ socket organization policy security mycorp --json" |
| 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 organization policy security\`, cwd: <redacted>" |
| 46 | + `) |
| 47 | + |
| 48 | + expect(code, 'help should exit with code 2').toBe(2) |
| 49 | + expect( |
| 50 | + stderr, |
| 51 | + 'header should include command (without params)' |
| 52 | + ).toContain('`socket organization policy security`') |
| 53 | + } |
| 54 | + ) |
| 55 | + |
| 56 | + cmdit( |
| 57 | + ['organization', 'policy', 'security', '--dry-run'], |
| 58 | + 'should reject dry run without proper args', |
| 59 | + async cmd => { |
| 60 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 61 | + expect(stdout).toMatchInlineSnapshot(`""`) |
| 62 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 63 | + " |
| 64 | + _____ _ _ /--------------- |
| 65 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 66 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 67 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: <redacted> |
| 68 | +
|
| 69 | + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: |
| 70 | +
|
| 71 | + - Org name as the first argument \\x1b[31m(missing!)\\x1b[39m |
| 72 | + - The json and markdown flags cannot be both set \\x1b[32m(ok)\\x1b[39m" |
| 73 | + `) |
| 74 | + |
| 75 | + expect(code, 'dry-run should exit with code 2 if input bad').toBe(2) |
| 76 | + } |
| 77 | + ) |
| 78 | + |
| 79 | + cmdit( |
| 80 | + ['organization', 'policy', 'security', 'fakeorg', '--dry-run'], |
| 81 | + 'should be ok with org name and id', |
| 82 | + async cmd => { |
| 83 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 84 | + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) |
| 85 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 86 | + " |
| 87 | + _____ _ _ /--------------- |
| 88 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 89 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 90 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: <redacted>" |
| 91 | + `) |
| 92 | + |
| 93 | + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) |
| 94 | + } |
| 95 | + ) |
| 96 | +}) |
0 commit comments