UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

52 lines (51 loc) 1.95 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 getBrandId_1 = require("./getBrandId"); const inquirer = require("inquirer"); const errors = require("@oclif/core/lib/errors"); describe('getBrandId', () => { beforeEach(() => { sinon.restore(); }); it('returns the brandId of the first brand when there\' only one brand', async () => { const requestStub = sinon.stub(zcli_core_1.request, 'requestAPI'); requestStub.returns(Promise.resolve({ data: { brands: [{ id: 1234 }] } })); const brandId = await (0, getBrandId_1.default)(); (0, test_1.expect)(brandId).to.equal('1234'); }); it('prompts the user when there are multiple brands', async () => { const requestStub = sinon.stub(zcli_core_1.request, 'requestAPI'); const promptStub = sinon.stub(inquirer, 'prompt'); requestStub.returns(Promise.resolve({ data: { brands: [ { id: 1111, name: 'Brand 1' }, { id: 2222, name: 'Brand 2' } ] } })); promptStub.returns(Promise.resolve({ brandId: '2222' })); const brandId = await (0, getBrandId_1.default)(); (0, test_1.expect)(brandId).to.equal('2222'); }); it('handles failure when requesting brands', async () => { const requestStub = sinon.stub(zcli_core_1.request, 'requestAPI'); const errorStub = sinon.stub(errors, 'error'); requestStub.throws(); try { await (0, getBrandId_1.default)(); } catch (_a) { (0, test_1.expect)(errorStub.calledWith('Failed to retrieve brands')).to.equal(true); } }); });