Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33000099
D14450.1768352447.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D14450.1768352447.diff
View Options
diff --git a/lib/ops/dm-operations-store-ops.js b/lib/ops/dm-operations-store-ops.js
--- a/lib/ops/dm-operations-store-ops.js
+++ b/lib/ops/dm-operations-store-ops.js
@@ -44,3 +44,17 @@
| ClientDBReplaceDMOperationOperation
| RemoveDMOperationsOperation
| RemoveAllDMOperationsOperation;
+
+function convertDMOperationIntoClientDBDMOperation({
+ id,
+ type,
+ operation,
+}: Operation): ClientDBDMOperation {
+ return {
+ id,
+ type,
+ operation: JSON.stringify(operation),
+ };
+}
+
+export { convertDMOperationIntoClientDBDMOperation };
diff --git a/web/shared-worker/queries/dm-operations-queries.test.js b/web/shared-worker/queries/dm-operations-queries.test.js
new file mode 100644
--- /dev/null
+++ b/web/shared-worker/queries/dm-operations-queries.test.js
@@ -0,0 +1,106 @@
+// @flow
+
+import { convertDMOperationIntoClientDBDMOperation } from 'lib/ops/dm-operations-store-ops.js';
+
+import { getDatabaseModule } from '../db-module.js';
+import type { EmscriptenModule } from '../types/module.js';
+import type { SQLiteQueryExecutor } from '../types/sqlite-query-executor.js';
+import { clearSensitiveData } from '../utils/db-utils.js';
+
+const FILE_PATH = 'test.sqlite';
+
+const TEST_OPERATION_1 = {
+ type: 'send_text_message',
+ threadID: '0',
+ creatorID: '2',
+ time: 3,
+ messageID: '2',
+ text: 'abc123',
+};
+
+const TEST_OPERATION_2 = {
+ type: 'leave_thread',
+ editorID: '5',
+ time: 12,
+ messageID: '3',
+ threadID: '0',
+};
+
+describe('DM Operations Store queries', () => {
+ let queryExecutor: ?SQLiteQueryExecutor = null;
+ let dbModule: ?EmscriptenModule = null;
+
+ beforeAll(async () => {
+ dbModule = getDatabaseModule();
+ });
+
+ beforeEach(() => {
+ if (!dbModule) {
+ throw new Error('Database module is missing');
+ }
+ queryExecutor = new dbModule.SQLiteQueryExecutor(FILE_PATH);
+ if (!queryExecutor) {
+ throw new Error('SQLiteQueryExecutor is missing');
+ }
+
+ queryExecutor?.replaceDMOperation(
+ convertDMOperationIntoClientDBDMOperation({
+ id: '0',
+ type: TEST_OPERATION_1.type,
+ operation: TEST_OPERATION_1,
+ }),
+ );
+
+ queryExecutor?.replaceDMOperation(
+ convertDMOperationIntoClientDBDMOperation({
+ id: '1',
+ type: TEST_OPERATION_2.type,
+ operation: TEST_OPERATION_2,
+ }),
+ );
+ });
+
+ afterEach(() => {
+ if (!dbModule || !queryExecutor) {
+ return;
+ }
+ clearSensitiveData(dbModule, FILE_PATH, queryExecutor);
+ });
+
+ it('should return all operations', () => {
+ const operations = queryExecutor?.getAllDMOperations();
+ expect(operations?.length).toBe(2);
+ });
+
+ it('should remove all operations', () => {
+ queryExecutor?.removeAllDMOperations();
+ const operations = queryExecutor?.getAllDMOperations();
+ expect(operations?.length).toBe(0);
+ });
+
+ it('should remove operation', () => {
+ queryExecutor?.removeDMOperations(['0']);
+ const operations = queryExecutor?.getAllDMOperations();
+ expect(operations?.length).toBe(1);
+ expect(operations?.[0]).toEqual(
+ convertDMOperationIntoClientDBDMOperation({
+ id: '1',
+ type: TEST_OPERATION_2.type,
+ operation: TEST_OPERATION_2,
+ }),
+ );
+ });
+
+ it('should query operations by type', () => {
+ const operations =
+ queryExecutor?.getDMOperationsByType('send_text_message');
+ expect(operations?.length).toBe(1);
+ expect(operations?.[0]).toEqual(
+ convertDMOperationIntoClientDBDMOperation({
+ id: '0',
+ type: TEST_OPERATION_1.type,
+ operation: TEST_OPERATION_1,
+ }),
+ );
+ });
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 14, 1:00 AM (3 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5929674
Default Alt Text
D14450.1768352447.diff (3 KB)
Attached To
Mode
D14450: [web] Add SQLite query executor tests
Attached
Detach File
Event Timeline
Log In to Comment