Skip to content

Commit

Permalink
feat(api-core): add file upload delivery batch api
Browse files Browse the repository at this point in the history
  • Loading branch information
Christie Baker authored and Christie Baker committed Nov 19, 2018
1 parent 6b1f68e commit eff0a3c
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/api-angular/src/filesDelivery.js
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),
});
2 changes: 2 additions & 0 deletions packages/api-angular/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import avSpacesApiFactory from './spaces';
import avUsersApiFactory from './user';
import avUserPermissionsApiFactory from './userPermissions';
import avFilesApiFactory from './files';
import avFilesDeliveryApiFactory from './filesDelivery';
import avSettingsApiFactory from './settings';

export default angular
Expand All @@ -37,4 +38,5 @@ export default angular
.factory('avUsersApi', avUsersApiFactory)
.factory('avUserPermissionsApi', avUserPermissionsApiFactory)
.factory('avFilesApi', avFilesApiFactory)
.factory('avFilesDeliveryApi', avFilesDeliveryApiFactory)
.factory('avSettingsApi', avSettingsApiFactory).name;
16 changes: 16 additions & 0 deletions packages/api-angular/src/tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ describe('Api Definitions Angular', () => {
});
expect(avSettingsApi).toBeDefined();
});

test('avFilesApi should be defined', () => {
let avFilesApi;
angular.mock.inject(_avFilesApi_ => {
avFilesApi = _avFilesApi_;
});
expect(avFilesApi).toBeDefined();
});

test('avFileDeliveryApi should be defined', () => {
let avFilesDeliveryApi;
angular.mock.inject(_avFilesDeliveryApi_ => {
avFilesDeliveryApi = _avFilesDeliveryApi_;
});
expect(avFilesDeliveryApi).toBeDefined();
});
});
11 changes: 11 additions & 0 deletions packages/api-axios/src/filesDelivery.js
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,
});
2 changes: 2 additions & 0 deletions packages/api-axios/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import avUserApi from './user';
import avPdfApi from './pdf';
import avUserPermissionsApi from './userPermissions';
import avFilesApi from './files';
import avFilesDeliveryApi from './filesDelivery';
import avSettingsApi from './settings';

export default AvApi;
Expand All @@ -32,5 +33,6 @@ export {
avUserApi,
avUserPermissionsApi,
avFilesApi,
avFilesDeliveryApi,
avSettingsApi,
};
2 changes: 2 additions & 0 deletions packages/api-axios/src/tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Api, {
avUserApi,
avUserPermissionsApi,
avFilesApi,
avFilesDeliveryApi,
avSettingsApi,
} from '../';

Expand Down Expand Up @@ -39,6 +40,7 @@ describe('API Definitions', () => {
expect(avUserApi).toBeDefined();
expect(avUserPermissionsApi).toBeDefined();
expect(avFilesApi).toBeDefined();
expect(avFilesDeliveryApi).toBeDefined();
expect(avSettingsApi).toBeDefined();
});
});
2 changes: 2 additions & 0 deletions packages/api-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AvSpaces from './resources/spaces';
import AvUsers from './resources/user';
import AvUserPermissions from './resources/userPermissions';
import AvFiles from './resources/files';
import AvFilesDelivery from './resources/filesDelivery';
import AvSettings from './resources/settings';

export default AvApi;
Expand All @@ -32,5 +33,6 @@ export {
AvUsers,
AvUserPermissions,
AvFiles,
AvFilesDelivery,
AvSettings,
};
23 changes: 22 additions & 1 deletion packages/api-core/src/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [AvLogMessage](#avlogmessage)
* [AvProxy](#avproxy)
* [AvFiles](#avfiles)
* [AvFilesDelivery](#avfilesdelivery)
* [AvSettings](#avsettings)

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

#### Methods

##### `me()`
##### `me()`
Helper function that returns information about logged in user.

### AvRegions
Expand Down Expand Up @@ -100,6 +101,26 @@ Upload a file to a bucket in the vault
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)
`config` should contain `customerId`, `id` (the bucketId), and `clientId`

### AvFilesDelivery
Upload a batch of files to a designated channel configured on the server.

#### Methods

#### `uploadFilesDelivery(data, config)`
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.

Example:
```html
data = {
deliveries:
[ {
fileURI: upload.references[0],
deliveryChannel: 'DEMO',
metadata: { payerId: "DEMOPAYERID", requestId: "123", patientLastName: "lastName", patientFirstName: "firstName" },
} ]
};
```
`config` should contain `customerId` and `clientId`

### AvSettings
Store and retrieve settings to be reused.
Expand Down
39 changes: 39 additions & 0 deletions packages/api-core/src/resources/filesDelivery.js
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 packages/api-core/src/resources/tests/filesDelivery.test.js
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));
});
});

0 comments on commit eff0a3c

Please sign in to comment.