Skip to content

Commit eff0a3c

Browse files
Christie BakerChristie Baker
authored andcommitted
feat(api-core): add file upload delivery batch api
1 parent 6b1f68e commit eff0a3c

File tree

10 files changed

+178
-1
lines changed

10 files changed

+178
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import angular from 'angular';
2+
3+
import { AvFilesDelivery } from '@availity/api-core';
4+
5+
export default ($http, $q, avApiOptions) =>
6+
new AvFilesDelivery({
7+
http: $http,
8+
promise: $q,
9+
merge: angular.merge,
10+
config: angular.copy(avApiOptions),
11+
});

packages/api-angular/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import avSpacesApiFactory from './spaces';
1717
import avUsersApiFactory from './user';
1818
import avUserPermissionsApiFactory from './userPermissions';
1919
import avFilesApiFactory from './files';
20+
import avFilesDeliveryApiFactory from './filesDelivery';
2021
import avSettingsApiFactory from './settings';
2122

2223
export default angular
@@ -37,4 +38,5 @@ export default angular
3738
.factory('avUsersApi', avUsersApiFactory)
3839
.factory('avUserPermissionsApi', avUserPermissionsApiFactory)
3940
.factory('avFilesApi', avFilesApiFactory)
41+
.factory('avFilesDeliveryApi', avFilesDeliveryApiFactory)
4042
.factory('avSettingsApi', avSettingsApiFactory).name;

packages/api-angular/src/tests/api.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,20 @@ describe('Api Definitions Angular', () => {
127127
});
128128
expect(avSettingsApi).toBeDefined();
129129
});
130+
131+
test('avFilesApi should be defined', () => {
132+
let avFilesApi;
133+
angular.mock.inject(_avFilesApi_ => {
134+
avFilesApi = _avFilesApi_;
135+
});
136+
expect(avFilesApi).toBeDefined();
137+
});
138+
139+
test('avFileDeliveryApi should be defined', () => {
140+
let avFilesDeliveryApi;
141+
angular.mock.inject(_avFilesDeliveryApi_ => {
142+
avFilesDeliveryApi = _avFilesDeliveryApi_;
143+
});
144+
expect(avFilesDeliveryApi).toBeDefined();
145+
});
130146
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import axios from 'axios';
2+
import utils from 'axios/lib/utils';
3+
import { AvFilesDelivery } from '@availity/api-core';
4+
5+
const { merge } = utils;
6+
7+
export default new AvFilesDelivery({
8+
http: axios,
9+
promise: Promise,
10+
merge,
11+
});

packages/api-axios/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import avUserApi from './user';
1313
import avPdfApi from './pdf';
1414
import avUserPermissionsApi from './userPermissions';
1515
import avFilesApi from './files';
16+
import avFilesDeliveryApi from './filesDelivery';
1617
import avSettingsApi from './settings';
1718

1819
export default AvApi;
@@ -32,5 +33,6 @@ export {
3233
avUserApi,
3334
avUserPermissionsApi,
3435
avFilesApi,
36+
avFilesDeliveryApi,
3537
avSettingsApi,
3638
};

packages/api-axios/src/tests/api.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Api, {
1212
avUserApi,
1313
avUserPermissionsApi,
1414
avFilesApi,
15+
avFilesDeliveryApi,
1516
avSettingsApi,
1617
} from '../';
1718

@@ -39,6 +40,7 @@ describe('API Definitions', () => {
3940
expect(avUserApi).toBeDefined();
4041
expect(avUserPermissionsApi).toBeDefined();
4142
expect(avFilesApi).toBeDefined();
43+
expect(avFilesDeliveryApi).toBeDefined();
4244
expect(avSettingsApi).toBeDefined();
4345
});
4446
});

packages/api-core/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import AvSpaces from './resources/spaces';
1313
import AvUsers from './resources/user';
1414
import AvUserPermissions from './resources/userPermissions';
1515
import AvFiles from './resources/files';
16+
import AvFilesDelivery from './resources/filesDelivery';
1617
import AvSettings from './resources/settings';
1718

1819
export default AvApi;
@@ -32,5 +33,6 @@ export {
3233
AvUsers,
3334
AvUserPermissions,
3435
AvFiles,
36+
AvFilesDelivery,
3537
AvSettings,
3638
};

