Skip to content

Commit 1dcbe32

Browse files
committed
Add test for when body has different order
1 parent 50233e3 commit 1dcbe32

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cache.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,25 @@ describe('cache', () => {
3333
});
3434
expect(result).toEqual('771798e93f4fbad36b4c89cd88d3752383224caf8e585661dc174feb25939f75');
3535
});
36+
37+
it('returns a same hash uniquely representing the params when body has different order', async () => {
38+
let params = {
39+
method: 'POST',
40+
path: '/v1/completions',
41+
authHeader: null,
42+
body: '{"key1":"1","key2":"2"}',
43+
};
44+
let result = await getCacheKey(params);
45+
expect(result).toEqual('91b1af0c3f20778905ab588460bcb1d14b4621445f32fd871d7fe23056142923');
46+
47+
params = {
48+
method: 'POST',
49+
path: '/v1/completions',
50+
authHeader: null,
51+
body: '{"key2":"2","key1":"1"}',
52+
};
53+
result = await getCacheKey(params);
54+
expect(result).toEqual('91b1af0c3f20778905ab588460bcb1d14b4621445f32fd871d7fe23056142923');
55+
});
3656
});
3757
});

0 commit comments

Comments
 (0)