-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd49d29
commit 52d8fd7
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Command, Flags, CliUx } from '@oclif/core' | ||
import { request } from '@zendesk/zcli-core' | ||
import * as chalk from 'chalk' | ||
import getBrandId from '../../lib/getBrandId' | ||
|
||
export default class List extends Command { | ||
static description = 'list installed themes' | ||
|
||
static enableJsonFlag = true | ||
|
||
static flags = { | ||
brandId: Flags.string({ description: 'The id of the brand where the themes are installed' }) | ||
} | ||
|
||
static examples = [ | ||
'$ zcli themes:list --brandId=123456' | ||
] | ||
|
||
static strict = false | ||
|
||
async run () { | ||
let { flags: { brandId } } = await this.parse(List) | ||
|
||
brandId = brandId || await getBrandId() | ||
|
||
try { | ||
CliUx.ux.action.start('Listing themes') | ||
const { data: { themes } } = await request.requestAPI(`/api/v2/guide/theming/themes?brand_id=${brandId}`, { | ||
headers: { | ||
'X-Zendesk-Request-Originator': 'zcli themes:list' | ||
}, | ||
validateStatus: (status: number) => status === 200 | ||
}) | ||
CliUx.ux.action.stop('Ok') | ||
this.log(chalk.green('Themes listed successfully'), themes) | ||
return { themes } | ||
} catch (e: any) { | ||
const [error] = e.response.data.errors | ||
this.error(`${error.code} - ${error.title}`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expect, test } from '@oclif/test' | ||
import ListCommand from '../../src/commands/themes/list' | ||
import env from './env' | ||
|
||
describe('themes:list', function () { | ||
describe('successful list', () => { | ||
const success = test | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => api | ||
.get('/api/v2/guide/theming/themes?brand_id=1111') | ||
.reply(200, { themes: [] })) | ||
|
||
success | ||
.stdout() | ||
.it('should display success message when thes themes are listed successfully', async ctx => { | ||
await ListCommand.run(['--brandId', '1111']) | ||
expect(ctx.stdout).to.contain('Themes listed successfully []') | ||
}) | ||
|
||
success | ||
.stdout() | ||
.it('should return an object containing the theme ID when ran with --json', async ctx => { | ||
await ListCommand.run(['--brandId', '1111', '--json']) | ||
expect(ctx.stdout).to.equal(JSON.stringify({ themes: [] }, null, 2) + '\n') | ||
}) | ||
}) | ||
|
||
describe('list failure', () => { | ||
test | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => api | ||
.get('/api/v2/guide/theming/themes?brand_id=1111') | ||
.reply(500, { | ||
errors: [{ | ||
code: 'InternalError', | ||
title: 'Something went wrong' | ||
}] | ||
})) | ||
.stderr() | ||
.it('should report publish errors', async ctx => { | ||
try { | ||
await ListCommand.run(['--brandId', '1111']) | ||
} catch (error) { | ||
expect(ctx.stderr).to.contain('!') | ||
expect(error.message).to.contain('InternalError - Something went wrong') | ||
} | ||
}) | ||
}) | ||
}) |