2024-04-23 15:51:43 +00:00
|
|
|
import { cacheDocumentKey } from '../src/client/utils';
|
2022-09-22 11:22:35 +00:00
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce identical hash for the same document and the same keys but different values in variables', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: true });
|
|
|
|
|
const right = await cacheDocumentKey('doc', { a: false });
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).toEqual(right);
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce identical hash for the same document but with an empty array', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: [] });
|
|
|
|
|
const right = await cacheDocumentKey('doc', { a: [] });
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).toEqual(right);
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce identical hash for the same document but with and without an empty array', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: [] });
|
|
|
|
|
const right = await cacheDocumentKey('doc', { a: null });
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).toEqual(right);
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce identical hash for the same document but with an array of primitive values', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: [1, 2, 3] });
|
|
|
|
|
const right = await cacheDocumentKey('doc', { a: [4, 5, 6] });
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).toEqual(right);
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce different hash for the same document but with different keys in variables', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: true });
|
|
|
|
|
const right = await cacheDocumentKey('doc', { b: true });
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).not.toEqual(right);
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce different hash for the same document but with and without variables', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: true });
|
|
|
|
|
const right = await cacheDocumentKey('doc', null);
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).not.toEqual(right);
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-23 11:49:51 +00:00
|
|
|
test('produce different hash for the same document but with and without variables (empty object)', async () => {
|
|
|
|
|
const left = await cacheDocumentKey('doc', { a: true });
|
|
|
|
|
const right = await cacheDocumentKey('doc', {});
|
2022-09-22 11:22:35 +00:00
|
|
|
expect(left).not.toEqual(right);
|
|
|
|
|
});
|