Skip to content

Commit bb8975d

Browse files
authoredJul 28, 2023
fix(2767): Pipeline stage tests (#2902)
1 parent dc27788 commit bb8975d

30 files changed

+53
-118
lines changed
 

‎features/step_definitions/templates.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const fs = require('mz/fs');
43
const path = require('path');
4+
const fs = require('mz/fs');
55
const Assert = require('chai').assert;
66
const request = require('screwdriver-request');
77
const { Before, Given, Then, When } = require('@cucumber/cucumber');

‎features/support/world.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const Assert = require('chai').assert;
43
const path = require('path');
4+
const Assert = require('chai').assert;
55
const env = require('node-env-file');
66
const { setWorldConstructor } = require('@cucumber/cucumber');
77
const request = require('screwdriver-request');

‎plugins/banners/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const schema = require('screwdriver-data-schema');
5-
const urlLib = require('url');
66

77
module.exports = () => ({
88
method: 'POST',

‎plugins/buildClusters/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const boom = require('@hapi/boom');
43
const urlLib = require('url');
4+
const boom = require('@hapi/boom');
55
const validationSchema = require('screwdriver-data-schema');
66

77
module.exports = () => ({

‎plugins/builds/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const boom = require('@hapi/boom');
43
const urlLib = require('url');
4+
const boom = require('@hapi/boom');
55
const validationSchema = require('screwdriver-data-schema');
66

77
module.exports = () => ({

‎plugins/collections/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const schema = require('screwdriver-data-schema');
5-
const urlLib = require('url');
66

77
module.exports = () => ({
88
method: 'POST',

‎plugins/commands/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
'use strict';
44

5+
const urlLib = require('url');
56
const boom = require('@hapi/boom');
67
const schema = require('screwdriver-data-schema');
78
const validator = require('screwdriver-command-validator');
89
const hoek = require('@hapi/hoek');
9-
const urlLib = require('url');
1010
const req = require('screwdriver-request');
1111
const VERSION_REGEX = schema.config.regex.VERSION;
1212
const DEFAULT_BYTES = 1024 * 1024 * 1024; // 1GB

‎plugins/commands/createTag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const joi = require('joi');
56
const schema = require('screwdriver-data-schema');
67
const baseSchema = schema.models.commandTag.base;
7-
const urlLib = require('url');
88
const VERSION_REGEX = schema.config.regex.VERSION;
99
const exactVersionSchema = schema.models.commandTag.base.extract('version');
1010
const tagSchema = schema.models.commandTag.base.extract('tag');

‎plugins/events/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const boom = require('@hapi/boom');
43
const urlLib = require('url');
4+
const boom = require('@hapi/boom');
55
const validationSchema = require('screwdriver-data-schema');
66
const ANNOT_RESTRICT_PR = 'screwdriver.cd/restrictPR';
77
const { getScmUri } = require('../helper');

‎plugins/events/stopBuilds.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const hoek = require('@hapi/hoek');
56
const joi = require('joi');
6-
const urlLib = require('url');
77
const schema = require('screwdriver-data-schema');
88
const getSchema = schema.models.event.get;
99
const idSchema = schema.models.event.base.extract('id');

‎plugins/pipelines/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const schema = require('screwdriver-data-schema');
5-
const urlLib = require('url');
66
const logger = require('screwdriver-logger');
77
const { formatCheckoutUrl, sanitizeRootDir } = require('./helper');
88
const { getUserPermissions } = require('../helper');

‎plugins/pipelines/listStages.js

+13-31
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,23 @@ module.exports = () => ({
3333
params: { pipelineId }
3434
};
3535

36-
// Set groupEventId if provided
37-
if (request.query.groupEventId) {
38-
config.params.groupEventId = request.query.groupEventId;
39-
}
40-
// Get specific stages if eventId is provided
41-
else if (request.query.eventId) {
42-
const events = await eventFactory.list({ params: { id: request.query.eventId } });
43-
44-
if (!events || Object.keys(events).length === 0) {
45-
throw boom.notFound(`Event ${request.query.eventId} does not exist`);
36+
// Get latest stages
37+
const latestCommitEvents = await eventFactory.list({
38+
params: {
39+
pipelineId,
40+
parentEventId: null,
41+
type: 'pipeline'
42+
},
43+
paginate: {
44+
count: 1
4645
}
46+
});
4747

48-
config.params.groupEventId = events[0].groupEventId;
48+
if (!latestCommitEvents || Object.keys(latestCommitEvents).length === 0) {
49+
throw boom.notFound(`Latest event does not exist for pipeline ${pipelineId}`);
4950
}
50-
// Get latest stages if eventId not provided
51-
else {
52-
const latestCommitEvents = await eventFactory.list({
53-
params: {
54-
pipelineId,
55-
parentEventId: null,
56-
type: 'pipeline'
57-
},
58-
paginate: {
59-
count: 1
60-
}
61-
});
6251

63-
if (!latestCommitEvents || Object.keys(latestCommitEvents).length === 0) {
64-
throw boom.notFound(`Latest event does not exist for pipeline ${pipelineId}`);
65-
}
66-
67-
config.params.groupEventId = latestCommitEvents[0].groupEventId;
68-
}
52+
config.params.eventId = latestCommitEvents[0].id;
6953

7054
return stageFactory.list(config);
7155
})
@@ -83,8 +67,6 @@ module.exports = () => ({
8367
}),
8468
query: schema.api.pagination.concat(
8569
joi.object({
86-
eventId: pipelineIdSchema,
87-
groupEventId: pipelineIdSchema,
8870
search: joi.forbidden() // we don't support search for Pipeline list stages
8971
})
9072
)

‎plugins/pipelines/tokens/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const joi = require('joi');
56
const schema = require('screwdriver-data-schema');
67
const logger = require('screwdriver-logger');
7-
const urlLib = require('url');
88
const pipelineIdSchema = schema.models.pipeline.base.extract('id');
99
const tokenCreateSchema = schema.models.token.create;
1010
const { getUserPermissions, getScmUri } = require('../../helper');

‎plugins/secrets/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const schema = require('screwdriver-data-schema');
56
const logger = require('screwdriver-logger');
6-
const urlLib = require('url');
77
const { getUserPermissions, getScmUri } = require('../helper');
88

99
module.exports = () => ({

‎plugins/templates/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const schema = require('screwdriver-data-schema');
56
const validator = require('screwdriver-template-validator');
67
const templateSchema = schema.api.templateValidator;
78
const hoek = require('@hapi/hoek');
8-
const urlLib = require('url');
99

1010
module.exports = () => ({
1111
method: 'POST',

‎plugins/templates/createTag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const joi = require('joi');
56
const schema = require('screwdriver-data-schema');
67
const baseSchema = schema.models.templateTag.base;
7-
const urlLib = require('url');
88

99
/* Currently, only build scope is allowed to tag template due to security reasons.
1010
* The same pipeline that publishes the template has the permission to tag it.

‎plugins/tokens/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const boom = require('@hapi/boom');
45
const schema = require('screwdriver-data-schema');
5-
const urlLib = require('url');
66

77
module.exports = () => ({
88
method: 'POST',

‎plugins/versions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
const checker = require('license-checker');
43
const fs = require('fs');
54
const path = require('path');
65
const process = require('process');
6+
const checker = require('license-checker');
77
const VError = require('verror');
88
const schema = require('screwdriver-data-schema');
99

‎test/plugins/auth.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3+
const fs = require('fs');
34
const chai = require('chai');
45
const { assert } = chai;
56
const { expect } = chai;
67
const hapi = require('@hapi/hapi');
78
const sinon = require('sinon');
8-
const fs = require('fs');
99
const hoek = require('@hapi/hoek');
1010
const jwt = require('jsonwebtoken');
1111
const testCollection = require('./data/collection.json');

‎test/plugins/buildClusters.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const { assert } = require('chai');
45
const sinon = require('sinon');
56
const hapi = require('@hapi/hapi');
6-
const urlLib = require('url');
77
const hoek = require('@hapi/hoek');
88
const testBuildCluster = require('./data/buildCluster.json');
99
const testBuildClusters = require('./data/buildClusters.json');

‎test/plugins/builds.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const { assert } = require('chai');
45
const sinon = require('sinon');
56
const hapi = require('@hapi/hapi');
67
const rewiremock = require('rewiremock/node');
7-
const urlLib = require('url');
88
const hoek = require('@hapi/hoek');
99
const nock = require('nock');
1010
const rewire = require('rewire');

‎test/plugins/collections.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const { assert } = require('chai');
45
const sinon = require('sinon');
56
const hapi = require('@hapi/hapi');
67
const rewiremock = require('rewiremock/node');
7-
const urlLib = require('url');
88
const hoek = require('@hapi/hoek');
99
const testCollection = require('./data/collection.json');
1010
const testCollectionResponse = require('./data/collection.response.json');

‎test/plugins/commands.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const { assert } = require('chai');
45
const sinon = require('sinon');
56
const hapi = require('@hapi/hapi');
67
const rewiremock = require('rewiremock/node');
7-
const urlLib = require('url');
88
const hoek = require('@hapi/hoek');
99
const streamToPromise = require('stream-to-promise');
1010
const FormData = require('form-data');

‎test/plugins/data/stages.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44
"pipelineId": 123,
55
"name": "setup",
66
"jobIds": [1, 2, 3, 4],
7-
"groupEventId": 222,
8-
"description": "Stage for setting up"
7+
"description": "Stage for setting up",
8+
"archived": false,
9+
"setup": [],
10+
"teardown": []
911
},
1012
{
1113
"id": 2,
1214
"pipelineId": 123,
1315
"name": "deploy",
1416
"jobIds": [5, 6, 7],
15-
"groupEventId": 222
17+
"archived": true,
18+
"setup": [],
19+
"teardown": []
1620
},
1721
{
1822
"id": 3,
1923
"pipelineId": 123,
2024
"name": "test",
2125
"jobIds": [],
22-
"groupEventId": 222
26+
"archived": false,
27+
"setup": [11],
28+
"teardown": [12]
2329
}
2430
]

‎test/plugins/events.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3+
const urlLib = require('url');
34
const { assert } = require('chai');
45
const badgeMaker = require('badge-maker');
56
const sinon = require('sinon');
67
const hapi = require('@hapi/hapi');
78
const hoek = require('@hapi/hoek');
8-
const urlLib = require('url');
99
const testBuild = require('./data/build.json');
1010
const testBuilds = require('./data/builds.json');
1111
const testEvent = require('./data/events.json')[0];

0 commit comments

Comments
 (0)
Please sign in to comment.