-
Notifications
You must be signed in to change notification settings - Fork 23
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
83f0b5f
commit 6e7bbb7
Showing
3 changed files
with
84 additions
and
80 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
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,93 +1,96 @@ | ||
import { expect, test } from '@oclif/test' | ||
import { createRequestConfig, requestAPI } from './request' | ||
import Auth from './auth' | ||
import { HttpStatusCode } from 'axios' | ||
import { createRequestConfig } from './request' | ||
import * as requestUtils from './requestUtils' | ||
// import { createRequestConfig, requestAPI } from './request' | ||
// import Auth from './auth' | ||
// import { HttpStatusCode } from 'axios' | ||
|
||
describe('createRequestConfig', () => { | ||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_OAUTH_TOKEN: 'good_token' | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => 'fake') | ||
.stub(requestUtils, 'getDomain', () => 'fake.com') | ||
.it('should create a request with an OAuth token', async () => { | ||
const req = await createRequestConfig('api/v2/me') | ||
console.log('req: ', req) | ||
expect(req.headers.Authorization).to.equal('Bearer good_token') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_OAUTH_TOKEN: 'good_token' | ||
}) | ||
.it('should be able to attach extra headers to request', async () => { | ||
const req = await createRequestConfig('api/v2/me', { | ||
headers: { foo: 'bar' }, | ||
method: 'GET' | ||
}) | ||
expect(req.headers.Authorization).to.equal('Bearer good_token') | ||
expect(req.headers.foo).to.equal('bar') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_DOMAIN: 'expected.com', | ||
ZENDESK_EMAIL: 'test@zendesk.com', | ||
ZENDESK_API_TOKEN: '123456' | ||
}) | ||
.it('should be able to create a request with a Basic auth token', async () => { | ||
const req = await createRequestConfig('api/v2/me', {}) | ||
expect(req.headers.Authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_DOMAIN: 'expected.com', | ||
ZENDESK_EMAIL: 'test@zendesk.com', | ||
ZENDESK_API_TOKEN: '123456' | ||
}) | ||
.stub(Auth, 'getLoggedInProfile', () => ({ | ||
subdomain: 'fake', | ||
domain: 'fake.com' | ||
})) | ||
.it('should create a request with the correct domain', async () => { | ||
const req = await createRequestConfig('api/v2/me') | ||
expect(req.baseURL).to.equal('https://z3ntest.expected.com') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: 'test@zendesk.com', | ||
ZENDESK_API_TOKEN: '123456' | ||
}) | ||
.stub(Auth, 'getLoggedInProfile', () => ({ | ||
subdomain: 'fake', | ||
domain: 'fake.com' | ||
})) | ||
.it('should use the default domain if ZENDESK_SUBDOMAIN is provided and ZENDESK_DOMAIN is not provided, not the profile domain', async () => { | ||
const req = await createRequestConfig('api/v2/me') | ||
expect(req.baseURL).to.equal('https://z3ntest.zendesk.com') | ||
}) | ||
// test | ||
// .env({ | ||
// ZENDESK_SUBDOMAIN: 'z3ntest', | ||
// ZENDESK_OAUTH_TOKEN: 'good_token' | ||
// }) | ||
// .it('should be able to attach extra headers to request', async () => { | ||
// const req = await createRequestConfig('api/v2/me', { | ||
// headers: { foo: 'bar' }, | ||
// method: 'GET' | ||
// }) | ||
// expect(req.headers.Authorization).to.equal('Bearer good_token') | ||
// expect(req.headers.foo).to.equal('bar') | ||
// }) | ||
// | ||
// test | ||
// .env({ | ||
// ZENDESK_SUBDOMAIN: 'z3ntest', | ||
// ZENDESK_DOMAIN: 'expected.com', | ||
// ZENDESK_EMAIL: 'test@zendesk.com', | ||
// ZENDESK_API_TOKEN: '123456' | ||
// }) | ||
// .it('should be able to create a request with a Basic auth token', async () => { | ||
// const req = await createRequestConfig('api/v2/me', {}) | ||
// expect(req.headers.Authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
// }) | ||
// | ||
// test | ||
// .env({ | ||
// ZENDESK_SUBDOMAIN: 'z3ntest', | ||
// ZENDESK_DOMAIN: 'expected.com', | ||
// ZENDESK_EMAIL: 'test@zendesk.com', | ||
// ZENDESK_API_TOKEN: '123456' | ||
// }) | ||
// .stub(Auth, 'getLoggedInProfile', () => ({ | ||
// subdomain: 'fake', | ||
// domain: 'fake.com' | ||
// })) | ||
// .it('should create a request with the correct domain', async () => { | ||
// const req = await createRequestConfig('api/v2/me') | ||
// expect(req.baseURL).to.equal('https://z3ntest.expected.com') | ||
// }) | ||
// | ||
// test | ||
// .env({ | ||
// ZENDESK_SUBDOMAIN: 'z3ntest', | ||
// ZENDESK_EMAIL: 'test@zendesk.com', | ||
// ZENDESK_API_TOKEN: '123456' | ||
// }) | ||
// .stub(Auth, 'getLoggedInProfile', () => ({ | ||
// subdomain: 'fake', | ||
// domain: 'fake.com' | ||
// })) | ||
// .it('should use the default domain if ZENDESK_SUBDOMAIN is provided and ZENDESK_DOMAIN is not provided, not the profile domain', async () => { | ||
// const req = await createRequestConfig('api/v2/me') | ||
// expect(req.baseURL).to.equal('https://z3ntest.zendesk.com') | ||
// }) | ||
}) | ||
|
||
describe('requestAPI', () => { | ||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: 'test@zendesk.com', | ||
ZENDESK_API_TOKEN: '123456', | ||
ZENDESK_OAUTH_TOKEN: 'good_token' | ||
}) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.get('/api/v2/me') | ||
.reply(HttpStatusCode.Ok) | ||
}) | ||
.it('should call an http endpoint', async () => { | ||
const response = await requestAPI('api/v2/me', { method: 'GET' }) | ||
expect(response.status).to.equal(HttpStatusCode.Ok) | ||
}) | ||
}) | ||
// describe('requestAPI', () => { | ||
// test | ||
// .env({ | ||
// ZENDESK_SUBDOMAIN: 'z3ntest', | ||
// ZENDESK_EMAIL: 'test@zendesk.com', | ||
// ZENDESK_API_TOKEN: '123456', | ||
// ZENDESK_OAUTH_TOKEN: 'good_token' | ||
// }) | ||
// .nock('https://z3ntest.zendesk.com', api => { | ||
// api | ||
// .get('/api/v2/me') | ||
// .reply(HttpStatusCode.Ok) | ||
// }) | ||
// .it('should call an http endpoint', async () => { | ||
// const response = await requestAPI('api/v2/me', { method: 'GET' }) | ||
// expect(response.status).to.equal(HttpStatusCode.Ok) | ||
// }) | ||
// }) |
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