packages/api-core/src/resources/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [AvLogMessage](#avlogmessage)
1515
* [AvProxy](#avproxy)
1616
* [AvFiles](#avfiles)
17+
* [AvFilesDelivery](#avfilesdelivery)
1718
* [AvSettings](#avsettings)
1819

1920
## Intro
@@ -25,7 +26,7 @@ Get information about current logged in user.
2526

2627
#### Methods
2728

28-
##### `me()`
29+
##### `me()`
2930
Helper function that returns information about logged in user.
3031

3132
### AvRegions
@@ -100,6 +101,26 @@ Upload a file to a bucket in the vault
100101
Method to upload a file. `data` contains FormData elements with a key of either `reference` (if pointed to an existing file) or `filedata` (if uploading a new file)
101102
`config` should contain `customerId`, `id` (the bucketId), and `clientId`
102103

104+
### AvFilesDelivery
105+
Upload a batch of files to a designated channel configured on the server.
106+
107+
#### Methods
108+
109+
#### `uploadFilesDelivery(data, config)`
110+
Method to upload a batch of file deliveries. `data` contains an array of `deliveries`. Provide the `fileUri` (reference field from AvFiles), `deliveryChannel`, and the required `metadata` for that channel.
111+
112+
Example:
113+
```html
114+
data = {
115+
deliveries:
116+
[ {
117+
fileURI: upload.references[0],
118+
deliveryChannel: 'DEMO',
119+
metadata: { payerId: "DEMOPAYERID", requestId: "123", patientLastName: "lastName", patientFirstName: "firstName" },
120+
} ]
121+
};
122+
```
123+
`config` should contain `customerId` and `clientId`
103124

104125
### AvSettings
105126
Store and retrieve settings to be reused.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import AvMicroservice from '../ms';
2+
3+
export default class AvFilesDelivery extends AvMicroservice {
4+
constructor({ http, promise, merge, config }) {
5+
const options = Object.assign(
6+
{
7+
name: 'platform/file-upload-delivery/v1/batch/deliveries',
8+
headers: {
9+
'Content-Type': 'application/json',
10+
},
11+
polling: true,
12+
pollingMethod: 'GET',
13+
},
14+
config
15+
);
16+
super({
17+
http,
18+
promise,
19+
merge,
20+
config: options,
21+
});
22+
}
23+
24+
uploadFilesDelivery(data, config) {
25+
if (!config.customerId || !config.clientId) {
26+
throw Error('[config.customerId] and [config.clientId] must be defined');
27+
}
28+
config = this.config(config);
29+
config.headers['X-Availity-Customer-ID'] = config.customerId;
30+
config.headers['X-Client-ID'] = config.clientId;
31+
32+
return this.create(data || {}, config);
33+
}
34+
35+
getLocation(response) {
36+
const baseUrl = super.getLocation(response.config);
37+
return `${baseUrl}/${response.data.id}`;
38+
}
39+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import AvFilesDelivery from '../filesDelivery';
2+
3+
const mockHttp = jest.fn(() => Promise.resolve({}));
4+
const mockMerge = jest.fn((...args) => Object.assign(...args));
5+
6+
const mockConfig = {
7+
clientId: '123-456',
8+
customerId: '1194',
9+
};
10+
11+
describe('AvFileDelivery', () => {
12+
let api;
13+
14+
test('should be defined', () => {
15+
api = new AvFilesDelivery({
16+
http: mockHttp,
17+
promise: Promise,
18+
merge: mockMerge,
19+
config: {},
20+
});
21+
expect(api).toBeDefined();
22+
});
23+
24+
test('should handle no config passed in', () => {
25+
api = new AvFilesDelivery({
26+
http: mockHttp,
27+
promise: Promise,
28+
merge: mockMerge,
29+
});
30+
expect(api).toBeDefined();
31+
});
32+
33+
test('post url should be correct', () => {
34+
api = new AvFilesDelivery({
35+
http: mockHttp,
36+
promise: Promise,
37+
merge: mockMerge,
38+
});
39+
expect(api.getUrl(mockConfig)).toBe(
40+
'/ms/api/availity/internal/platform/file-upload-delivery/v1/batch/deliveries'
41+
);
42+
});
43+
44+
test('uploadFile() should call create for reference passed', () => {
45+
api = new AvFilesDelivery({
46+
http: mockHttp,
47+
promise: Promise,
48+
merge: mockMerge,
49+
config: {},
50+
});
51+
52+
const data = {
53+
deliveries: [
54+
{
55+
fileURI: 'uri',
56+
deliveryChannel: 'DEMO',
57+
metadata: {
58+
payerId: 'test_payerId',
59+
requestId: '123',
60+
patientLastName: 'lastName',
61+
patientFirstName: 'firstName',
62+
},
63+
},
64+
],
65+
};
66+
67+
api.create = jest.fn();
68+
api.uploadFilesDelivery(data, mockConfig);
69+
expect(api.create).toHaveBeenLastCalledWith(data, api.config(mockConfig));
70+
});
71+
});

0 commit comments

Comments
 (0)