@aofl/api-request
Advanced tools
Comparing version
{ | ||
"name": "@aofl/api-request", | ||
"version": "2.0.0-alpha.1", | ||
"version": "2.0.0-alpha.5", | ||
"description": "A module for simplifying api calls", | ||
@@ -27,5 +27,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@aofl/cache-manager": "^2.0.0-alpha.1" | ||
"@aofl/cache-manager": "^2.0.0-alpha.5" | ||
}, | ||
"gitHead": "afeca11d48651d7710e6942de5fdad812d9d87f9" | ||
"gitHead": "00d91514e0c953e8cd998150ed5705b87db20b39" | ||
} |
@@ -21,3 +21,3 @@ import FormatterManager from '../formatter-manager'; | ||
return 'ApiRequest'; | ||
}; | ||
} | ||
@@ -77,3 +77,3 @@ /** | ||
const requestPromise = fetch(url, formatter.pack(payload)) | ||
.then(formatter.unpack); | ||
.then(formatter.unpack); | ||
@@ -80,0 +80,0 @@ cacheManager.setItem(cacheKey, requestPromise); |
@@ -17,5 +17,5 @@ /* eslint no-invalid-this: "off" */ | ||
sinon.stub(window, 'fetch') | ||
.returns(Promise.resolve({ | ||
json: () => Promise.resolve({}) | ||
})); | ||
.returns(Promise.resolve({ | ||
json: () => Promise.resolve({}) | ||
})); | ||
this.apiRequest = new ApiRequest(); | ||
@@ -41,6 +41,5 @@ this.apiRequest.addFormatter('test', this.formatter); | ||
it('should return cached result', async function() { | ||
const apiRequest = this.apiRequest; | ||
try { | ||
await apiRequest.request('http://example.org', '', 'test'); | ||
await apiRequest.request('http://example.org', '', 'test'); | ||
await this.apiRequest.request('http://example.org', '', 'test'); | ||
await this.apiRequest.request('http://example.org', '', 'test'); | ||
@@ -54,6 +53,5 @@ expect(window.fetch.calledOnce).to.be.true; | ||
it('should invoke fetch when cache is disabled', async function() { | ||
const apiRequest = this.apiRequest; | ||
try { | ||
await apiRequest.request('http://example.org', '', 'test'); | ||
await apiRequest.request('http://example.org', '', 'test', false); | ||
await this.apiRequest.request('http://example.org', '', 'test'); | ||
await this.apiRequest.request('http://example.org', '', 'test', false); | ||
@@ -68,6 +66,5 @@ expect(window.fetch.calledTwice).to.be.true; | ||
try { | ||
const apiRequest = this.apiRequest; | ||
await apiRequest.request('http://example.org', '', 'test'); | ||
apiRequest.clearCache('default'); | ||
await apiRequest.request('http://example.org', '', 'test'); | ||
await this.apiRequest.request('http://example.org', '', 'test'); | ||
this.apiRequest.clearCache('default'); | ||
await this.apiRequest.request('http://example.org', '', 'test'); | ||
@@ -80,7 +77,6 @@ expect(window.fetch.calledTwice).to.be.true; | ||
it('should invoke fetch when a deffirent cache namespace is used', async function() { | ||
it('should invoke fetch when a different cache namespace is used', async function() { | ||
try { | ||
const apiRequest = this.apiRequest; | ||
await apiRequest.request('http://example.org', '', 'test', true); | ||
await apiRequest.request('http://example.org', '', 'test', true, 'test'); | ||
await this.apiRequest.request('http://example.org', '', 'test', true); | ||
await this.apiRequest.request('http://example.org', '', 'test', true, 'test'); | ||
@@ -87,0 +83,0 @@ expect(window.fetch.calledTwice).to.be.true; |
12862
-0.92%296
-1.33%