-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7): replace FormData objects with k-v map in object-hash replacer
- Loading branch information
1 parent
d113b65
commit fc5455e
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/const cachios = require('./../src'); | ||
|
||
const axios = require('axios'); | ||
const hash = require('object-hash'); | ||
|
||
describe('cachios.getReplaced', () => { | ||
test('should be set by default', () => { | ||
expect(cachios.getReplaced).toBeDefined(); | ||
}); | ||
|
||
test('should not modify common values', () => { | ||
[ | ||
{ foo: 'bar' }, | ||
1234, | ||
'Melon', | ||
1.234, | ||
null, | ||
undefined, | ||
].forEach((thing) => { | ||
expect(cachios.getReplaced(thing)).toEqual(thing); | ||
}); | ||
}); | ||
|
||
test('should be used when creating cache keys', () => { | ||
const instance = cachios.create(axios); | ||
|
||
instance.getReplaced = (thing) => { | ||
console.log(thing); | ||
if (thing === 'bar') { | ||
return 'baz'; | ||
} | ||
return thing; | ||
}; | ||
|
||
const expected = hash({ | ||
method: 'GET', | ||
url: '/something', | ||
params: { | ||
foo: 'baz', | ||
}, | ||
data: { | ||
stuff: [ | ||
{ foo: 'baz' }, | ||
], | ||
}, | ||
}); | ||
|
||
const actual = instance.getCacheKey({ | ||
method: 'GET', | ||
url: '/something', | ||
params: { | ||
foo: 'bar', | ||
}, | ||
data: { | ||
stuff: [ | ||
{ foo: 'bar' }, | ||
], | ||
}, | ||
}); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
|
||
test('should transform FormData to an object', () => { | ||
const instance = cachios.create(axios); | ||
|
||
const fd = new FormData(); | ||
fd.append('foo', 'bar'); | ||
fd.append('transform', 'hello'); | ||
|
||
expect(instance.getReplaced(fd)).toEqual({ | ||
foo: 'bar', | ||
transform: 'hello', | ||
}); | ||
console.log(typeof cachios); | ||
}); | ||
}); |