-
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
415b5e1
commit e4eb869
Showing
8 changed files
with
40 additions
and
87 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import * as createAppUtils from '../../src/utils/createApp' | |
import * as appConfig from '../../src/utils/appConfig' | ||
import * as requestUtils from '../../../zcli-core/src/lib/requestUtils' | ||
import * as packageUtil from '../../src/lib/package' | ||
import env from './env' | ||
|
||
describe('apps', function () { | ||
const singleProductApp = path.join(__dirname, 'mocks/single_product_app') | ||
|
@@ -27,11 +28,7 @@ describe('apps', function () { | |
.stub(createAppUtils, 'getManifestAppName', () => 'importantAppName') | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve('z3ntest')) | ||
.stub(appConfig, 'setConfig', () => Promise.resolve()) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 817 }) | ||
|
@@ -67,11 +64,7 @@ describe('apps', function () { | |
describe('with single app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
@@ -97,11 +90,7 @@ describe('apps', function () { | |
describe('with requirements-only app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
@@ -126,11 +115,7 @@ describe('apps', function () { | |
describe('with single app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
@@ -153,11 +138,7 @@ describe('apps', function () { | |
describe('with requirements-only app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
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,5 @@ | ||
export default { | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_API_TOKEN: '123456' | ||
} |
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 |
---|---|---|
|
@@ -3,15 +3,12 @@ import * as path from 'path' | |
import * as fs from 'fs' | ||
import * as readline from 'readline' | ||
import * as AdmZip from 'adm-zip' | ||
import env from './env' | ||
|
||
describe('package', function () { | ||
const appPath = path.join(__dirname, 'mocks/single_product_app') | ||
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/apps/validate') | ||
|
@@ -25,11 +22,7 @@ describe('package', 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/apps/validate') | ||
|
@@ -69,11 +62,7 @@ describe('zcliignore', 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/apps/validate') | ||
|
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import { expect, test } from '@oclif/test' | ||
import * as path from 'path' | ||
import env from './env' | ||
|
||
describe('validate', 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/apps/validate') | ||
|
@@ -20,11 +17,7 @@ describe('validate', 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/apps/validate') | ||
|
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 |
---|---|---|
|
@@ -6,18 +6,14 @@ import Auth from './auth' | |
import SecureStore from './secureStore' | ||
import { Profile } from '../types' | ||
|
||
const mockCreateBasicAuthToken = (...args: any[]) => { | ||
return `Basic ${args[0]}_${args[1]}_base64` | ||
} | ||
|
||
describe('Auth', () => { | ||
describe('createBasicAuthToken', () => { | ||
test | ||
.it('should create basic auth token', async () => { | ||
const auth = new Auth() | ||
expect( | ||
await auth.createBasicAuthToken('[email protected]', '123456') | ||
).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbToxMjM0NTY=') | ||
).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
}) | ||
}) | ||
|
||
|
@@ -35,19 +31,8 @@ describe('Auth', () => { | |
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_API_TOKEN: 'test_api_token' | ||
}) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.it('should return basic token if ZENDESK_EMAIL and ZENDESK_API_TOKEN is set', async () => { | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic [email protected]/token_test_api_token_base64') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' | ||
}) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.it('should return basic token if ZENDESK_EMAIL and ZENDESK_PASSWORD is set', async () => { | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic [email protected]_123456_base64') | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjp0ZXN0X2FwaV90b2tlbg==') | ||
}) | ||
|
||
test | ||
|
@@ -74,10 +59,20 @@ describe('Auth', () => { | |
ZENDESK_API_TOKEN: 'test_api_token', | ||
ZENDESK_PASSWORD: '123456' | ||
}) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.it('should give precedence to ZENDESK_EMAIL and ZENDESK_API_TOKEN when ZENDESK_OAUTH_TOKEN is not defined', async () => { | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic [email protected]/token_test_api_token_base64') | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjp0ZXN0X2FwaV90b2tlbg==') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' | ||
}) | ||
.do(async () => { | ||
await auth.getAuthorizationToken() | ||
}) | ||
.catch(chalk.red('Basic authentication of type \'password\' is not supported.')) | ||
.it('should throw an error if only ZENDESK_EMAIL and ZENDESK_PASSWORD are set - basic auth with password not supported') | ||
}) | ||
|
||
describe('loginInteractively', () => { | ||
|
@@ -93,12 +88,11 @@ describe('Auth', () => { | |
.stub(CliUx.ux, 'prompt', () => promptStub) | ||
.stub(auth.secureStore, 'setPassword', () => Promise.resolve()) | ||
.stub(auth, 'setLoggedInProfile', () => Promise.resolve()) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.get('/api/v2/account/settings.json') | ||
.reply(function () { | ||
expect(this.req.headers.authorization).to.equal('Basic [email protected]_123456_base64') | ||
expect(this.req.headers.authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
return [200] | ||
}) | ||
}) | ||
|
@@ -116,12 +110,11 @@ describe('Auth', () => { | |
.stub(CliUx.ux, 'prompt', () => promptStub) | ||
.stub(auth.secureStore, 'setPassword', () => Promise.resolve()) | ||
.stub(auth, 'setLoggedInProfile', () => Promise.resolve()) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.nock('https://z3ntest.example.com', api => { | ||
api | ||
.get('/api/v2/account/settings.json') | ||
.reply(function () { | ||
expect(this.req.headers.authorization).to.equal('Basic [email protected]_123456_base64') | ||
expect(this.req.headers.authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
return [200] | ||
}) | ||
}) | ||
|
@@ -138,12 +131,11 @@ describe('Auth', () => { | |
.stub(CliUx.ux, 'prompt', () => promptStub) | ||
.stub(auth.secureStore, 'setPassword', () => Promise.resolve()) | ||
.stub(auth, 'setLoggedInProfile', () => Promise.resolve()) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.nock('https://z3ntest.example.com', api => { | ||
api | ||
.get('/api/v2/account/settings.json') | ||
.reply(function () { | ||
expect(this.req.headers.authorization).to.equal('Basic [email protected]_123456_base64') | ||
expect(this.req.headers.authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
return [200] | ||
}) | ||
}) | ||
|
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default { | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
ZENDESK_API_TOKEN: '123456' | ||
} |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import * as nock from 'nock' | |
import axios from 'axios' | ||
import { cloneDeep } from 'lodash' | ||
import PreviewCommand from '../../src/commands/themes/preview' | ||
import env from './env' | ||
|
||
describe('themes:preview', function () { | ||
const baseThemePath = path.join(__dirname, 'mocks/base_theme') | ||
|
@@ -15,11 +16,7 @@ describe('themes:preview', function () { | |
|
||
const preview = test | ||
.stdout() | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.put('/hc/api/internal/theming/local_preview') | ||
|
@@ -79,11 +76,7 @@ describe('themes:preview', function () { | |
|
||
test | ||
.stdout() | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.it('should report template errors', async (ctx) => { | ||
nock('https://z3ntest.zendesk.com').put('/hc/api/internal/theming/local_preview').reply(400, { | ||
template_errors: { | ||
|