Skip to content

Commit

Permalink
CB-5186 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Jun 3, 2024
1 parent b8e0ff2 commit 6571274
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
25 changes: 12 additions & 13 deletions webapp/packages/core-utils/src/MetadataMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,32 @@ import { z } from 'zod';
import { MetadataMap } from './MetadataMap';

describe('MetadataMap', () => {
it('should create an empty map', () => {
const map = new MetadataMap<number, string>();

expect(map.size).toBe(0);
});

it('should sync items', () => {
const map = new MetadataMap<number, string>();
const emptyMap = new MetadataMap<number, string>();

const data: [number, string][] = [
[1, 'one'],
[2, 'two'],
[3, 'three'],
[Infinity, 'infinity'],
[NaN, 'nan'],
];

map.sync(data);
emptyMap.sync([]);

data.forEach(([key, value]) => {
expect(map.get(key)).toBe(value);
});

expect(emptyMap.size).toBe(0);
});

it('should set items', () => {
Expand Down Expand Up @@ -165,19 +177,6 @@ describe('MetadataMap', () => {
expect(map.has(4)).toBeFalsy();
});

it('should set value', () => {
const map = new MetadataMap<number, string>();
map.sync([
[1, 'one'],
[2, 'two'],
[3, 'three'],
]);

map.set(4, 'four');

expect(map.get(4)).toBe('four');
});

it('should clear', () => {
const map = new MetadataMap<number, string>();
map.sync([
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/core-utils/src/MetadataMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class MetadataMap<TKey, TValue> implements Map<TKey, TValue> {
return this;
}

// TODO replace zod schema with just validation callback returning true/false.
// In case we use something else than zod
get(key: TKey, defaultValue?: DefaultValueGetter<TKey, TValue>, schema?: schema.AnyZodObject): TValue {
const value = this.temp.get(key);
let invalidate = !this.temp.has(key);
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/core-utils/src/TempMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('TempMap', () => {
expect(map.isDeleted('test')).toBe(false);
});

it('should remove from deleted if set again', () => {
it('should remove from deleted map if set again', () => {
const map = new TempMap<string, string>(new Map());

map.set('test', 'test value');
Expand Down
11 changes: 7 additions & 4 deletions webapp/packages/core-utils/src/errorOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ describe('errorOf', () => {
});

it('returns undefined if error is not an instance of Error', () => {
const error = { message: 'test' };
const result = errorOf(error, Error);

expect(result).toBeUndefined();
expect(errorOf({ message: 'test' }, Error)).toBeUndefined();
expect(errorOf(undefined, Error)).toBeUndefined();
expect(errorOf(null, Error)).toBeUndefined();
expect(errorOf(0, Error)).toBeUndefined();
expect(errorOf('', Error)).toBeUndefined();
expect(errorOf(true, Error)).toBeUndefined();
expect(errorOf(Symbol(), Error)).toBeUndefined();
});
});

0 comments on commit 6571274

Please sign in to comment.