@availity/api-core
Advanced tools
Comparing version 1.0.0-alpha.10 to 1.0.0-alpha.11
{ | ||
"name": "@availity/api-core", | ||
"version": "1.0.0-alpha.10", | ||
"version": "1.0.0-alpha.11", | ||
"description": "Base API definitions for the Availity REST API", | ||
@@ -17,6 +17,6 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@availity/localstorage-core": "^1.0.0-alpha.10" | ||
"@availity/localstorage-core": "^1.0.0-alpha.11" | ||
}, | ||
"devDependencies": { | ||
"@availity/localstorage-core": "^1.0.0-alpha.10" | ||
"@availity/localstorage-core": "^1.0.0-alpha.11" | ||
}, | ||
@@ -23,0 +23,0 @@ "publishConfig": { |
@@ -6,9 +6,12 @@ import AvLocalStorage from '@availity/localstorage-core'; | ||
export default class AvApi { | ||
constructor(http, promise, config) { | ||
if (!http || !config || !promise) { | ||
throw new Error('[http], [promise] and [config] and must be defined'); | ||
constructor({ http, promise, merge, config }) { | ||
if (!http || !config || !promise || !merge) { | ||
throw new Error( | ||
'[http], [promise], [config], and [merge] must be defined' | ||
); | ||
} | ||
this.http = http; | ||
this.Promise = promise; | ||
this.defaultConfig = Object.assign({}, API_OPTIONS, config); | ||
this.merge = merge; | ||
this.defaultConfig = this.merge({}, API_OPTIONS, config); | ||
this.localStorage = new AvLocalStorage(); | ||
@@ -19,11 +22,22 @@ } | ||
config(config = {}) { | ||
return Object.assign({}, this.defaultConfig, config); | ||
return this.merge({}, this.defaultConfig, config); | ||
} | ||
addParams(params = {}, config = {}, newObj = true) { | ||
const output = newObj ? Object.assign({ params: {} }, config) : config; | ||
if (!newObj) { | ||
output.params = output.params || {}; | ||
} | ||
output.params = Object.assign({}, output.params, params); | ||
return output; | ||
} | ||
// set the cache paramaters | ||
cacheParams(config) { | ||
config.params = config.params || {}; | ||
const params = {}; | ||
if (config.cacheBust) { | ||
config.params.cacheBust = this.getCacheBustVal(config.cacheBust, () => | ||
params.cacheBust = this.getCacheBustVal(config.cacheBust, () => | ||
Date.now() | ||
@@ -34,3 +48,3 @@ ); | ||
if (config.pageBust) { | ||
config.params.pageBust = this.getCacheBustVal(config.pageBust, () => | ||
params.pageBust = this.getCacheBustVal(config.pageBust, () => | ||
this.getPageBust() | ||
@@ -41,3 +55,3 @@ ); | ||
if (config.sessionBust) { | ||
config.params.sessionBust = this.getCacheBustVal( | ||
params.sessionBust = this.getCacheBustVal( | ||
config.sessionBust, | ||
@@ -47,2 +61,4 @@ () => this.localStorage.getSessionBust() || this.getPageBust() | ||
} | ||
return this.addParams(params, config, false); | ||
} | ||
@@ -210,3 +226,3 @@ | ||
config.url = this.getUrl(config, id); | ||
this.cacheParams(config); | ||
config = this.cacheParams(config); | ||
return this.request(config, this.afterGet); | ||
@@ -220,3 +236,3 @@ } | ||
config.url = this.getUrl(config); | ||
this.cacheParams(config); | ||
config = this.cacheParams(config); | ||
return this.request(config, this.afterQuery); | ||
@@ -223,0 +239,0 @@ } |
import AvApi from '../api'; | ||
export default class AvLogMessages extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -11,3 +11,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
@@ -14,0 +19,0 @@ |
import AvApi from '../api'; | ||
export default class AvNavigation extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,4 +12,9 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
} |
import AvApi from '../api'; | ||
export default class AvNotifications extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,9 +12,14 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
deleteByTopic(topic) { | ||
const params = Object.assign({}, { topicId: topic }); | ||
return this.remove({ params }); | ||
deleteByTopic(topic, config) { | ||
const removeConfig = this.addParams({ topicId: topic }, config); | ||
return this.remove(removeConfig); | ||
} | ||
} |
import AvApi from '../api'; | ||
export default class AvOrganizations extends AvApi { | ||
constructor(http, promise, avUsers, config = {}) { | ||
constructor({ http, promise, merge, avUsers, config }) { | ||
const options = Object.assign( | ||
@@ -12,6 +12,11 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
if (!avUsers) { | ||
throw new Error('[avUsers] must be defined and be instance of AvUsers'); | ||
throw new Error('[avUsers] must be defined and be instance of avUsers'); | ||
} | ||
@@ -23,4 +28,4 @@ | ||
queryOrganizations(user, config) { | ||
const params = Object.assign({}, { userId: user.id }, config.params || {}); | ||
return this.query(Object.assign({}, { params }, config)); | ||
const queryConfig = this.addParams({ userId: user.id }, config); | ||
return this.query(queryConfig); | ||
} | ||
@@ -27,0 +32,0 @@ |
import AvApi from '../api'; | ||
export default class AvPdfs extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,3 +12,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
@@ -15,0 +20,0 @@ |
import AvApi from '../api'; | ||
export default class AvPermissions extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,3 +12,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
@@ -15,0 +20,0 @@ |
import AvApi from '../api'; | ||
export default class AvProviders extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,15 +12,14 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
getProviders(customerId, config = {}) { | ||
let queryConfig = { | ||
params: { | ||
customerId, | ||
}, | ||
}; | ||
queryConfig = Object.assign({}, queryConfig, config); | ||
getProviders(customerId, config) { | ||
const queryConfig = this.addParams({ customerId }, config); | ||
return this.query(queryConfig); | ||
} | ||
} |
import AvApi from '../api'; | ||
export default class AvProxy extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
if (!config || !config.tenant) { | ||
@@ -15,4 +15,9 @@ throw Error('Must specify tenant name for Proxy'); | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
} |
import AvApi from '../api'; | ||
export default class AvRegions extends AvApi { | ||
constructor(http, promise, avUsers, config = {}) { | ||
constructor({ http, promise, merge, avUsers, config }) { | ||
const options = Object.assign( | ||
@@ -14,3 +14,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
this.avUsers = avUsers; | ||
@@ -26,5 +31,4 @@ } | ||
return this.avUsers.me().then(user => { | ||
config.params = config.params || {}; | ||
config.params.userId = config.params.userId || user.id; | ||
return this.query(config); | ||
const queryConfig = this.addParams({ userId: user.id }, config); | ||
return this.query(queryConfig); | ||
}); | ||
@@ -31,0 +35,0 @@ } |
import AvApi from '../api'; | ||
export default class AvSpaces extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,3 +12,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
@@ -15,0 +20,0 @@ |
import AvLogMessages from '../logs'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvLogMessages', () => { | ||
test('should be defined', () => { | ||
api = new AvLogMessages(mockHttp, Promise, {}); | ||
api = new AvLogMessages({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,8 @@ }); | ||
test('send() should return {level, entries}', () => { | ||
api = new AvLogMessages(mockHttp, Promise, {}); | ||
api = new AvLogMessages({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const level = 'testLevel'; | ||
@@ -26,3 +37,8 @@ const entries = 'testEntries'; | ||
test('send() should delete entries.level', () => { | ||
api = new AvLogMessages(mockHttp, Promise, {}); | ||
api = new AvLogMessages({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const level = 'testLevel'; | ||
@@ -41,3 +57,8 @@ const entries = { | ||
beforeEach(() => { | ||
api = new AvLogMessages(mockHttp, Promise, {}); | ||
api = new AvLogMessages({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.send = jest.fn(); | ||
@@ -44,0 +65,0 @@ api.create = jest.fn(); |
import AvNavigation from '../navigation'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvNavigation', () => { | ||
test('should be defined', () => { | ||
api = new AvNavigation(mockHttp, Promise, {}); | ||
api = new AvNavigation({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,5 +21,9 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvNavigation(mockHttp, Promise); | ||
api = new AvNavigation({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
}); | ||
}); |
import AvNotification from '../notifications'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvNotification', () => { | ||
test('should be defined', () => { | ||
api = new AvNotification(mockHttp, Promise, {}); | ||
api = new AvNotification({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,7 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvNotification(mockHttp, Promise); | ||
api = new AvNotification({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -21,3 +31,8 @@ }); | ||
test('deleteByTopic() should call remove with topic added to params.topicId', () => { | ||
api = new AvNotification(mockHttp, Promise, {}); | ||
api = new AvNotification({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.remove = jest.fn(); | ||
@@ -24,0 +39,0 @@ |
import AvOrganizations from '../organizations'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -16,3 +17,9 @@ const mockUser = { | ||
test('should be defined', () => { | ||
api = new AvOrganizations(mockHttp, Promise, mockAvUsers, {}); | ||
api = new AvOrganizations({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -22,9 +29,19 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvOrganizations(mockHttp, Promise, mockAvUsers); | ||
api = new AvOrganizations({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
}); | ||
expect(api).toBeDefined(); | ||
}); | ||
test('should throw error if no AvUsers passed in', () => { | ||
test('should throw error if no avUsers passed in', () => { | ||
expect(() => { | ||
api = new AvOrganizations(mockHttp, Promise); | ||
api = new AvOrganizations({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}).toThrow('[avUsers] must be defined'); | ||
@@ -34,3 +51,9 @@ }); | ||
test('queryOrganizations() should call query with user.id added to params.userId', () => { | ||
api = new AvOrganizations(mockHttp, Promise, mockAvUsers); | ||
api = new AvOrganizations({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
@@ -40,8 +63,8 @@ | ||
const user = { id: userId }; | ||
const testConfig = { name: 'testName' }; | ||
const expectedConfig = Object.assign( | ||
{}, | ||
{ params: { userId } }, | ||
testConfig | ||
); | ||
const testConfig = { | ||
name: 'testName', | ||
params: { otherParam: 'helloWorld' }, | ||
}; | ||
const expectedConfig = Object.assign({}, testConfig); | ||
expectedConfig.params.userId = userId; | ||
@@ -52,4 +75,26 @@ api.queryOrganizations(user, testConfig); | ||
test('getOrganizations() should call AvUsers.me() and then queryOrganizations()', async () => { | ||
api = new AvOrganizations(mockHttp, Promise, mockAvUsers); | ||
test('queryOrganizations() should handle undefined config param', () => { | ||
api = new AvOrganizations({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
const userId = 'testUserId'; | ||
const user = { id: userId }; | ||
const expectedConfig = { params: { userId } }; | ||
api.queryOrganizations(user); | ||
expect(api.query).toHaveBeenLastCalledWith(expectedConfig); | ||
}); | ||
test('getOrganizations() should call avUsers.me() and then queryOrganizations()', async () => { | ||
api = new AvOrganizations({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.queryOrganizations = jest.fn(); | ||
@@ -56,0 +101,0 @@ |
import AvPdfs from '../pdfs'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvPdfs', () => { | ||
test('should be defined', () => { | ||
api = new AvPdfs(mockHttp, Promise, {}); | ||
api = new AvPdfs({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,8 @@ }); | ||
test('should throw error with bad config', () => { | ||
api = new AvPdfs(mockHttp, Promise, {}); | ||
api = new AvPdfs({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(() => { | ||
@@ -23,3 +34,8 @@ api = api.getPdf({}); | ||
test('should call onPdf() when pdf completes', async () => { | ||
api = new AvPdfs(mockHttp, Promise, {}); | ||
api = new AvPdfs({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.onPdf = jest.fn(); | ||
@@ -26,0 +42,0 @@ |
import AvPermissions from '../permissions'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvPermissions', () => { | ||
test('should be defined', () => { | ||
api = new AvPermissions(mockHttp, Promise, {}); | ||
api = new AvPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,7 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvPermissions(mockHttp, Promise); | ||
api = new AvPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -21,3 +31,8 @@ }); | ||
test('getPermissions() should query with permissionId and region params from arguments', () => { | ||
api = new AvPermissions(mockHttp, Promise); | ||
api = new AvPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
@@ -24,0 +39,0 @@ const id = 'testPermissionId'; |
import AvProviders from '../providers'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvProviders', () => { | ||
test('AvProviders should be defined', () => { | ||
api = new AvProviders(mockHttp, Promise, {}); | ||
api = new AvProviders({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,7 @@ }); | ||
test('AvProviders should handle no config passed in', () => { | ||
api = new AvProviders(mockHttp, Promise); | ||
api = new AvProviders({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -21,16 +31,35 @@ }); | ||
test('getProviders should query with customerId param added', () => { | ||
api = new AvProviders(mockHttp, Promise); | ||
api = new AvProviders({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
const customerId = 'testCustomerId'; | ||
const testConfig = { name: 'testName' }; | ||
const expectedConfig = Object.assign( | ||
{}, | ||
{ params: { customerId } }, | ||
testConfig | ||
); | ||
const testConfig = { | ||
name: 'testName', | ||
params: { testParam: 'hello world' }, | ||
}; | ||
const expectedConfig = Object.assign({}, testConfig); | ||
Object.assign(expectedConfig.params, { customerId }); | ||
api.getProviders(customerId, testConfig); | ||
expect(api.query).toHaveBeenLastCalledWith(expectedConfig); | ||
}); | ||
test('getProviders should handle undefined config param', () => { | ||
api = new AvProviders({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
const customerId = 'testCustomerId'; | ||
const expectedConfig = { params: { customerId } }; | ||
api.getProviders(customerId); | ||
expect(api.query).toHaveBeenLastCalledWith(expectedConfig); | ||
}); | ||
}); |
import AvProxy from '../proxy'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvProxy', () => { | ||
test('AvProxy should be defined', () => { | ||
api = new AvProxy(mockHttp, Promise, { tenant: 'healthplan' }); | ||
api = new AvProxy({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: { tenant: 'healthplan' }, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -16,5 +22,10 @@ }); | ||
expect(() => { | ||
api = new AvProxy(mockHttp, Promise); | ||
api = new AvProxy({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}).toThrow('Must specify tenant name for Proxy'); | ||
}); | ||
}); |
import AvRegions from '../regions'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -16,3 +17,9 @@ const mockUser = { | ||
test('should be defined', () => { | ||
api = new AvRegions(mockHttp, Promise, mockAvUsers, {}); | ||
api = new AvRegions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -22,3 +29,8 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvRegions(mockHttp, Promise); | ||
api = new AvRegions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -28,3 +40,9 @@ }); | ||
test('afterUpdate should call setPageBust and return response', () => { | ||
api = new AvRegions(mockHttp, Promise, mockAvUsers); | ||
api = new AvRegions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.setPageBust = jest.fn(); | ||
@@ -43,13 +61,18 @@ const testResponse1 = {}; | ||
test('getRegions should call AvUsers.me() and then query with result', () => { | ||
api = new AvRegions(mockHttp, Promise, mockAvUsers); | ||
test('getRegions should call avUsers.me() and then query with result', () => { | ||
api = new AvRegions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
const testConfig = { name: 'testName' }; | ||
const expectedConfig = Object.assign( | ||
{}, | ||
{ params: { userId: mockUser.id } }, | ||
testConfig | ||
); | ||
const testConfig = { | ||
name: 'testName', | ||
params: { testParam: 'helloWorld' }, | ||
}; | ||
const expectedConfig = Object.assign({}, testConfig); | ||
Object.assign(expectedConfig.params, { userId: mockUser.id }); | ||
return api.getRegions(testConfig).then(() => { | ||
@@ -60,4 +83,26 @@ expect(api.query).toHaveBeenLastCalledWith(expectedConfig); | ||
test('getRegions should handle undefined config param', () => { | ||
api = new AvRegions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
const expectedConfig = { params: { userId: mockUser.id } }; | ||
return api.getRegions().then(() => { | ||
expect(api.query).toHaveBeenLastCalledWith(expectedConfig); | ||
}); | ||
}); | ||
test('getCurrent region should query with param currentlySelected: true', () => { | ||
api = new AvRegions(mockHttp, Promise, mockAvUsers); | ||
api = new AvRegions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
avUsers: mockAvUsers, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
@@ -64,0 +109,0 @@ const expectedConfig = { |
import AvSpaces from '../spaces'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -18,3 +19,8 @@ const get = jest.fn(() => | ||
beforeEach(() => { | ||
api = new AvSpaces(mockHttp, Promise, {}); | ||
api = new AvSpaces({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.get = get; | ||
@@ -21,0 +27,0 @@ }); |
import AvUsers from '../user'; | ||
const mockPromise = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvUsers', () => { | ||
test('should be defined', () => { | ||
api = new AvUsers(mockPromise, Promise, {}); | ||
api = new AvUsers({ | ||
http: mockPromise, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,7 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvUsers(mockPromise, Promise); | ||
api = new AvUsers({ | ||
http: mockPromise, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -21,3 +31,8 @@ }); | ||
test("me() should get with id 'me'", () => { | ||
api = new AvUsers(mockPromise, Promise); | ||
api = new AvUsers({ | ||
http: mockPromise, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.get = mockPromise; | ||
@@ -24,0 +39,0 @@ api.me(); |
import AvUserPermissions from '../userPermissions'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -9,3 +10,8 @@ describe('AvUserPermissions', () => { | ||
test('should be defined', () => { | ||
api = new AvUserPermissions(mockHttp, Promise, {}); | ||
api = new AvUserPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -15,3 +21,7 @@ }); | ||
test('should handle no config passed in', () => { | ||
api = new AvUserPermissions(mockHttp, Promise); | ||
api = new AvUserPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -21,3 +31,8 @@ }); | ||
test('afterQuery should return response.data.axiUserPermissions if it exists or an empty array', () => { | ||
api = new AvUserPermissions(mockHttp, Promise); | ||
api = new AvUserPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const testResponse1 = {}; | ||
@@ -35,3 +50,8 @@ const axiUserPermissions = ['testPermission']; | ||
test('getPermissions should query with permissionId and region params from arguments', () => { | ||
api = new AvUserPermissions(mockHttp, Promise); | ||
api = new AvUserPermissions({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.query = jest.fn(); | ||
@@ -38,0 +58,0 @@ const permissionId = 'testPermissionId'; |
import AvApi from '../api'; | ||
export default class AvUsers extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,3 +12,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
@@ -15,0 +20,0 @@ |
import AvApi from '../api'; | ||
export default class AvUserPermissions extends AvApi { | ||
constructor(http, promise, config = {}) { | ||
constructor({ http, promise, merge, config }) { | ||
const options = Object.assign( | ||
@@ -12,3 +12,8 @@ { | ||
); | ||
super(http, promise, options); | ||
super({ | ||
http, | ||
promise, | ||
merge, | ||
config: options, | ||
}); | ||
} | ||
@@ -15,0 +20,0 @@ |
@@ -6,2 +6,3 @@ import AvApi from '../api'; | ||
const mockHttp = jest.fn(() => Promise.resolve({})); | ||
const mockMerge = jest.fn((...args) => Object.assign(...args)); | ||
@@ -12,3 +13,8 @@ describe('AvApi', () => { | ||
test('AvApi should be defined', () => { | ||
api = new AvApi(mockHttp, {}, Promise); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
expect(api).toBeDefined(); | ||
@@ -18,33 +24,50 @@ }); | ||
test('AvApi should throw errors when missing paramaters', () => { | ||
expect(() => { | ||
api = new AvApi(); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
// expect(() => { | ||
// api = new AvApi(); | ||
// }).toThrowError('[http], [promise], [config], and [merge] must be defined'); | ||
expect(() => { | ||
api = new AvApi(false, false, false); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
api = new AvApi({ | ||
http: false, | ||
promise: false, | ||
merge: false, | ||
config: false, | ||
}); | ||
}).toThrowError('[http], [promise], [config], and [merge] must be defined'); | ||
expect(() => { | ||
api = new AvApi(false, Promise, {}); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
api = new AvApi({ | ||
http: false, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}).toThrowError('[http], [promise], [config], and [merge] must be defined'); | ||
expect(() => { | ||
api = new AvApi(mockHttp, Promise, false); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: false, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}).toThrowError('[http], [promise], [config], and [merge] must be defined'); | ||
expect(() => { | ||
api = new AvApi(mockHttp, false, Promise); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: false, | ||
config: {}, | ||
}); | ||
}).toThrowError('[http], [promise], [config], and [merge] must be defined'); | ||
expect(() => { | ||
api = new AvApi(false, Promise, false); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
expect(() => { | ||
api = new AvApi(mockHttp, false, false); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
expect(() => { | ||
api = new AvApi(false, false, {}); | ||
}).toThrowError('[http], [promise] and [config] and must be defined'); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: false, | ||
}); | ||
}).toThrowError('[http], [promise], [config], and [merge] must be defined'); | ||
}); | ||
@@ -56,3 +79,8 @@ | ||
}; | ||
api = new AvApi(mockHttp, Promise, mockConfig); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: mockConfig, | ||
}); | ||
const testConfig = { path: '/api/internal' }; | ||
@@ -65,3 +93,8 @@ const testExpectConfig = Object.assign({}, api.defaultConfig, testConfig); | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}); | ||
@@ -103,3 +136,8 @@ | ||
test('setPageBust() should set to passed in value', () => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const test = 'test'; | ||
@@ -111,3 +149,8 @@ api.setPageBust(test); | ||
test('setPageBust() should use Date.now()', () => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const test = 'test'; | ||
@@ -121,3 +164,8 @@ Date.now = jest.fn(() => test); | ||
test('getPageBust() should return pageBustValue() if set', () => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const test = 'test'; | ||
@@ -129,3 +177,8 @@ api.pageBustValue = test; | ||
test('getPageBust() should set pageBustValue() if not set yet', () => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
const test = 'test'; | ||
@@ -139,9 +192,78 @@ api.setPageBust = jest.fn(() => { | ||
describe('addParams', () => { | ||
beforeEach(() => { | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}); | ||
test("should merge params into the config's", () => { | ||
const configParams = { | ||
part1: 'hello', | ||
}; | ||
const testParams = { | ||
part2: 'world', | ||
}; | ||
const expectedParams = Object.assign({}, configParams, testParams); | ||
const testConfig = { params: configParams }; | ||
const expectedResults = { params: expectedParams }; | ||
expect(api.addParams(testParams, testConfig)).toEqual(expectedResults); | ||
}); | ||
test('should not modify passed in config by default', () => { | ||
const configParams = { | ||
part1: 'hello', | ||
}; | ||
const testParams = { | ||
part2: 'world', | ||
}; | ||
const expectedParams = Object.assign({}, configParams, testParams); | ||
const testConfig = { params: configParams }; | ||
const testConfig2 = { params: configParams }; | ||
const expectedResults = { params: expectedParams }; | ||
const result = api.addParams(testParams, testConfig); | ||
expect(testConfig).toEqual(testConfig2); | ||
expect(result).not.toBe(testConfig); | ||
expect(result).toEqual(expectedResults); | ||
}); | ||
test('should modify passed in config with 3rd param false', () => { | ||
const configParams = { | ||
part1: 'hello', | ||
}; | ||
const testParams = { | ||
part2: 'world', | ||
}; | ||
const expectedParams = Object.assign({}, configParams, testParams); | ||
const testConfig = { params: configParams }; | ||
const testConfig2 = { params: configParams }; | ||
const expectedResults = { params: expectedParams }; | ||
const result = api.addParams(testParams, testConfig, false); | ||
expect(testConfig).not.toEqual(testConfig2); | ||
expect(result).toBe(testConfig); | ||
expect(result).toEqual(expectedResults); | ||
}); | ||
}); | ||
describe('cacheParams', () => { | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}); | ||
test('should make sure params object exists', () => { | ||
const testConfig = {}; | ||
test('should make sure params object exists, if adding cache', () => { | ||
const testConfig = { cacheBust: true }; | ||
api.cacheParams(testConfig); | ||
@@ -228,3 +350,8 @@ expect(testConfig.params).toBeDefined(); | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}); | ||
@@ -296,9 +423,14 @@ | ||
test('getRequestUrl() should without passing in config', () => { | ||
const fakeAPi = new AvApi(mockHttp, Promise, { | ||
api: true, | ||
path: '/api/', | ||
version: '/v1/', | ||
name: '/test', | ||
const fakeApi = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: { | ||
api: true, | ||
path: '/api/', | ||
version: '/v1/', | ||
name: '/test', | ||
}, | ||
}); | ||
expect(fakeAPi.getRequestUrl()).toBe('/api/v1/test'); | ||
expect(fakeApi.getRequestUrl()).toBe('/api/v1/test'); | ||
}); | ||
@@ -309,3 +441,8 @@ }); | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
}); | ||
@@ -396,3 +533,8 @@ | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.getLocation = jest.fn(() => testLocation); | ||
@@ -454,3 +596,8 @@ api.request = jest.fn(); | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.onResponse = jest.fn(() => mockFinalResponse); | ||
@@ -494,5 +641,10 @@ }); | ||
beforeEach(() => { | ||
api = new AvApi(mockHttp, Promise, {}); | ||
api = new AvApi({ | ||
http: mockHttp, | ||
promise: Promise, | ||
merge: mockMerge, | ||
config: {}, | ||
}); | ||
api.request = jest.fn(); | ||
api.cacheParams = jest.fn(); | ||
api.cacheParams = jest.fn(config => Object.assign({}, config)); | ||
api.config = jest.fn(config => Object.assign({}, config)); | ||
@@ -499,0 +651,0 @@ api.getUrl = jest.fn(() => testUrl); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66078
33
2049