🐛 add env to useDb and apply prettier
tinyedge/deploy Deployed by TinyEdge

This commit is contained in:
2026-08-07 13:28:26 +02:00
parent 67727f96ab
commit cbe1b42f6e
54 changed files with 5492 additions and 2406 deletions
+27 -25
View File
@@ -1,45 +1,47 @@
import { describe, expect, it } from 'vitest'
import { readIdentity, writeIdentity } from './identity'
import { describe, expect, it } from 'vitest';
import { readIdentity, writeIdentity } from './identity';
function createMockStorage(): Storage {
const store = new Map<string, string>()
const store = new Map<string, string>();
return {
getItem: (key: string) => store.get(key) ?? null,
setItem: (key: string, value: string) => void store.set(key, value),
removeItem: (key: string) => void store.delete(key),
clear: () => store.clear(),
key: () => null,
get length() { return store.size },
}
get length() {
return store.size;
},
};
}
describe('identity storage', () => {
it('returns null when nothing is stored', () => {
expect(readIdentity(createMockStorage())).toBeNull()
})
expect(readIdentity(createMockStorage())).toBeNull();
});
it('round-trips a written identity', () => {
const storage = createMockStorage()
writeIdentity(storage, { name: 'Alice' })
expect(readIdentity(storage)).toEqual({ name: 'Alice' })
})
const storage = createMockStorage();
writeIdentity(storage, { name: 'Alice' });
expect(readIdentity(storage)).toEqual({ name: 'Alice' });
});
it('ignores malformed JSON', () => {
const storage = createMockStorage()
storage.setItem('stb:identity', '{not json')
expect(readIdentity(storage)).toBeNull()
})
const storage = createMockStorage();
storage.setItem('stb:identity', '{not json');
expect(readIdentity(storage)).toBeNull();
});
it('ignores an empty stored name', () => {
const storage = createMockStorage()
storage.setItem('stb:identity', JSON.stringify({ name: ' ' }))
expect(readIdentity(storage)).toBeNull()
})
const storage = createMockStorage();
storage.setItem('stb:identity', JSON.stringify({ name: ' ' }));
expect(readIdentity(storage)).toBeNull();
});
it('overwrites a previously stored identity', () => {
const storage = createMockStorage()
writeIdentity(storage, { name: 'Alice' })
writeIdentity(storage, { name: 'Bob' })
expect(readIdentity(storage)).toEqual({ name: 'Bob' })
})
})
const storage = createMockStorage();
writeIdentity(storage, { name: 'Alice' });
writeIdentity(storage, { name: 'Bob' });
expect(readIdentity(storage)).toEqual({ name: 'Bob' });
});
});