Skip to content

Commit

Permalink
feat: return json in import, update and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-almeida committed Jul 31, 2023
1 parent 346f64a commit cd49d29
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ OPTIONS
EXAMPLES
$ zcli themes:import ./copenhagen_theme
$ zcli themes:import ./copenhagen_theme --brandId=123456789100
$ zcli themes:import ./copenhagen_theme --brandId=123456
```

## `zcli themes:update [THEMEDIRECTORY]`
Expand Down
10 changes: 8 additions & 2 deletions packages/zcli-themes/src/commands/themes/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import pollJobStatus from '../../lib/pollJobStatus'
export default class Import extends Command {
static description = 'import a theme'

static enableJsonFlag = true

static flags = {
brandId: Flags.string({ description: 'The id of the brand where the theme should be imported to' })
}
Expand All @@ -20,7 +22,7 @@ export default class Import extends Command {

static examples = [
'$ zcli themes:import ./copenhagen_theme',
'$ zcli themes:import ./copenhagen_theme --brandId=123456789100'
'$ zcli themes:import ./copenhagen_theme --brandId=123456'
]

static strict = false
Expand All @@ -42,6 +44,10 @@ export default class Import extends Command {

await pollJobStatus(themePath, job.id)

this.log(chalk.green('Theme imported successfully'), `theme ID: ${job.data.theme_id}`)
const themeId = job.data.theme_id

this.log(chalk.green('Theme imported successfully'), `theme ID: ${themeId}`)

return { themeId }
}
}
3 changes: 3 additions & 0 deletions packages/zcli-themes/src/commands/themes/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as chalk from 'chalk'
export default class Publish extends Command {
static description = 'publish a theme'

static enableJsonFlag = true

static flags = {
themeId: Flags.string({ description: 'The id of the theme to publish' })
}
Expand All @@ -31,6 +33,7 @@ export default class Publish extends Command {
})
CliUx.ux.action.stop('Ok')
this.log(chalk.green('Theme published successfully'), `theme ID: ${themeId}`)
return { themeId }
} catch (e: any) {
const [error] = e.response.data.errors
this.error(`${error.code} - ${error.title}`)
Expand Down
6 changes: 5 additions & 1 deletion packages/zcli-themes/src/commands/themes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import uploadThemePackage from '../../lib/uploadThemePackage'
import pollJobStatus from '../../lib/pollJobStatus'

export default class Update extends Command {
static description = 'import a theme'
static description = 'update a theme'

static enableJsonFlag = true

static flags = {
themeId: Flags.string({ description: 'The id of the theme to update' }),
Expand Down Expand Up @@ -43,5 +45,7 @@ export default class Update extends Command {
await pollJobStatus(themePath, job.id)

this.log(chalk.green('Theme updated successfully'))

return { themeId }
}
}
5 changes: 5 additions & 0 deletions packages/zcli-themes/tests/functional/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
}
30 changes: 14 additions & 16 deletions packages/zcli-themes/tests/functional/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, test } from '@oclif/test'
import * as path from 'path'
import * as nock from 'nock'
import ImportCommand from '../../src/commands/themes/import'
import env from './env'

describe('themes:import', function () {
const baseThemePath = path.join(__dirname, 'mocks/base_theme')
Expand All @@ -19,12 +20,8 @@ describe('themes:import', function () {
}

describe('successful import', () => {
test
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
const success = test
.env(env)
.nock('https://z3ntest.zendesk.com', api => {
api
.post('/api/v2/guide/theming/jobs/themes/imports')
Expand All @@ -39,21 +36,26 @@ describe('themes:import', function () {
.post('/upload/path')
.reply(200)
})

success
.stdout()
.it('should display success message when the theme is imported successfully', async ctx => {
await ImportCommand.run([baseThemePath, '--brandId', '1111'])
expect(ctx.stdout).to.contain('Theme imported successfully theme ID: 1234')
})

success
.stdout()
.it('should return an object containing the theme ID when ran with --json', async ctx => {
await ImportCommand.run([baseThemePath, '--brandId', '1111', '--json'])
expect(ctx.stdout).to.equal(JSON.stringify({ themeId: '1234' }, null, 2) + '\n')
})
})

describe('import failure', () => {
test
.stderr()
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
.env(env)
.nock('https://z3ntest.zendesk.com', api => {
api
.post('/api/v2/guide/theming/jobs/themes/imports')
Expand All @@ -77,11 +79,7 @@ describe('themes:import', function () {
})

test
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
.env(env)
.nock('https://z3ntest.zendesk.com', api => {
api
.post('/api/v2/guide/theming/jobs/themes/imports')
Expand Down
24 changes: 13 additions & 11 deletions packages/zcli-themes/tests/functional/publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import { expect, test } from '@oclif/test'
import PublishCommand from '../../src/commands/themes/publish'
import env from './env'

describe('themes:publish', function () {
describe('successful publish', () => {
test
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
const success = test
.env(env)
.nock('https://z3ntest.zendesk.com', api => api
.post('/api/v2/guide/theming/themes/1234/publish')
.reply(200))

success
.stdout()
.it('should display success message when the theme is published successfully', async ctx => {
await PublishCommand.run(['--themeId', '1234'])
expect(ctx.stdout).to.contain('Theme published successfully theme ID: 1234')
})

success
.stdout()
.it('should return an object containing the theme ID when ran with --json', async ctx => {
await PublishCommand.run(['--themeId', '1234', '--json'])
expect(ctx.stdout).to.equal(JSON.stringify({ themeId: '1234' }, null, 2) + '\n')
})
})

describe('publish failure', () => {
test
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
.env(env)
.nock('https://z3ntest.zendesk.com', api => api
.post('/api/v2/guide/theming/themes/1234/publish')
.reply(400, {
Expand Down
30 changes: 14 additions & 16 deletions packages/zcli-themes/tests/functional/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, test } from '@oclif/test'
import * as path from 'path'
import * as nock from 'nock'
import UpdateCommand from '../../src/commands/themes/update'
import env from './env'

describe('themes:update', function () {
const baseThemePath = path.join(__dirname, 'mocks/base_theme')
Expand All @@ -19,12 +20,8 @@ describe('themes:update', function () {
}

describe('successful update', () => {
test
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
const success = test
.env(env)
.nock('https://z3ntest.zendesk.com', api => {
api
.post('/api/v2/guide/theming/jobs/themes/updates')
Expand All @@ -39,21 +36,26 @@ describe('themes:update', function () {
.post('/upload/path')
.reply(200)
})

success
.stdout()
.it('should display success message when the theme is updated successfully', async ctx => {
await UpdateCommand.run([baseThemePath, '--themeId', '1234'])
expect(ctx.stdout).to.contain('Theme updated successfully')
})

success
.stdout()
.it('should return an object containing the theme ID when ran with --json', async ctx => {
await UpdateCommand.run([baseThemePath, '--themeId', '1234', '--json'])
expect(ctx.stdout).to.equal(JSON.stringify({ themeId: '1234' }, null, 2) + '\n')
})
})

describe('update failure', () => {
test
.stderr()
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
.env(env)
.nock('https://z3ntest.zendesk.com', api => {
api
.post('/api/v2/guide/theming/jobs/themes/updates')
Expand All @@ -77,11 +79,7 @@ describe('themes:update', function () {
})

test
.env({
ZENDESK_SUBDOMAIN: 'z3ntest',
ZENDESK_EMAIL: '[email protected]',
ZENDESK_PASSWORD: '123456' // the universal password
})
.env(env)
.nock('https://z3ntest.zendesk.com', api => {
api
.post('/api/v2/guide/theming/jobs/themes/updates')
Expand Down

0 comments on commit cd49d29

Please sign in to comment.