-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-core): add file upload delivery batch api
- Loading branch information
Christie Baker
authored and
Christie Baker
committed
Nov 19, 2018
1 parent
6b1f68e
commit eff0a3c
Showing
10 changed files
with
178 additions
and
1 deletion.
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,11 @@ | ||
import angular from 'angular'; | ||
|
||
import { AvFilesDelivery } from '@availity/api-core'; | ||
|
||
export default ($http, $q, avApiOptions) => | ||
new AvFilesDelivery({ | ||
http: $http, | ||
promise: $q, | ||
merge: angular.merge, | ||
config: angular.copy(avApiOptions), | ||
}); |
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,11 @@ | ||
import axios from 'axios'; | ||
import utils from 'axios/lib/utils'; | ||
import { AvFilesDelivery } from '@availity/api-core'; | ||
|
||
const { merge } = utils; | ||
|
||
export default new AvFilesDelivery({ | ||
http: axios, | ||
promise: Promise, | ||
merge, | ||
}); |
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,39 @@ | ||
import AvMicroservice from '../ms'; | ||
|
||
export default class AvFilesDelivery extends AvMicroservice { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
{ | ||
name: 'platform/file-upload-delivery/v1/batch/deliveries', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
polling: true, | ||
pollingMethod: 'GET', | ||
}, | ||
config | ||
); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
|
||
uploadFilesDelivery(data, config) { | ||
if (!config.customerId || !config.clientId) { | ||
throw Error('[config.customerId] and [config.clientId] must be defined'); | ||
} | ||
config = this.config(config); | ||
config.headers['X-Availity-Customer-ID'] = config.customerId; | ||
config.headers['X-Client-ID'] = config.clientId; | ||
|
||
return this.create(data || {}, config); | ||
} | ||
|
||
getLocation(response) { | ||
const baseUrl = super.getLocation(response.config); | ||
return `${baseUrl}/${response.data.id}`; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/api-core/src/resources/tests/filesDelivery.test.js
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,71 @@ | ||
import AvFilesDelivery from '../filesDelivery'; | ||
|
||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
|
||
const mockConfig = { | ||
clientId: '123-456', | ||
customerId: '1194', | ||
}; | ||
|
||
describe('AvFileDelivery', () => { | ||
let api; | ||
|
||
test('should be defined', () => { | ||
api = new AvFilesDelivery({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
}); | ||
|
||
test('should handle no config passed in', () => { | ||
api = new AvFilesDelivery({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
}); | ||
|
||
test('post url should be correct', () => { | ||
api = new AvFilesDelivery({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api.getUrl(mockConfig)).toBe( | ||
'/ms/api/availity/internal/platform/file-upload-delivery/v1/batch/deliveries' | ||
); | ||
}); | ||
|
||
test('uploadFile() should call create for reference passed', () => { | ||
api = new AvFilesDelivery({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
|
||
const data = { | ||
deliveries: [ | ||
{ | ||
fileURI: 'uri', | ||
deliveryChannel: 'DEMO', | ||
metadata: { | ||
payerId: 'test_payerId', | ||
requestId: '123', | ||
patientLastName: 'lastName', | ||
patientFirstName: 'firstName', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
api.create = jest.fn(); | ||
api.uploadFilesDelivery(data, mockConfig); | ||
expect(api.create).toHaveBeenLastCalledWith(data, api.config(mockConfig)); | ||
}); | ||
}); |