@aofl/resource-enumerate
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -0,1 +1,9 @@ | ||
/** | ||
* Exports ResourceEnumerate | ||
* | ||
* @module aofl-js/resource-enumerate-package | ||
* @version 1.0.0 | ||
* @author Arian Khosravi <arian.khosravi@aofl.com> | ||
*/ | ||
export {default as ResourceEnumerate} from './src/resource-enumerate'; |
{ | ||
"name": "@aofl/resource-enumerate", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -16,7 +16,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"@aofl/api-request": "^1.0.1", | ||
"@aofl/cache-manager": "^1.0.1", | ||
"@aofl/middleware": "^1.0.0", | ||
"@aofl/server-environment": "^1.0.1" | ||
"@aofl/api-request": "^1.1.0", | ||
"@aofl/cache-manager": "^1.1.0", | ||
"@aofl/middleware": "^1.1.0", | ||
"@aofl/server-environment": "^1.1.0" | ||
} | ||
} |
@@ -1,8 +0,1 @@ | ||
/** | ||
* Resource Enumerate implementation | ||
* | ||
* @summary resource-enumerate | ||
* @version 1.0.0 | ||
* @author Arian Khosravi <arian.khosravi@aofl.com> | ||
*/ | ||
import {environmentTypeEnumerate} from '@aofl/server-environment'; | ||
@@ -17,2 +10,11 @@ import {Middleware} from '@aofl/middleware'; | ||
* hardcode paths\urls. | ||
* | ||
* @summary resource-enumerate | ||
* @version 1.0.0 | ||
* @author Arian Khosravi <arian.khosravi@aofl.com> | ||
* @memberof module:aofl-js/resource-enumerate-package | ||
* | ||
* @requires module:aofl-js/middleware-package | ||
* @requires module:aofl-js/api-request-package | ||
* @requires module:aofl-js/server-environment-package | ||
*/ | ||
@@ -19,0 +21,0 @@ class ResourceEnumerate { |
@@ -7,2 +7,7 @@ /* eslint no-invalid-this: "off" */ | ||
beforeEach(function() { | ||
sinon.stub(window, 'fetch') | ||
.returns(Promise.resolve({ | ||
json: () => Promise.resolve({}) | ||
})); | ||
this.config = { | ||
@@ -37,150 +42,134 @@ apis: { | ||
beforeEach(function() { | ||
fetchMock.mock('productionHost', {}); | ||
fetchMock.mock('stageHost', {}); | ||
fetchMock.mock('developmentHost', {}); | ||
}); | ||
afterEach(function() { | ||
const cacheManager = new CacheManager(ResourceEnumerate.NAMESPACE); | ||
cacheManager.clear(); | ||
fetchMock.restore(); | ||
window.fetch.restore(); | ||
}); | ||
it('should call production', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
resourceEnumerateInstance.init(this.config) | ||
.then(() => { | ||
it('should call production', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
await resourceEnumerateInstance.init(this.config); | ||
expect(config.apis.apins.url).to.be.equal('productionHost'); | ||
done(); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should call development', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('development'); | ||
it('should call development', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('development'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
await resourceEnumerateInstance.init(config); | ||
expect(config.apis.apins.url).to.be.equal('developmentHost'); | ||
done(); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should call stage', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('stage'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
it('should call stage', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('stage'); | ||
await resourceEnumerateInstance.init(config); | ||
expect(config.apis.apins.url).to.be.equal('stageHost'); | ||
done(); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should work without variables function', function(done) { | ||
const config = this.config; | ||
config.apis.apins.developmentVariables = void 0; | ||
const resourceEnumerateInstance = new ResourceEnumerate('development'); | ||
config.developmentConfig = () => Promise.resolve({ | ||
default(ns, {host}) { | ||
return 'stageHost'; | ||
} | ||
}); | ||
it('should work without variables function', async function() { | ||
try { | ||
const config = this.config; | ||
config.apis.apins.developmentVariables = void 0; | ||
const resourceEnumerateInstance = new ResourceEnumerate('development'); | ||
config.developmentConfig = () => Promise.resolve({ | ||
default(ns, {host}) { | ||
return 'stageHost'; | ||
} | ||
}); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
await resourceEnumerateInstance.init(config); | ||
expect(config.apis.apins.url).to.be.equal('stageHost'); | ||
done(); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should get from cache', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
resourceEnumerateInstance | ||
.get('apins') | ||
.then(() => { | ||
resourceEnumerateInstance | ||
.get('apins') | ||
.then((payload) => { | ||
const numCalls = fetchMock.calls('productionHost').length; | ||
it('should get from cache', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
await resourceEnumerateInstance.init(config); | ||
await resourceEnumerateInstance.get('apins'); | ||
await resourceEnumerateInstance.get('apins'); | ||
expect(numCalls).to.be.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
expect(window.fetch.calledWith('productionHost')).to.true; | ||
expect(window.fetch.calledOnce).to.be.true; | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should make network call', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
resourceEnumerateInstance | ||
.get('apins') | ||
.then((payload) => { | ||
expect(fetchMock.called('productionHost')).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
it('should make network call', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
await resourceEnumerateInstance.init(config); | ||
await resourceEnumerateInstance.get('apins'); | ||
expect(window.fetch.calledWith('productionHost')).to.true; | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should make new call when fromCache is false', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
resourceEnumerateInstance | ||
.get('apins', false) | ||
.then((payload) => { | ||
resourceEnumerateInstance | ||
.get('apins', false) | ||
.then(() => { | ||
const numCalls = fetchMock.calls('productionHost').length; | ||
it('should make new call when fromCache is false', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
await resourceEnumerateInstance.init(config); | ||
await resourceEnumerateInstance.get('apins', false); | ||
await resourceEnumerateInstance.get('apins', false); | ||
expect(numCalls).to.be.equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
expect(window.fetch.calledWith('productionHost')).to.true; | ||
expect(window.fetch.calledTwice).to.be.true; | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should make new call when invalidateCache return true', function(done) { | ||
const config = this.config; | ||
config.apis.apins.invalidateCache = () => true; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
resourceEnumerateInstance | ||
.get('apins') | ||
.then((payload) => { | ||
resourceEnumerateInstance | ||
.get('apins') | ||
.then(() => { | ||
const numCalls = fetchMock.calls('productionHost').length; | ||
it('should make new call when invalidateCache return true', async function() { | ||
try { | ||
const config = this.config; | ||
config.apis.apins.invalidateCache = () => true; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
await resourceEnumerateInstance.init(config); | ||
await resourceEnumerateInstance.get('apins'); | ||
await resourceEnumerateInstance.get('apins'); | ||
expect(numCalls).to.be.equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
expect(window.fetch.calledWith('productionHost')).to.true; | ||
expect(window.fetch.calledTwice).to.be.true; | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
it('should throw a TypeError when api namespace is undefined', function(done) { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
resourceEnumerateInstance.init(config) | ||
.then(() => { | ||
resourceEnumerateInstance | ||
.get('undefined-namespace', false) | ||
.catch((e) => { | ||
it('should throw a TypeError when api namespace is undefined', async function() { | ||
try { | ||
const config = this.config; | ||
const resourceEnumerateInstance = new ResourceEnumerate('production'); | ||
await resourceEnumerateInstance.init(config); | ||
try { | ||
await resourceEnumerateInstance.get('undefined-namespace', false); | ||
} catch (e) { | ||
expect(e).to.be.an.instanceOf(TypeError); | ||
done(); | ||
}); | ||
}); | ||
} | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14905
0
306
Updated@aofl/api-request@^1.1.0
Updated@aofl/cache-manager@^1.1.0
Updated@aofl/middleware@^1.1.0