UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

93 lines (92 loc) 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const test_1 = require("@oclif/test"); const validationErrorsToString = require("./validationErrorsToString"); const errors = require("@oclif/core/lib/errors"); const handleTemplateError_1 = require("./handleTemplateError"); describe('handleTemplateError', () => { beforeEach(() => { sinon.restore(); }); it('transforms template identifiers to template paths and calls error', () => { const validationErrorsToStringStub = sinon.stub(validationErrorsToString, 'default').returns('formatted errors'); const errorStub = sinon.stub(errors, 'error'); const templateErrors = { home_page: [ { description: 'not possible to access `names`', line: 1, column: 45, length: 5 } ], article_page: [ { description: "'articles' does not exist", line: 21, column: 16, length: 11 } ] }; (0, handleTemplateError_1.default)('theme/path', templateErrors); (0, test_1.expect)(validationErrorsToStringStub.calledOnce).to.equal(true); (0, test_1.expect)(validationErrorsToStringStub.firstCall.args[0]).to.equal('theme/path'); const transformedErrors = validationErrorsToStringStub.firstCall.args[1]; (0, test_1.expect)(transformedErrors).to.have.property('templates/home_page.hbs'); (0, test_1.expect)(transformedErrors).to.have.property('templates/article_page.hbs'); (0, test_1.expect)(transformedErrors['templates/home_page.hbs']).to.deep.equal([ { description: 'not possible to access `names`', line: 1, column: 45, length: 5 } ]); (0, test_1.expect)(errorStub.calledOnce).to.equal(true); (0, test_1.expect)(errorStub.firstCall.args[0]).to.contain('InvalidTemplates'); (0, test_1.expect)(errorStub.firstCall.args[0]).to.contain('Template(s) with syntax error(s)'); (0, test_1.expect)(errorStub.firstCall.args[0]).to.contain('formatted errors'); }); it('handles empty template errors', () => { const validationErrorsToStringStub = sinon.stub(validationErrorsToString, 'default').returns(''); const errorStub = sinon.stub(errors, 'error'); (0, handleTemplateError_1.default)('theme/path', {}); (0, test_1.expect)(validationErrorsToStringStub.calledOnce).to.equal(true); (0, test_1.expect)(validationErrorsToStringStub.firstCall.args[1]).to.deep.equal({}); (0, test_1.expect)(errorStub.calledOnce).to.equal(true); }); it('handles single template with multiple errors', () => { const validationErrorsToStringStub = sinon.stub(validationErrorsToString, 'default').returns('multiple errors'); sinon.stub(errors, 'error'); const templateErrors = { new_request_page: [ { description: 'First error', line: 1, column: 1, length: 5 }, { description: 'Second error', line: 10, column: 5, length: 3 }, { description: 'Third error', line: 20, column: 10, length: 7 } ] }; (0, handleTemplateError_1.default)('/my/theme', templateErrors); const transformedErrors = validationErrorsToStringStub.firstCall.args[1]; (0, test_1.expect)(transformedErrors['templates/new_request_page.hbs']).to.have.length(3); (0, test_1.expect)(transformedErrors['templates/new_request_page.hbs'][0].description).to.equal('First error'); (0, test_1.expect)(transformedErrors['templates/new_request_page.hbs'][1].description).to.equal('Second error'); (0, test_1.expect)(transformedErrors['templates/new_request_page.hbs'][2].description).to.equal('Third error'); }); });