Skip to content

Commit 7e2d2c0

Browse files
committed
tests
1 parent 35107d5 commit 7e2d2c0

11 files changed

Lines changed: 393 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, REPO, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings analysis-feature-flags-get', () => {
5+
it('exits non-zero when --repo is missing', () => {
6+
const r = run('settings', 'analysis-feature-flags-get');
7+
expect(r.status).not.toBe(0);
8+
expect(r.combined).toMatch(/--repo/);
9+
});
10+
11+
it.skipIf(SKIP_ONLINE)('returns analysis feature flags for repo', () => {
12+
const r = run('settings', 'analysis-feature-flags-get', '--repo', REPO);
13+
expect(r.status).toBe(0);
14+
}, TIMEOUT);
15+
});
16+
17+
describe('settings analysis-feature-flags-update', () => {
18+
it('exits non-zero when --repo is missing', () => {
19+
const r = run('settings', 'analysis-feature-flags-update', '--flags', '{}');
20+
expect(r.status).not.toBe(0);
21+
expect(r.combined).toMatch(/--repo/);
22+
});
23+
24+
it('exits non-zero when --flags is missing', () => {
25+
const r = run('settings', 'analysis-feature-flags-update', '--repo', REPO);
26+
expect(r.status).not.toBe(0);
27+
expect(r.combined).toMatch(/--flags/);
28+
});
29+
});

tests/settings/audit-logs.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings audit-logs', () => {
5+
it.skipIf(SKIP_ONLINE)('exits 0 with default options', () => {
6+
const r = run('settings', 'audit-logs');
7+
expect(r.status).toBe(0);
8+
}, TIMEOUT);
9+
10+
it.skipIf(SKIP_ONLINE)('accepts --days --page --limit options', () => {
11+
const r = run('settings', 'audit-logs', '--days', '7', '--page', '1', '--limit', '10');
12+
expect(r.status).toBe(0);
13+
}, TIMEOUT);
14+
});

