-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor JiraService to AddonService and fix IoC
- Loading branch information
Marcelo Mendonça
committed
Jun 11, 2019
1 parent
d6b7b85
commit f69960e
Showing
32 changed files
with
392 additions
and
277 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 |
---|---|---|
|
@@ -22,4 +22,4 @@ suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe | |
[strict] | ||
|
||
[version] | ||
0.93.0 | ||
0.100.0 |
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
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @flow | ||
import { promisify } from 'util'; | ||
import { getBodyJson } from '../utils/addonService'; | ||
import type { AddonServiceInterface, JiraApiResponse, ACEHttp } from '../types'; | ||
|
||
/** | ||
* Wrapper around Jira's HTTP Client | ||
* https://developer.atlassian.com/cloud/jira/platform/rest/v2/ | ||
* | ||
* @export | ||
* @class AddonService | ||
*/ | ||
export default class AddonService implements AddonServiceInterface { | ||
_http: ACEHttp; | ||
|
||
_put: (...args: any) => Promise<any>; | ||
|
||
_post: (...args: any) => Promise<any>; | ||
|
||
_get: (...args: any) => Promise<any>; | ||
|
||
_del: (...args: any) => Promise<any>; | ||
|
||
async get(...args: any): Promise<JiraApiResponse> { | ||
return getBodyJson(this._get(...args)); | ||
} | ||
|
||
async put(...args: any): Promise<JiraApiResponse> { | ||
return getBodyJson(this._put(...args)); | ||
} | ||
|
||
async post(...args: any): Promise<JiraApiResponse> { | ||
return getBodyJson(this._post(...args)); | ||
} | ||
|
||
async _del(...args: any): Promise<JiraApiResponse> { | ||
return getBodyJson(this._del(...args)); | ||
} | ||
|
||
constructor(http: ACEHttp) { | ||
this._http = http; | ||
// promisify ace's get and post functions | ||
this._get = promisify(this._http.get).bind(this._http); | ||
this._put = promisify(this._http.put).bind(this._http); | ||
this._post = promisify(this._http.post).bind(this._http); | ||
this._del = promisify(this._http.del).bind(this._http); | ||
} | ||
|
||
asUserByAccountId(userAccountId: string): Function { | ||
return this._http.asUserByAccountId(userAccountId); | ||
} | ||
} |
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,6 @@ | ||
// @flow | ||
import AddonService from './AddonService'; | ||
import type { ACEHttp } from '../types'; | ||
|
||
|
||
export default (http: ACEHttp) => new AddonService(http); |
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,36 @@ | ||
import { createSandbox } from 'sinon'; | ||
import chai, { expect } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import AddonService from '../AddonService'; | ||
|
||
chai.use(sinonChai); | ||
const sandbox = createSandbox(); | ||
|
||
describe('JiraIssue Domain', () => { | ||
const response = { body: JSON.stringify({ foo: 'bar' }) }; | ||
const httpMock = { | ||
get: (args, cb) => cb(null, response), | ||
put: (args, cb) => cb(null, response), | ||
post: (args, cb) => cb(null, response), | ||
del: (args, cb) => cb(null, response), | ||
}; | ||
const underTest = new AddonService(httpMock); | ||
beforeEach(() => { }); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('getIssues', () => { | ||
it('parses response body', async () => { | ||
const getResponse = await underTest.get('/nowhere'); | ||
const putResponse = await underTest.get('/nowhere'); | ||
const postResponse = await underTest.get('/nowhere'); | ||
const delResponse = await underTest.get('/nowhere'); | ||
expect(getResponse).to.be.eql({ foo: 'bar' }); | ||
expect(putResponse).to.be.eql({ foo: 'bar' }); | ||
expect(postResponse).to.be.eql({ foo: 'bar' }); | ||
expect(delResponse).to.be.eql({ foo: 'bar' }); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.