2020-11-24 15:15:51 +05:30
|
|
|
import {
|
|
|
|
createUnexpectedCommitError,
|
|
|
|
createCodeownersCommitError,
|
|
|
|
createBranchChangedCommitError,
|
2021-01-03 14:25:43 +05:30
|
|
|
branchAlreadyExistsCommitError,
|
2020-11-24 15:15:51 +05:30
|
|
|
parseCommitError,
|
|
|
|
} from '~/ide/lib/errors';
|
|
|
|
|
|
|
|
const TEST_SPECIAL = '&special<';
|
|
|
|
const TEST_SPECIAL_ESCAPED = '&special<';
|
|
|
|
const TEST_MESSAGE = 'Test message.';
|
|
|
|
const CODEOWNERS_MESSAGE =
|
|
|
|
'Push to protected branches that contain changes to files matching CODEOWNERS is not allowed';
|
|
|
|
const CHANGED_MESSAGE = 'Things changed since you started editing';
|
|
|
|
|
|
|
|
describe('~/ide/lib/errors', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
const createResponseError = (message) => ({
|
2020-11-24 15:15:51 +05:30
|
|
|
response: {
|
|
|
|
data: {
|
|
|
|
message,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const NEW_BRANCH_SUFFIX = `<br/><br/>Would you like to create a new branch?`;
|
|
|
|
const AUTOGENERATE_SUFFIX = `<br/><br/>Would you like to try auto-generating a branch name?`;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it.each`
|
|
|
|
fn | title | message | messageHTML
|
|
|
|
${createCodeownersCommitError} | ${'CODEOWNERS rule violation'} | ${TEST_MESSAGE} | ${TEST_MESSAGE}
|
|
|
|
${createCodeownersCommitError} | ${'CODEOWNERS rule violation'} | ${TEST_SPECIAL} | ${TEST_SPECIAL_ESCAPED}
|
|
|
|
${branchAlreadyExistsCommitError} | ${'Branch already exists'} | ${TEST_MESSAGE} | ${`${TEST_MESSAGE}${AUTOGENERATE_SUFFIX}`}
|
|
|
|
${branchAlreadyExistsCommitError} | ${'Branch already exists'} | ${TEST_SPECIAL} | ${`${TEST_SPECIAL_ESCAPED}${AUTOGENERATE_SUFFIX}`}
|
|
|
|
${createBranchChangedCommitError} | ${'Branch changed'} | ${TEST_MESSAGE} | ${`${TEST_MESSAGE}${NEW_BRANCH_SUFFIX}`}
|
|
|
|
${createBranchChangedCommitError} | ${'Branch changed'} | ${TEST_SPECIAL} | ${`${TEST_SPECIAL_ESCAPED}${NEW_BRANCH_SUFFIX}`}
|
|
|
|
`('$fn escapes and uses given message="$message"', ({ fn, title, message, messageHTML }) => {
|
|
|
|
expect(fn(message)).toEqual({
|
|
|
|
title,
|
|
|
|
messageHTML,
|
|
|
|
primaryAction: { text: 'Create new branch', callback: expect.any(Function) },
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('parseCommitError', () => {
|
|
|
|
it.each`
|
|
|
|
message | expectation
|
|
|
|
${null} | ${createUnexpectedCommitError()}
|
|
|
|
${{}} | ${createUnexpectedCommitError()}
|
|
|
|
${{ response: {} }} | ${createUnexpectedCommitError()}
|
|
|
|
${{ response: { data: {} } }} | ${createUnexpectedCommitError()}
|
2021-01-03 14:25:43 +05:30
|
|
|
${createResponseError(TEST_MESSAGE)} | ${createUnexpectedCommitError(TEST_MESSAGE)}
|
2020-11-24 15:15:51 +05:30
|
|
|
${createResponseError(CODEOWNERS_MESSAGE)} | ${createCodeownersCommitError(CODEOWNERS_MESSAGE)}
|
|
|
|
${createResponseError(CHANGED_MESSAGE)} | ${createBranchChangedCommitError(CHANGED_MESSAGE)}
|
|
|
|
`('parses message into error object with "$message"', ({ message, expectation }) => {
|
|
|
|
expect(parseCommitError(message)).toEqual(expectation);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|