Skip to content

Commit

Permalink
test: add FileStore iterator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Nov 2, 2021
1 parent 7d9215a commit 12e787d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ describe('FileStore', () => {
const store = await FileStore.open(name);

assert.deepStrictEqual(store.get('joe'), undefined);
assert.deepStrictEqual([...store], []);
assert.ok(!fs.existsSync(name));

await store.add({ name: 'joe', pat: 'abc' });
assert.deepStrictEqual(store.get('joe'), { name: 'joe', pat: 'abc' });
assert.deepStrictEqual([...store], [{ name: 'joe', pat: 'abc' }]);
assert.deepStrictEqual(JSON.parse(fs.readFileSync(name, 'utf8')), {
publishers: [{ name: 'joe', pat: 'abc' }],
});

await store.add({ name: 'joe', pat: 'what' });
assert.deepStrictEqual(store.get('joe'), { name: 'joe', pat: 'what' });
assert.deepStrictEqual([...store], [{ name: 'joe', pat: 'what' }]);
assert.deepStrictEqual(JSON.parse(fs.readFileSync(name, 'utf8')), {
publishers: [{ name: 'joe', pat: 'what' }],
});

await store.add({ name: 'jane', pat: 'oh' });
assert.deepStrictEqual(store.get('joe'), { name: 'joe', pat: 'what' });
assert.deepStrictEqual(store.get('jane'), { name: 'jane', pat: 'oh' });
assert.deepStrictEqual(
[...store],
[
{ name: 'joe', pat: 'what' },
{ name: 'jane', pat: 'oh' },
]
);
assert.deepStrictEqual(JSON.parse(fs.readFileSync(name, 'utf8')), {
publishers: [
{ name: 'joe', pat: 'what' },
Expand All @@ -36,20 +46,23 @@ describe('FileStore', () => {
await store.delete('joe');
assert.deepStrictEqual(store.get('joe'), undefined);
assert.deepStrictEqual(store.get('jane'), { name: 'jane', pat: 'oh' });
assert.deepStrictEqual([...store], [{ name: 'jane', pat: 'oh' }]);
assert.deepStrictEqual(JSON.parse(fs.readFileSync(name, 'utf8')), {
publishers: [{ name: 'jane', pat: 'oh' }],
});

await store.delete('joe');
assert.deepStrictEqual(store.get('joe'), undefined);
assert.deepStrictEqual(store.get('jane'), { name: 'jane', pat: 'oh' });
assert.deepStrictEqual([...store], [{ name: 'jane', pat: 'oh' }]);
assert.deepStrictEqual(JSON.parse(fs.readFileSync(name, 'utf8')), {
publishers: [{ name: 'jane', pat: 'oh' }],
});

await store.delete('jane');
assert.deepStrictEqual(store.get('joe'), undefined);
assert.deepStrictEqual(store.get('jane'), undefined);
assert.deepStrictEqual([...store], []);
assert.deepStrictEqual(JSON.parse(fs.readFileSync(name, 'utf8')), {
publishers: [],
});
Expand Down

0 comments on commit 12e787d

Please sign in to comment.