tests/settings/branches.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, REPO, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings branches-all', () => {
5+
it('exits non-zero when --repo is missing', () => {
6+
const r = run('settings', 'branches-all');
7+
expect(r.status).not.toBe(0);
8+
expect(r.combined).toMatch(/--repo/);
9+
});
10+
11+
it.skipIf(SKIP_ONLINE)('returns branch list for repo', () => {
12+
const r = run('settings', 'branches-all', '--repo', REPO);
13+
expect(r.status).toBe(0);
14+
expect(r.combined).toMatch(/branch|name/i);
15+
}, TIMEOUT);
16+
});
17+
18+
describe('settings branches-default', () => {
19+
it('exits non-zero when --repo is missing', () => {
20+
const r = run('settings', 'branches-default');
21+
expect(r.status).not.toBe(0);
22+
expect(r.combined).toMatch(/--repo/);
23+
});
24+
25+
it.skipIf(SKIP_ONLINE)('returns default branch for repo', () => {
26+
const r = run('settings', 'branches-default', '--repo', REPO);
27+
expect(r.status).toBe(0);
28+
expect(r.combined).toMatch(/branch|default/i);
29+
}, TIMEOUT);
30+
});
31+
32+
describe('settings branches-update-default', () => {
33+
it('exits non-zero when --repo is missing', () => {
34+
const r = run('settings', 'branches-update-default', '--branch', 'main');
35+
expect(r.status).not.toBe(0);
36+
expect(r.combined).toMatch(/--repo/);
37+
});
38+
39+
it('exits non-zero when --branch is missing', () => {
40+
const r = run('settings', 'branches-update-default', '--repo', REPO);
41+
expect(r.status).not.toBe(0);
42+
expect(r.combined).toMatch(/--branch/);
43+
});
44+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, REPO, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings cve-reporting-list', () => {
5+
it.skipIf(SKIP_ONLINE)('exits 0 with no filters', () => {
6+
const r = run('settings', 'cve-reporting-list');
7+
expect(r.status).toBe(0);
8+
}, TIMEOUT);
9+
10+
it.skipIf(SKIP_ONLINE)('accepts --repo and --status filters', () => {
11+
const r = run('settings', 'cve-reporting-list', '--repo', REPO, '--status', 'ACTIVE');
12+
expect(r.status).toBe(0);
13+
}, TIMEOUT);
14+
});
15+
16+
describe('settings cve-reporting-create', () => {
17+
it('exits non-zero when --name is missing', () => {
18+
const r = run('settings', 'cve-reporting-create');
19+
expect(r.status).not.toBe(0);
20+
expect(r.combined).toMatch(/--name/);
21+
});
22+
});
23+
24+
describe('settings cve-reporting-update', () => {
25+
it('exits non-zero when --report-id is missing', () => {
26+
const r = run('settings', 'cve-reporting-update', '--repo', REPO);
27+
expect(r.status).not.toBe(0);
28+
expect(r.combined).toMatch(/--report-id/);
29+
});
30+
31+
it('exits non-zero when --repo is missing', () => {
32+
const r = run('settings', 'cve-reporting-update', '--report-id', 'some-id');
33+
expect(r.status).not.toBe(0);
34+
expect(r.combined).toMatch(/--repo/);
35+
});
36+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, REPO, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings feature-flags-get', () => {
5+
it('exits non-zero when --repo is missing', () => {
6+
const r = run('settings', 'feature-flags-get');
7+
expect(r.status).not.toBe(0);
8+
expect(r.combined).toMatch(/--repo/);
9+
});
10+
11+
it.skipIf(SKIP_ONLINE)('returns feature flags for repo', () => {
12+
const r = run('settings', 'feature-flags-get', '--repo', REPO);
13+
expect(r.status).toBe(0);
14+
}, TIMEOUT);
15+
16+
it.skipIf(SKIP_ONLINE)('accepts --v2 flag', () => {
17+
const r = run('settings', 'feature-flags-get', '--repo', REPO, '--v2');
18+
expect(r.status).toBe(0);
19+
}, TIMEOUT);
20+
});
21+
22+
describe('settings feature-flags-update', () => {
23+
it('exits non-zero when --repo is missing', () => {
24+
const r = run('settings', 'feature-flags-update', '--flags', '{}');
25+
expect(r.status).not.toBe(0);
26+
expect(r.combined).toMatch(/--repo/);
27+
});
28+
29+
it('exits non-zero when --flags is missing', () => {
30+
const r = run('settings', 'feature-flags-update', '--repo', REPO);
31+
expect(r.status).not.toBe(0);
32+
expect(r.combined).toMatch(/--flags/);
33+
});
34+
});

