diff options
author | Mavlushechka <mavlushechka@gmail.com> | 2022-09-24 00:07:19 +0500 |
---|---|---|
committer | Mavlushechka <mavlushechka@gmail.com> | 2022-09-24 00:07:19 +0500 |
commit | 43ffc1d6e59f2d118c730e968e032fcecbeaf202 (patch) | |
tree | 7e1e87163c8af30cd29d2b6e745d1c6b1077dc25 /app/spec/persistence/sqlite.spec.js | |
parent | e7c380c64056a004a1d61f04df7afb2a1c1c3675 (diff) |
Copy docker/getting-started repository
Diffstat (limited to 'app/spec/persistence/sqlite.spec.js')
-rw-r--r-- | app/spec/persistence/sqlite.spec.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/app/spec/persistence/sqlite.spec.js b/app/spec/persistence/sqlite.spec.js new file mode 100644 index 0000000..996d451 --- /dev/null +++ b/app/spec/persistence/sqlite.spec.js @@ -0,0 +1,65 @@ +const db = require('../../src/persistence/sqlite'); +const fs = require('fs'); +const location = process.env.SQLITE_DB_LOCATION || '/etc/todos/todo.db'; + +const ITEM = { + id: '7aef3d7c-d301-4846-8358-2a91ec9d6be3', + name: 'Test', + completed: false, +}; + +beforeEach(() => { + if (fs.existsSync(location)) { + fs.unlinkSync(location); + } +}); + +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); +}); |