Skip to content

Commit 181f90e

Browse files
Saas 6899 (#438)
* SAAS-6899 throw error when cant find project by id/name * SAAS-6899 throw error when cant find project by id/name * SAAS-6899 throw error when cant find project by id/name * SAAS-6899 throw error when cant find project by id/name * SAAS-6901 Add tags to query params for getting pipeline by name * SAAS-6899 fixed tests
1 parent 2922406 commit 181f90e

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

lib/interface/cli/commands/project/get.cmd.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Command = require('../../Command');
2+
const CFError = require('cf-errors');
23
const { sdk } = require('../../../../logic');
34
const Project = require('../../../../logic/entities/Project');
45
const Output = require('../../../../output/Output');
@@ -17,29 +18,27 @@ const command = new Command({
1718
category: 'Projects',
1819
title: 'Get Projects',
1920
},
20-
builder: (yargs) => {
21-
return yargs
22-
.positional('id|name', {
23-
describe: 'Project id or name to get one project',
24-
})
25-
.option('name', {
26-
alias: 'n',
27-
describe: 'Project name to filter by',
28-
})
29-
.option('tag', {
30-
alias: 't',
31-
describe: 'Project tags array to filter by',
32-
array: true,
33-
})
34-
.option('limit', {
35-
describe: 'Limit amount of returned results',
36-
default: DEFAULTS.GET_LIMIT_RESULTS,
37-
})
38-
.option('page', {
39-
describe: 'Paginated page',
40-
default: DEFAULTS.GET_PAGINATED_PAGE,
41-
});
42-
},
21+
builder: yargs => yargs
22+
.positional('id|name', {
23+
describe: 'Project id or name to get one project',
24+
})
25+
.option('name', {
26+
alias: 'n',
27+
describe: 'Project name to filter by',
28+
})
29+
.option('tag', {
30+
alias: 't',
31+
describe: 'Project tags array to filter by',
32+
array: true,
33+
})
34+
.option('limit', {
35+
describe: 'Limit amount of returned results',
36+
default: DEFAULTS.GET_LIMIT_RESULTS,
37+
})
38+
.option('page', {
39+
describe: 'Paginated page',
40+
default: DEFAULTS.GET_PAGINATED_PAGE,
41+
}),
4342
handler: async (argv) => {
4443
const { id, name, limit, page, tag: tags } = argv; // eslint-disable-line
4544
const offset = (page - 1) * limit;
@@ -56,7 +55,10 @@ const command = new Command({
5655
limit,
5756
offset,
5857
});
59-
projects = result.projects; // eslint-disable-line
58+
projects = result.projects || []; // eslint-disable-line
59+
}
60+
if (!projects.length) {
61+
throw new CFError('No projects found');
6062
}
6163
Output.print(_.map(projects, Project.fromResponse));
6264
},

lib/interface/cli/commands/project/project.sdk.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ describe('project commands', () => {
2626

2727
it('should handle getting given name', async () => {
2828
const argv = { name: 'some name' };
29-
await getCmd.handler(argv);
30-
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
29+
const res = await getCmd.handler(argv).catch(err => err);
30+
expect(res.message).toEqual('No projects found');
3131
});
3232

3333
it('should handle getting all', async () => {
3434
const argv = {};
3535
const response = { statusCode: 200, body: [DEFAULT_RESPONSE.body] };
3636
request.__setResponse(response);
37-
await getCmd.handler(argv);
38-
await verifyResponsesReturned([response]); // eslint-disable-line
37+
const res = await getCmd.handler(argv).catch(err => err);
38+
expect(res.message).toEqual('No projects found');
3939
});
4040
});
4141

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.52.2",
3+
"version": "0.52.3",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)