tests/settings/helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { run, runAsync, expectOk, expectExit, expectOutput, REPO, ORG, TIMEOUT } from '../scans/helpers.js';
2+
3+
export const SKIP_ONLINE = !process.env.CODEANT_API_TOKEN;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings pr-instructions-get', () => {
5+
it('exits non-zero when --type is missing', () => {
6+
const r = run('settings', 'pr-instructions-get');
7+
expect(r.status).not.toBe(0);
8+
expect(r.combined).toMatch(/--type/);
9+
});
10+
11+
it.skipIf(SKIP_ONLINE)('returns instructions for given type', () => {
12+
const r = run('settings', 'pr-instructions-get', '--type', 'custom');
13+
expect(r.status).toBe(0);
14+
}, TIMEOUT);
15+
});
16+
17+
describe('settings pr-instructions-save', () => {
18+
it.skipIf(SKIP_ONLINE)('exits 0 with no options (all optional)', () => {
19+
const r = run('settings', 'pr-instructions-save');
20+
expect(r.status).toBe(0);
21+
}, TIMEOUT);
22+
});
23+
24+
describe('settings pr-instructions-edit', () => {
25+
it('exits non-zero when --instruction-id is missing', () => {
26+
const r = run('settings', 'pr-instructions-edit');
27+
expect(r.status).not.toBe(0);
28+
expect(r.combined).toMatch(/--instruction-id/);
29+
});
30+
});
31+
32+
describe('settings pr-instructions-delete', () => {
33+
it('exits non-zero when --instruction-id is missing', () => {
34+
const r = run('settings', 'pr-instructions-delete');
35+
expect(r.status).not.toBe(0);
36+
expect(r.combined).toMatch(/--instruction-id/);
37+
});
38+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, REPO, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings recurring-scans-list', () => {
5+
it.skipIf(SKIP_ONLINE)('exits 0 with no filters', () => {
6+
const r = run('settings', 'recurring-scans-list');
7+
expect(r.status).toBe(0);
8+
}, TIMEOUT);
9+
10+
it.skipIf(SKIP_ONLINE)('accepts --repo and --status filters', () => {
11+
const r = run('settings', 'recurring-scans-list', '--repo', REPO, '--status', 'ACTIVE');
12+
expect(r.status).toBe(0);
13+
}, TIMEOUT);
14+
});
15+
16+
describe('settings recurring-scans-create', () => {
17+
it('exits non-zero when --name is missing', () => {
18+
const r = run('settings', 'recurring-scans-create');
19+
expect(r.status).not.toBe(0);
20+
expect(r.combined).toMatch(/--name/);
21+
});
22+
});
23+
24+
describe('settings recurring-scans-update', () => {
25+
it('exits non-zero when --schedule-id is missing', () => {
26+
const r = run('settings', 'recurring-scans-update', '--repo', REPO);
27+
expect(r.status).not.toBe(0);
28+
expect(r.combined).toMatch(/--schedule-id/);
29+
});
30+
31+
it('exits non-zero when --repo is missing', () => {
32+
const r = run('settings', 'recurring-scans-update', '--schedule-id', 'some-id');
33+
expect(r.status).not.toBe(0);
34+
expect(r.combined).toMatch(/--repo/);
35+
});
36+
});

tests/settings/repos.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings repos', () => {
5+
it.skipIf(SKIP_ONLINE)('exits 0 and returns repo list', () => {
6+
const r = run('settings', 'repos');
7+
expect(r.status).toBe(0);
8+
expect(r.combined).toMatch(/repo|name/i);
9+
}, TIMEOUT);
10+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { run, REPO, TIMEOUT, SKIP_ONLINE } from './helpers.js';
3+
4+
describe('settings sprint-reports-list', () => {
5+
it.skipIf(SKIP_ONLINE)('exits 0 with no filters', () => {
6+
const r = run('settings', 'sprint-reports-list');
7+
expect(r.status).toBe(0);
8+
}, TIMEOUT);
9+
10+
it.skipIf(SKIP_ONLINE)('accepts --repo and --status filters', () => {
11+
const r = run('settings', 'sprint-reports-list', '--repo', REPO, '--status', 'ACTIVE');
12+
expect(r.status).toBe(0);
13+
}, TIMEOUT);
14+
});
15+
16+
describe('settings sprint-reports-create', () => {
17+
it('exits non-zero when --name is missing', () => {
18+
const r = run('settings', 'sprint-reports-create');
19+
expect(r.status).not.toBe(0);
20+
expect(r.combined).toMatch(/--name/);
21+
});
22+
});
23+
24+
describe('settings sprint-reports-update', () => {
25+
it('exits non-zero when --config-id is missing', () => {
26+
const r = run('settings', 'sprint-reports-update', '--repo', REPO);
27+
expect(r.status).not.toBe(0);
28+
expect(r.combined).toMatch(/--config-id/);
29+
});
30+
31+
it('exits non-zero when --repo is missing', () => {
32+
const r = run('settings', 'sprint-reports-update', '--config-id', 'some-id');
33+
expect(r.status).not.toBe(0);
34+
expect(r.combined).toMatch(/--repo/);
35+
});
36+
});

0 commit comments

Comments
 (0)