Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.repoName = 'functional-events';
// Reset shared information
this.pipelineId = null;
this.eventId = null;
this.jwt = null;
});
Given(/^an existing pipeline with the workflow:$/, { timeout: TIMEOUT }, function step(table) {
return this.ensurePipelineExists({ repoName: this.repoName })
.then(() => table);
});
Given(/^"calvin" has admin permission to the pipeline$/, () => null);
Then(/^an event is created$/, { timeout: TIMEOUT }, function step() {
return request({
uri: `${this.instance}/${this.namespace}/pipelines/${this.pipelineId}/events`,
method: 'GET',
json: true,
auth: {
bearer: this.jwt
}
}).then(response => Assert.equal(response.body[0].id, this.eventId));
});
Then(/^the "main" build succeeds$/, { timeout: TIMEOUT }, function step() {
return this.waitForBuild(this.buildId).then((resp) => {
Assert.equal(resp.body.status, 'SUCCESS');
Assert.equal(resp.statusCode, 200);
});
});
case 'calvin':
Assert.strictEqual(decodedToken.username, this.username);
break;
case 'github:calvin':
Assert.strictEqual(decodedToken.username, this.username);
Assert.strictEqual(decodedToken.scmContext, this.scmContext);
break;
default:
return Promise.resolve('pending');
}
return null;
});
});
Then(/^they can see the pipeline$/, { timeout: TIMEOUT }, function step() {
return request({ // make sure pipeline exists (TODO: move to Given an existing pipeline with that repository scenario)
uri: `${this.instance}/${this.namespace}/pipelines`,
method: 'POST',
auth: {
bearer: this.jwt
},
body: {
checkoutUrl: `git@${this.scmHostname}:${this.repoOrg}/${this.repoName}.git#master`
},
json: true
}).then((response) => {
Assert.oneOf(response.statusCode, [409, 201]);
if (response.statusCode === 201) {
this.pipelineId = response.body.id;
} else {
steps.forEach((step) => {
const matchPattern = "([^']*)?";
const matcher = step.matcher
.replace(new RegExp(`(${placeholders.join('|')})`, 'g'), matchPattern);
Then(new RegExp(`^${matcher}$`), {}, require(step.path));
step.regex = new RegExp(`^${matcher}$`); // eslint-disable-line no-param-reassign
});
Then(/^fail step and take screenshot$/, {}, () => Promise.reject(new Error('Failing step and taking screenshot')));
When(/^I access the status endpoint$/, function step(callback) {
request.get(`${this.instance}/v4/status`, (err, result) => {
this.body = result ? result.body : null;
callback(err);
});
});
When(/^I access the versions endpoint$/, function step(callback) {
request.get(`${this.instance}/v4/versions`, (err, result) => {
this.body = result ? JSON.parse(result.body) : null;
callback(err);
});
});
Then(/^I should get an OK response$/, function step(callback) {
Assert.equal(this.body, 'OK');
callback(null);
});
Then(/^I should get a list of versions$/, function step(callback) {
Assert.property(this.body, 'versions');
Assert.property(this.body, 'licenses');
Assert.isAbove(this.body.licenses.length, 0);
const sampleLicense = this.body.licenses.pop();
Assert.property(sampleLicense, 'name');
Assert.property(sampleLicense, 'repository');
Assert.property(sampleLicense, 'licenses');
callback(null);
});
const TIMEOUT = 240 * 1000;
Before({
tags: '@metadata'
}, function hook() {
this.repoOrg = this.testOrg;
this.repoName = 'functional-metadata';
this.pipelineId = null;
this.eventId = null;
this.meta = null;
this.jwt = null;
});
Given(/^a metadata starts with an empty object$/, { timeout: TIMEOUT }, () => null);
Then(/^the "(BAR|BAZ)" job is started$/, { timeout: TIMEOUT }, function step(jobName) {
switch (jobName) {
case 'BAR':
this.jobName = 'second';
break;
case 'BAZ':
this.jobName = 'third';
break;
default:
throw new Error('jobName is neither BAR or BAZ');
}
return sdapi.searchForBuild({
instance: this.instance,
pipelineId: this.pipelineId,
desiredSha: this.sha,
desiredStatus: ['QUEUED', 'RUNNING', 'SUCCESS', 'FAILURE'],
bearer: jwt
},
body: {
yaml: this.templateContents
},
json: true
});
})
.then((response) => {
Assert.equal(response.statusCode, 200);
this.body = response.body;
});
});
Then(/^they are notified it has (no|some) errors$/, function step(quantity) {
switch (quantity) {
case 'no':
Assert.equal(this.body.errors.length, 0);
break;
case 'some':
Assert.equal(this.body.errors.length, 2);
Assert.equal(this.body.errors[0].message, '"description" is required');
Assert.equal(this.body.errors[1].message, '"image" must be a string');
break;
default:
return Promise.resolve('pending');
}
return null;
});