|
| 1 | +import { expect } from '@oclif/test' |
| 2 | +import { dvcTest } from '../../../test-utils' |
| 3 | +import { BASE_URL } from '../../api/common' |
| 4 | + |
| 5 | +describe('features list', () => { |
| 6 | + const projectKey = 'test-project' |
| 7 | + const authFlags = ['--client-id', 'test-client-id', '--client-secret', 'test-client-secret'] |
| 8 | + |
| 9 | + const mockFeatures = [ |
| 10 | + { |
| 11 | + key: 'feature-1', |
| 12 | + name: 'Feature 1', |
| 13 | + _id: '61450f3daec96f5cf4a49946' |
| 14 | + }, |
| 15 | + { |
| 16 | + key: 'feature-2', |
| 17 | + name: 'Feature 2', |
| 18 | + _id: '61450f3daec96f5cf4a49947', |
| 19 | + } |
| 20 | + ] |
| 21 | + |
| 22 | + dvcTest() |
| 23 | + .nock(BASE_URL, (api) => api |
| 24 | + .get(`/v1/projects/${projectKey}/features`) |
| 25 | + .reply(200, mockFeatures) |
| 26 | + ) |
| 27 | + .stdout() |
| 28 | + .command(['features list', '--project', projectKey, ...authFlags]) |
| 29 | + .it('returns a list of feature keys', (ctx) => { |
| 30 | + expect(ctx.stdout).to.contain(JSON.stringify(['feature-1', 'feature-2'], null, 2)) |
| 31 | + }) |
| 32 | + |
| 33 | + dvcTest() |
| 34 | + .nock(BASE_URL, (api) => api |
| 35 | + .get(`/v1/projects/${projectKey}/features`) |
| 36 | + .query({ page: 2, perPage: 10 }) |
| 37 | + .reply(200, mockFeatures) |
| 38 | + ) |
| 39 | + .stdout() |
| 40 | + .command([ |
| 41 | + 'features list', |
| 42 | + '--project', projectKey, |
| 43 | + '--page', '2', |
| 44 | + '--per-page', '10', |
| 45 | + ...authFlags |
| 46 | + ]) |
| 47 | + .it('passes pagination params to api', (ctx) => { |
| 48 | + expect(ctx.stdout).to.contain(JSON.stringify(['feature-1', 'feature-2'], null, 2)) |
| 49 | + }) |
| 50 | + |
| 51 | + dvcTest() |
| 52 | + .nock(BASE_URL, (api) => api |
| 53 | + .get(`/v1/projects/${projectKey}/features`) |
| 54 | + .query({ search: 'hello world' }) |
| 55 | + .reply(200, mockFeatures) |
| 56 | + ) |
| 57 | + .stdout() |
| 58 | + .command([ |
| 59 | + 'features list', |
| 60 | + '--project', projectKey, |
| 61 | + '--search', 'hello world', |
| 62 | + ...authFlags |
| 63 | + ]) |
| 64 | + .it('passes search param to api', (ctx) => { |
| 65 | + expect(ctx.stdout).to.contain(JSON.stringify(['feature-1', 'feature-2'], null, 2)) |
| 66 | + }) |
| 67 | +}) |
0 commit comments