Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32172745
D7184.1765061979.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7184.1765061979.diff
View Options
diff --git a/web/database/queries/storage-engine-queries.test.js b/web/database/queries/storage-engine-queries.test.js
new file mode 100644
--- /dev/null
+++ b/web/database/queries/storage-engine-queries.test.js
@@ -0,0 +1,74 @@
+// @flow
+
+import initSqlJs from 'sql.js';
+
+import { setupSQLiteDB } from './db-queries.js';
+import {
+ getPersistStorageItem,
+ removePersistStorageItem,
+ setPersistStorageItem,
+} from './storage-engine-queries.js';
+
+const TEST_KEY = 'redux-persist';
+const TEST_ITEM = '[[{}]]';
+
+describe('redux-persist storage engine queries', () => {
+ let db;
+
+ beforeAll(async () => {
+ const SQL = await initSqlJs();
+ db = new SQL.Database();
+ });
+
+ beforeEach(() => {
+ setupSQLiteDB(db);
+ const query = `
+ INSERT INTO persist_storage (key, item)
+ VALUES ($key, $item)
+ `;
+ const values = {
+ $key: TEST_KEY,
+ $item: TEST_ITEM,
+ };
+ db.exec(query, values);
+ });
+
+ afterEach(() => {
+ db.exec(`DELETE FROM persist_storage`);
+ });
+
+ it('should return the item of an existing key', () => {
+ expect(getPersistStorageItem(db, TEST_KEY)).toBe(TEST_ITEM);
+ });
+
+ it('should return empty string for a non-existing key', () => {
+ const nonExistingKey = 'non_existing_key';
+ expect(getPersistStorageItem(db, nonExistingKey)).toBe('');
+ });
+
+ it('should set the item of an existing key', () => {
+ const newItem = '[[{a:2]]';
+ setPersistStorageItem(db, TEST_KEY, newItem);
+ expect(getPersistStorageItem(db, TEST_KEY)).toBe(newItem);
+ });
+
+ it('should set the item of a non-existing key', () => {
+ const newEntry = 'testEntry';
+ const newData = 'testData';
+ setPersistStorageItem(db, newEntry, newData);
+ expect(getPersistStorageItem(db, newEntry)).toBe(newData);
+ expect(getPersistStorageItem(db, TEST_KEY)).toBe(TEST_ITEM);
+ });
+
+ it('should remove an existing key', () => {
+ removePersistStorageItem(db, TEST_KEY);
+ expect(getPersistStorageItem(db, TEST_KEY)).toBe('');
+ });
+
+ it('should do nothing when removing a non-existing key', () => {
+ const nonExistingName = 'non_existing_name';
+ removePersistStorageItem(db, nonExistingName);
+ expect(getPersistStorageItem(db, nonExistingName)).toBe('');
+ expect(getPersistStorageItem(db, TEST_KEY)).toBe(TEST_ITEM);
+ });
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 6, 10:59 PM (4 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5838586
Default Alt Text
D7184.1765061979.diff (2 KB)
Attached To
Mode
D7184: [web-db] add unit tests for redux-persist engine operations
Attached
Detach File
Event Timeline
Log In to Comment