Page MenuHomePhabricator

D8555.diff
No OneTemporary

D8555.diff

diff --git a/web/database/queries/metadata-queries.test.js b/web/database/queries/metadata-queries.test.js
--- a/web/database/queries/metadata-queries.test.js
+++ b/web/database/queries/metadata-queries.test.js
@@ -1,70 +1,62 @@
// @flow
-import initSqlJs from 'sql.js';
+import { getDatabaseModule } from '../db-module.js';
+import { clearSensitiveData } from '../utils/db-utils.js';
-import { setupSQLiteDB } from './db-queries.js';
-import { clearMetadata, getMetadata, setMetadata } from './metadata-queries.js';
+const FILE_PATH = 'test.sqlite';
const TEST_USER_ID_KEY = 'current_user_id';
const TEST_USER_ID_VAL = 'qwerty1234';
describe('Metadata queries', () => {
- let db;
+ let queryExecutor;
+ let dbModule;
beforeAll(async () => {
- const SQL = await initSqlJs();
- db = new SQL.Database();
+ dbModule = getDatabaseModule();
});
beforeEach(() => {
- setupSQLiteDB(db);
- const query = `
- INSERT INTO metadata (name, data)
- VALUES ($name, $val)
- `;
- const values = {
- $name: TEST_USER_ID_KEY,
- $val: TEST_USER_ID_VAL,
- };
- db.exec(query, values);
+ queryExecutor = new dbModule.SQLiteQueryExecutor(FILE_PATH);
+ queryExecutor.setMetadata(TEST_USER_ID_KEY, TEST_USER_ID_VAL);
});
afterEach(() => {
- db.exec(`DELETE FROM metadata`);
+ clearSensitiveData(dbModule, FILE_PATH, queryExecutor);
});
it('should return the data of an existing name', () => {
- expect(getMetadata(db, TEST_USER_ID_KEY)).toBe(TEST_USER_ID_VAL);
+ expect(queryExecutor.getMetadata(TEST_USER_ID_KEY)).toBe(TEST_USER_ID_VAL);
});
it('should return undefined for a non-existing name', () => {
const nonExistingName = 'non_existing_name';
- expect(getMetadata(db, nonExistingName)).toBeUndefined();
+ expect(queryExecutor.getMetadata(nonExistingName)).toBe('');
});
it('should set the data of an existing name', () => {
const newUserID = 'newID123';
- setMetadata(db, TEST_USER_ID_KEY, newUserID);
- expect(getMetadata(db, TEST_USER_ID_KEY)).toBe(newUserID);
+ queryExecutor.setMetadata(TEST_USER_ID_KEY, newUserID);
+ expect(queryExecutor.getMetadata(TEST_USER_ID_KEY)).toBe(newUserID);
});
it('should set the data of a non-existing name', () => {
const newEntry = 'testEntry';
const newData = 'testData';
- setMetadata(db, newEntry, newData);
- expect(getMetadata(db, newEntry)).toBe(newData);
- expect(getMetadata(db, TEST_USER_ID_KEY)).toBe(TEST_USER_ID_VAL);
+ queryExecutor.setMetadata(newEntry, newData);
+ expect(queryExecutor.getMetadata(newEntry)).toBe(newData);
+ expect(queryExecutor.getMetadata(TEST_USER_ID_KEY)).toBe(TEST_USER_ID_VAL);
});
it('should clear an existing entry', () => {
- clearMetadata(db, TEST_USER_ID_KEY);
- expect(getMetadata(db, TEST_USER_ID_KEY)).toBeUndefined();
+ queryExecutor.clearMetadata(TEST_USER_ID_KEY);
+ expect(queryExecutor.getMetadata(TEST_USER_ID_KEY)).toBe('');
});
it('should do nothing when clearing a non-existing entry', () => {
const nonExistingName = 'non_existing_name';
- clearMetadata(db, nonExistingName);
- expect(getMetadata(db, nonExistingName)).toBeUndefined();
- expect(getMetadata(db, TEST_USER_ID_KEY)).toBe(TEST_USER_ID_VAL);
+ queryExecutor.clearMetadata(nonExistingName);
+ expect(queryExecutor.getMetadata(nonExistingName)).toBe('');
+ expect(queryExecutor.getMetadata(TEST_USER_ID_KEY)).toBe(TEST_USER_ID_VAL);
});
});

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 7:52 AM (13 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2699097
Default Alt Text
D8555.diff (3 KB)

Event Timeline