Skip to content

Commit 9ec1d13

Browse files
committed
refresh multiple contracts ids
1 parent 44dd60a commit 9ec1d13

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "verto-cache-interface",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "A communication package with Verto Cache System",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/hooks/cache-contract-hook.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ import {CacheInterfaceConstants} from "../constants";
99
* @return the result of the call for {@param action}
1010
*/
1111
export const cacheContractHook = async (action: () => Promise<any> | any,
12-
contractId?: string,
12+
contractId?: string | string[],
1313
refreshCommunityContract?: boolean) => {
1414
let response = await action();
1515
if(contractId) {
16-
await cacheContract(contractId);
16+
let ids: Array<string> = [];
17+
18+
if(!Array.isArray(contractId)) {
19+
ids = [contractId];
20+
} else {
21+
ids = [...contractId];
22+
}
23+
24+
for (let id of ids) {
25+
await cacheContract(id);
26+
}
1727
}
1828
if(refreshCommunityContract) {
1929
await cacheContract(CacheInterfaceConstants.COMMUNITY_CONTRACT);

src/tests/hooks.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ describe('Test hooks', () => {
2828
expect(spy).toHaveBeenCalledWith(CacheInterfaceConstants.COMMUNITY_CONTRACT);
2929
expect(spy).toHaveBeenCalledTimes(2);
3030
});
31+
32+
test('Cache contract hook with multiple contracts to refresh', async () => {
33+
const spy = jest.spyOn(cacheContractsModule, 'cacheContract');
34+
spy.mockImplementation();
35+
const fn = jest.fn();
36+
await cacheContractHook(fn, ['ABC', 'DEF'], true);
37+
expect(fn).toHaveBeenCalled();
38+
expect(spy).toHaveBeenCalledWith('ABC');
39+
expect(spy).toHaveBeenCalledWith('DEF');
40+
expect(spy).toHaveBeenCalledWith(CacheInterfaceConstants.COMMUNITY_CONTRACT);
41+
expect(spy).toHaveBeenCalledTimes(3);
42+
});
3143
})

0 commit comments

Comments
 (0)