Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Apr 24, 2024
1 parent 55e4f43 commit a2a6465
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/ci/run_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class RunPRJob {

try {
cli.startSpinner('Starting PR CI job');
throw 'NOOO'
const response = await this.request.fetch(CI_PR_URL, {
method: 'POST',
headers: {
Expand Down
44 changes: 43 additions & 1 deletion test/unit/ci_start.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, before } from 'node:test';
import { describe, it, before, afterEach } from 'node:test';
import assert from 'assert';

import sinon from 'sinon';
Expand All @@ -9,6 +9,7 @@ import {
CI_CRUMB_URL,
CI_PR_URL
} from '../../lib/ci/run_ci.js';
import PRChecker from '../../lib/pr_checker.js';

import TestCLI from '../fixtures/test_cli.js';

Expand Down Expand Up @@ -111,4 +112,45 @@ describe('Jenkins', () => {
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, true);
assert.strictEqual(await jobRunner.start(), false);
});

describe('without --certify-safe flag', () => {
afterEach(() => {
sinon.restore();
});
for (const certifySafe of [false, true]) {
it(`should return ${certifySafe} if PR checker reports it as ${
certifySafe ? '' : 'potentially un'
}safe`, async() => {
const cli = new TestCLI();

sinon.replace(PRChecker.prototype, 'checkCommitsAfterReview',
sinon.fake.returns(certifySafe));

const request = {
gql: sinon.stub().returns({
repository: {
pullRequest: {
labels: {
nodes: []
}
}
}
}),
fetch: sinon.stub()
.callsFake((url, { method, headers, body }) => {
assert.strictEqual(url, CI_PR_URL);
assert.strictEqual(method, 'POST');
assert.deepStrictEqual(headers, { 'Jenkins-Crumb': crumb });
assert.ok(body._validated);
return Promise.resolve({ status: 201 });
}),
json: sinon.stub().withArgs(CI_CRUMB_URL)
.returns(Promise.resolve({ crumb }))
};

const jobRunner = new RunPRJob(cli, request, owner, repo, prid, false);
assert.strictEqual(await jobRunner.start(), certifySafe);

Check failure on line 152 in test/unit/ci_start.test.js

View workflow job for this annotation

GitHub Actions / Test on Node.js / test (20, ubuntu-latest)

should return true if PR checker reports it as safe

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: false !== true ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: false !== true at TestContext.<anonymous> (file:///home/runner/work/node-core-utils/node-core-utils/test/unit/ci_start.test.js:152:16) at async Test.run (node:internal/test_runner/test:640:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: false, expected: true, operator: 'strictEqual' } }

Check failure on line 152 in test/unit/ci_start.test.js

View workflow job for this annotation

GitHub Actions / Test on Node.js / test (20, macos-latest)

should return true if PR checker reports it as safe

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: false !== true ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: false !== true at TestContext.<anonymous> (file:///Users/runner/work/node-core-utils/node-core-utils/test/unit/ci_start.test.js:152:16) at async Test.run (node:internal/test_runner/test:640:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: false, expected: true, operator: 'strictEqual' } }

Check failure on line 152 in test/unit/ci_start.test.js

View workflow job for this annotation

GitHub Actions / Test on Node.js / test (18, ubuntu-latest)

should return true if PR checker reports it as safe

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: false !== true ] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: false !== true at TestContext.<anonymous> (file:///home/runner/work/node-core-utils/node-core-utils/test/unit/ci_start.test.js:152:16) at async Test.run (node:internal/test_runner/test:632:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: false, expected: true, operator: 'strictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 152 in test/unit/ci_start.test.js

View workflow job for this annotation

GitHub Actions / Test on Node.js / test (18, macos-latest)

should return true if PR checker reports it as safe

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: false !== true ] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: false !== true at TestContext.<anonymous> (file:///Users/runner/work/node-core-utils/node-core-utils/test/unit/ci_start.test.js:152:16) at async Test.run (node:internal/test_runner/test:632:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: false, expected: true, operator: 'strictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 152 in test/unit/ci_start.test.js

View workflow job for this annotation

GitHub Actions / Test on Node.js / test (21, ubuntu-latest, experimental)

should return true if PR checker reports it as safe

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: false !== true ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: false !== true at TestContext.<anonymous> (file:///home/runner/work/node-core-utils/node-core-utils/test/unit/ci_start.test.js:152:16) at async Test.run (node:internal/test_runner/test:640:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: false, expected: true, operator: 'strictEqual' } }

Check failure on line 152 in test/unit/ci_start.test.js

View workflow job for this annotation

GitHub Actions / Test on Node.js / test (21, macos-latest, experimental)

should return true if PR checker reports it as safe

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: false !== true ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: false !== true at TestContext.<anonymous> (file:///Users/runner/work/node-core-utils/node-core-utils/test/unit/ci_start.test.js:152:16) at async Test.run (node:internal/test_runner/test:640:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: false, expected: true, operator: 'strictEqual' } }
});
}
});
});

0 comments on commit a2a6465

Please sign in to comment.