fsdb/tests/02_store_and_retrieve_an_item.test.ts

40 lines
861 B
TypeScript
Raw Permalink Normal View History

2025-06-13 20:40:28 -07:00
import * as asserts from '@std/assert';
import * as fsdb from '../fsdb.ts';
import { get_data_dir } from './helpers.ts';
Deno.test({
name: 'store and retrieve an item',
permissions: {
env: true,
read: ['./'],
write: ['./data']
},
fn: async () => {
type ITEM = {
id: string;
value: string;
};
const items: fsdb.FSDB_COLLECTION<ITEM> = new fsdb.FSDB_COLLECTION<ITEM>({
name: 'test-02-items',
root: get_data_dir() + '/test-02-items'
});
asserts.assert(items);
const item = {
id: 'blah-fish-test-with-cozy-home-down-here-yall-work',
value: 'the blah fish test, of course'
};
const stored_item = await items.create(item);
asserts.assertObjectMatch(stored_item, item);
const fetched_item = await items.get(item.id);
asserts.assert(fetched_item);
asserts.assertObjectMatch(fetched_item, stored_item);
}
});