Skip to content

Commit

Permalink
Bv fetch changes to fix, PD-238557 (#140)
Browse files Browse the repository at this point in the history
* PD-238557, bug fix

* PD-238557, fixing test cases

* 2.9.3
  • Loading branch information
VarshaAdigaBV authored Apr 11, 2024
1 parent 6713f93 commit d057b98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/bvFetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit }) {
}
}).then(() => {
if (canBeCached) {
const clonedResponse = response.clone()
const clonedResponse = response.clone();
const sizeCheck = response.clone();
const newHeaders = new Headers();
clonedResponse.headers.forEach((value, key) => {
newHeaders.append(key, value);
});
newHeaders.append('X-Bazaarvoice-Cached-Time', Date.now())
// Get response text to calculate its size
clonedResponse.text().then(text => {
sizeCheck.text().then(text => {
// Calculate size of response text in bytes
const sizeInBytes = new Blob([text]).size;

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bv-ui-core",
"version": "2.9.2",
"version": "2.9.3",
"license": "Apache 2.0",
"description": "Bazaarvoice UI-related JavaScript",
"repository": {
Expand Down
13 changes: 7 additions & 6 deletions test/unit/bvFetch/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ describe('BvFetch', function () {
bvFetchInstance.bvFetchFunc(url, options)
.then(response => {
// Check if response is fetched from network
expect(response).to.not.be.null;
console.log(response.body)
setTimeout(() => {
expect(response).to.not.be.null;
console.log(response.body)

// Check if caches.match was called
expect(cacheStub.calledOnce).to.be.false;
expect(cacheStub.calledOnce).to.be.false;

// Check if response is not cached
const cachedResponse = cacheStorage.get(url);
expect(cachedResponse).to.be.undefined;

const cachedResponse = cacheStorage.get(url);
expect(cachedResponse).to.be.undefined;
}, 500)
done();
})
.catch(done);
Expand Down

0 comments on commit d057b98

Please sign in to comment.