Initial commit
Signed-off-by: mikesir87 <mikesir87@gmail.com> Imported from dockersamples/101-tutorial, removed other languages for now, and replaced PWD references with Docker Desktop.
This commit is contained in:
64
app/spec/persistence/sqlite.spec.js
Normal file
64
app/spec/persistence/sqlite.spec.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const db = require('../../src/persistence/sqlite');
|
||||
const fs = require('fs');
|
||||
|
||||
const ITEM = {
|
||||
id: '7aef3d7c-d301-4846-8358-2a91ec9d6be3',
|
||||
name: 'Test',
|
||||
completed: false,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
if (fs.existsSync('/etc/todos/todo.db')) {
|
||||
fs.unlinkSync('/etc/todos/todo.db');
|
||||
}
|
||||
});
|
||||
|
||||
test('it initializes correctly', async () => {
|
||||
await db.init();
|
||||
});
|
||||
|
||||
test('it can store and retrieve items', async () => {
|
||||
await db.init();
|
||||
|
||||
await db.storeItem(ITEM);
|
||||
|
||||
const items = await db.getItems();
|
||||
expect(items.length).toBe(1);
|
||||
expect(items[0]).toEqual(ITEM);
|
||||
});
|
||||
|
||||
test('it can update an existing item', async () => {
|
||||
await db.init();
|
||||
|
||||
const initialItems = await db.getItems();
|
||||
expect(initialItems.length).toBe(0);
|
||||
|
||||
await db.storeItem(ITEM);
|
||||
|
||||
await db.updateItem(
|
||||
ITEM.id,
|
||||
Object.assign({}, ITEM, { completed: !ITEM.completed }),
|
||||
);
|
||||
|
||||
const items = await db.getItems();
|
||||
expect(items.length).toBe(1);
|
||||
expect(items[0].completed).toBe(!ITEM.completed);
|
||||
});
|
||||
|
||||
test('it can remove an existing item', async () => {
|
||||
await db.init();
|
||||
await db.storeItem(ITEM);
|
||||
|
||||
await db.removeItem(ITEM.id);
|
||||
|
||||
const items = await db.getItems();
|
||||
expect(items.length).toBe(0);
|
||||
});
|
||||
|
||||
test('it can get a single item', async () => {
|
||||
await db.init();
|
||||
await db.storeItem(ITEM);
|
||||
|
||||
const item = await db.getItem(ITEM.id);
|
||||
expect(item).toEqual(ITEM);
|
||||
});
|
Reference in New Issue
Block a user