UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

99 lines (98 loc) 5.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const test_1 = require("@oclif/test"); const zcli_core_1 = require("@zendesk/zcli-core"); const pollJobStatus_1 = require("./pollJobStatus"); const chalk = require("chalk"); const errors = require("@oclif/core/lib/errors"); describe('pollJobStatus', () => { beforeEach(() => { sinon.restore(); }); it('polls the jobs/{jobId} endpoint until the job is completed', async () => { const requestStub = sinon.stub(zcli_core_1.request, 'requestAPI'); requestStub .onFirstCall() .returns(Promise.resolve({ data: { job: { status: 'pending' } } })) .onSecondCall() .returns(Promise.resolve({ data: { job: { status: 'pending' } } })) .onThirdCall() .returns(Promise.resolve({ data: { job: { status: 'completed', theme_id: '1234' } } })); await (0, pollJobStatus_1.default)('theme/path', '9999', 10); (0, test_1.expect)(requestStub.calledWith('/api/v2/guide/theming/jobs/9999')).to.equal(true); (0, test_1.expect)(requestStub.callCount).to.equal(3); }); it('times out after the specified number of retries', async () => { const requestStub = sinon.stub(zcli_core_1.request, 'requestAPI'); const errorStub = sinon.stub(errors, 'error'); requestStub .onFirstCall() .returns(Promise.resolve({ data: { job: { status: 'pending' } } })) .onSecondCall() .returns(Promise.resolve({ data: { job: { status: 'pending' } } })) .onThirdCall() .returns(Promise.resolve({ data: { job: { status: 'pending' } } })); await (0, pollJobStatus_1.default)('theme/path', '9999', 10, 3); (0, test_1.expect)(requestStub.callCount).to.equal(3); (0, test_1.expect)(errorStub.calledWith('Import job timed out')).to.equal(true); }); it('handles job errors', async () => { const requestStub = sinon.stub(zcli_core_1.request, 'requestAPI'); const errorStub = sinon.stub(errors, 'error').callThrough(); requestStub .onFirstCall() .returns(Promise.resolve({ data: { job: { status: 'pending' } } })) .onSecondCall() .returns(Promise.resolve({ data: { job: { status: 'failed', errors: [ { message: 'Template(s) with syntax error(s)', code: 'InvalidTemplates', meta: { 'templates/home_page.hbs': [ { description: 'not possible to access `names` in `help_center.names`', line: 1, column: 45, length: 5 }, { description: "'articles' does not exist", line: 21, column: 16, length: 11 } ], 'templates/new_request_page.hbs': [ { description: "'post_form' does not exist", line: 22, column: 6, length: 10 } ] } } ] } } })); try { await (0, pollJobStatus_1.default)('theme/path', '9999', 10, 2); } catch (_a) { (0, test_1.expect)(requestStub.callCount).to.equal(2); (0, test_1.expect)(errorStub.calledWithMatch('Template(s) with syntax error(s)')).to.equal(true); (0, test_1.expect)(errorStub.calledWithMatch(`${chalk.bold('Validation error')} theme/path/templates/home_page.hbs:1:45`)).to.equal(true); (0, test_1.expect)(errorStub.calledWithMatch('not possible to access `names` in `help_center.names`')).to.equal(true); (0, test_1.expect)(errorStub.calledWithMatch(`${chalk.bold('Validation error')} theme/path/templates/home_page.hbs:21:16`)).to.equal(true); (0, test_1.expect)(errorStub.calledWithMatch("'articles' does not exist")).to.equal(true); (0, test_1.expect)(errorStub.calledWithMatch(`${chalk.bold('Validation error')} theme/path/templates/new_request_page.hbs:22:6`)).to.equal(true); (0, test_1.expect)(errorStub.calledWithMatch("'post_form' does not exist")).to.equal(true); } }); });