message: Update DB to reflect changes in spec
diff: @@ -4,7 +4,7 @@ import { promisify } from 'util';
  import { tmpdir } from 'os';
  import { mkdtemp } from 'fs';
  import rmrf from 'rmfr';
  -import { DB, KeyAlreadyExistsError, KeyError } from '../db';
  +import { DB, ValueError } from '../db';
  interface Context {
  dbDir: string;
  @@ -25,29 +25,48 @@ test.afterEach(async (t) => {
  await rmrf(t.context.dbDir);
  });
  -test('DB.get throws KeyError when no key exists', async (t) => {
  +test('DB.get returns undefined when no key exists', async (t) => {
  const { db } = t.context;
  - await t.throwsAsync(db.get('test'), KeyError);
  + t.is(await db.get('test'), undefined);
  });
  -test('DB.create creates a new document', async (t) => {
  +test('DB.create creates a new document and returns true', async (t) => {
  const { db } = t.context;
  - await db.create('test', { a: 1 });
  + const ret = await db.create('test', { a: 1 });
  const val = await db.get('test');
  t.deepEqual(val, { a: 1 });
  + t.true(ret);
  });
  -test('DB.create throws KeyAlreadyExistsError if key already exists', async (t) => {
  +test('DB.create returns false if key already exists', async (t) => {
  const { db } = t.context;
  await db.create('test', { a: 1 });
  - await t.throwsAsync(db.create('test', { a: 2 }), KeyAlreadyExistsError);
  + t.false(await db.create('test', { a: 2 }));
  });
  -test('DB.update creates a new document if key does not exist', async (t) => {
  +test('DB.create throws ValueError when value undefined', async (t) => {
  const { db } = t.context;
  - await db.update('test', (prev) => ({ ...prev, a: 1 }));
  + await t.throwsAsync(db.create('test', undefined as any), ValueError);
  +});
  +
  +test('DB.remove returns false when no key exists', async (t) => {
  + const { db } = t.context;
  + t.false(await db.remove('test'));
  +});
  +
  +test('DB.remove removes existing key from DB and returns true', async (t) => {
  + const { db } = t.context;
  + await db.create('test', { a: 1 });
  + t.true(await db.remove('test'));
  + t.is(await db.get('test'), undefined);
  +});
  +
  +test('DB.update creates a new document if key does not exist and returns it', async (t) => {
  + const { db } = t.context;
  + const next = await db.update('test', (prev) => ({ ...prev, a: 1 }));
  const val = await db.get('test');
  t.deepEqual(val, { a: 1 });
  + t.deepEqual(val, next);
  });
  test('DB.update uses initializer if key does not exist', async (t) => {
  @@ -73,14 +92,7 @@ test('DB.update ignores initializer on an existing document', async (t) => {
  t.deepEqual(val, { a: 1, b: 2 });
  });
  -test('DB.remove throws KeyError when no key exists', async (t) => {
  +test('DB.update throws ValueError if updater returned undefined', async (t) => {
  const { db } = t.context;
  - await t.throwsAsync(db.remove('test'), KeyError);
  -});
  -
  -test('DB.remove removes existing key from DB', async (t) => {
  - const { db } = t.context;
  - await db.create('test', { a: 1 });
  - await db.remove('test');
  - await t.throwsAsync(db.get('test'), KeyError);
  + await t.throwsAsync(db.update('test', () => undefined as any), ValueError);
  });
  