forked from Ivasoft/mattermost-mobile
MM_33226 [v2] DataOperator - User section (#5255)
* MM_30475 : ADDED default schema
* MM_30475 : ADDED todo for field 'value' of default/Global entity
* MM_30476 : Created schema for SERVER DB
* MM_30476 : Server model [ IN PROGRESS ]
* MM_30476 : Including types for group, groups_in_channel and role
* MM_30476 : ADDED models for Group
- @typings absolute path has been added to the tsconfig.json
* MM_30476 : ADDED typings to current models
* MM_30476 : ADDED typings to current models
* MM_30476 : ADDED models related to TEAM section of the ERD
* MM_30476 : ADDED models for User section of the ERD
* MM_30476 : ADDED models for POST section of the ERD
* MM_30476 : ADDED models for Channel section of the ERD
* MM_30475 : Updated typings and references to MM_TABLES
* MM_30476 : Verified all field names
* MM_30476 : Verified every table associations
* MM_30476 : Verified all relation fields
* MM_30476 : Updated primary id of the main models
We will override the wdb id at component level when we create a new records. This involves the models : channel, group, post, team and user.
* MM_30476 : Including 1:1 relationship amongs some entities
* MM_30476 : ADDED Schema Managers
* The migration array will hold all the migration steps.
* The initial app release (e.g. v2 )will have an empty array and subsequent releases (e.g. v2.1 ) will have the steps listed in that array.
* On initialization, the database will perform the migration to accomodate for new columns/tables creation and while it will conserve the mobile phone's data, it will also make it conform to this new schema.
* If a migration fails, the migration process will rollback any changes. This migration will be thoroughly tested in development before pushing it live.
* Revert "MM_30476 : ADDED Schema Managers"
This reverts commit a505bd5e11.
* MM_30478 : Converted schema_manager into a function
* MM_30478 : Updated schema manager and included patch for wdb
* MM_30478: Updated watermelondb patch package
* MM_30478 : Update function create_schema_manager to createSqliteAdaptorOptions
* MM_30476 : Update constant name to reflect directory name
* MM_30476 : Updated msgCount from my_channel model to message_count in server schema
* MM_30482 : Added tests for schema_manager
* MM_30482 : Database Manager [ IN PROGRESS ]
* MM_30478 : Returning an sqliteAdapter instead of an object
* MM_30476 : Apply suggestions from code review
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
* MM_30476 : Updated all imports as per instruction.
* MM_30476 : Shortening object chains by destructuring
* MM_30476 : Updated schema file structure
* MM_30476 : Prettifying @typings folder
* MM_30476 : Removing useless ids
* MM_30476 : Prettify imports for decorators
* MM_30476 : ADDED documentations and lazy queries to Channel and Channel_Info
* MM_30476 : ADDED documentations for default schema
* MM_30476 : Documentation [ IN PROGRESS ]
- Following JSDoc syntax for single line comment
- Removed redundant fields in the 'membership' tables and left only the @relation records.
* MM_30476 : Documentations [ IN PROGRESS ]
* MM_30476 : Documentations [ IN PROGRESS ]
* MM_30476 : Documentations [ IN PROGRESS ]
* MM_30476 : Documentations [ IN PROGRESS]
Updated
1) my_team and team,
2) my_channel and channel,
to each have 1:1 relationship with one another
* MM_30476 : Updated all Typescript definitions
* MM_30476 :Updated @relation to @immutableRelation
* MM_30476 : Updated description for previous_post_id
* MM_30478 : Updated patch package for wdb module
* MM_30478: DB Manager [IN PROGRESS ]
* MM_30478: DB Manager [IN PROGRESS]
* MM_30478: DB Manager [IN PROGRESS]
* MM_30478 : DB Manager [IN PROGRESS]
* MM_30478 : Deleting .db file on iOS
* MM_30478: Successfully deleting .db files and directory on iOS side
* MM_30478 : Update definition for default/global
* MM_30478 : Updated all models
* MM_30478 : Doing a bit of house cleaning
* MM_30478: Record of new server connection added to default/servers db
* TS Definitely Typed Assignment issue is now FIXED
* MM_30478 : TS Definitely Typed Assignment \n Removed all the constructors but error still in editor tabs. But this time the app is not crashing
* MM_30478 : Attempt 1 [SUCCESSFUL]
* MM_30478 : Removing useDefineForClassFields
* MM_30478 : Retrieving the servers in a list + Improved the DB Manager and Babel config
* MM_30478 : Updated babel.config.js
* MM_30478 : Minor UI correction
* MM_30478 : Jest and Typescript configuration
* MM_30478 : A bit of housekeeping
* MM_30478 : Installed WDB on Android
* MM_30478 : Deletes new server record from default DB
* MM_30478 : Returns subset of server db instances
* MM_30478 : Code clean up
* MM_30478 : Code clean up on db manager
* MM_30478 : House keeping + Patch for WDB
* MM_30478 : Android - Saving & Deleting in FilesDir [COMPLETED]
* MM_30478 : Code clean up
* MM_30478 : Code clean up
* MM_30478 : Code clean up
* MM_30478 : Test successful on Android device
* MM_30478 : Rolling back change to jest.config.js
* MM_30478 : Updated test to test_integration
* MM_30478 : Fix imports
* MM_30478 : Refactored the manual testscript
* MM_30478 : Renamed database manager test file
* MM_30478 : Code clean up
* MM_30478 : Updated manual test file with a note.
* MM_30482 : DataOperator [ IN PROGRESS ]
* MM_30482 : DataOperator - setting up the factory [ IN PROGRESS ]
* MM_30482: Code refactoring
* MM_30482 : DataOperator - setting up the factory [ IN PROGRESS ]
* MM_30482 : DataOperator - code clean up [ IN PROGRESS ]
* MM_30482 : Minor code clean up
* MM_30478 : Fixed JEST issue with TS
* MM_30478 : Fixed JEST issue with TS
* MM_30478 : Fixed JEST issue with TS
* MM_30478 : Implementing JEST test cases
* MM_30478 : Implementing JEST last test cases
* MM_30478 : Jest fixing ts errors
* MM_30478 : Database Manager Jest testing [ IN PROGRESS ]
* MM_30482 - Fixing DataOperator [ IN PROGRESS ]
* MM_30482 : Code clean up
* MM_30482 - Creates multiple records [ IN PROGRESS ]
* MM_30482 - Creates multiple records [ IN PROGRESS ]
* MM_30482 : Update operation [ COMPLETED ]
* MM_30482 : Code clean up
* MM_30482 : Updated TS for Data Operator
* Update mobile v2 detox deps
* MM_30482 : Added factories for all isolated tables
* MM_30482 : Refactored TS
* MM_30482 : Refactored base factory
* MM_30482 : Updated JSDoc for operateBaseRecord - Delete CASE
* MM_30482 : Implementing test for Data Operator
* MM_30482 : Completed tests for all isolated tables
* MM_30482 : Renamed entity_factory into operators
* MM_30482 : Fix all imports
* MM_30482 : Update multiple records
* MM_30482 : Edge case for existing records ( update instead of create )
* MM_30482 : Edge case - create instead of update
* MM_30482 : Code clean up
* MM_30482 : Code clean up
* MM_30482 : Code clean up
* MM_30482 : Code clean up
* Update app/database/admin/data_operator/operators.ts
Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
* Update app/database/admin/data_operator/operators.ts
Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
* Update app/database/admin/data_operator/operators.ts
Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
* MM_30482 : Imposing usage of correct table name for isolated entities
* MM_30482 : Code improvement as per Joseph reviews
* MM_30482 : Updated tests to validate choice of operator service wrt tableName
* MM_30482 : Updated PR as per suggestions
* MM_30482 : Updated comments to follow jsdoc conventions
* MM_33223 : Renamed DBInstance to DatabaseInstance
* MM_33223 : ADDED Prettier
* MM_33223 - Prettier formatting
* MM_33223 : Prettier formatting
* MM_33223 - Post section [ in progress ]
* MM_33223 : PostsInThread [99% completed ]
* MM_33223: Reaction entity completed
* MM_33223: Added Reaction to the Post
* MM_33223 : Refactored reactions utils
* MM_33223 : Added previous post id to all posts
* MM_33223 : Added File Metadata
* MM_33223 : Code clean up
* MM_33223 : Added PostMetadata
* MM_33223 : Added Draft
* MM_33223 - Removed Prettier
* MM_33223 - Undo files changes due to Prettier
* MM_33223 : Making use of MM eslint plugins
* MM_33223 : PostsInChannel [ IN PROGRESS ]
* MM_33223 : Including update_at in Post schema
* MM_33223: Code clean up
* MM_33223: Code clean up
* MM_33223 : Code clean up
* MM_33223: Testing Reaction [IN PROGRESS]
* MM_33223 : Updated typings for RawCustomEmoji in Reactions
* MM_33223 : Refactored DataOperator test
* MM_33223 : Jest - handleReactions - Completed
* MM_33223 : Jest - HandleDraft - Completed
* MM_33223 : Jest - HandleFiles - Completed
* MM_33223 : Refactored DataOperator-PostMetadata
* MM_33223 : Jest - HandlePostMetadata - Completed
* MM_33223 : Refactored posts into ordered and unordered
* MM_33223 : Refactoring + Jest Utils [ IN PROGRESS ]
* MM_33223 - Jest Utils - Completed
* MM_33223 : Jest - Remaining operators - Completed
* MM_33223 : Jest - Handler PostsInThread - Completed
* MM_33223 : Jest - HandlePostsInChannel - Completed
* MM_33223 : Refactored DataOperator class
* MM_33223 : DataOperator test clean up
* MM_33223 : DataOperator code clean up
* MM_33223 : Jest - HandlePosts - Completed
* MM_33223: JSDoc - Operators - Completed
* MM_33223 : Refactoring file types.ts
* MM_33223 : Refactored import statements
* MM_33223 : Added @database alias
* MM_33223 : Added missing JSDoc
* MM_33223 : Minor code clean up
* MM_33223 : Lint fixed
* MM_33223 : Disable eslint rules for Notification
* MM_33223 : Disable eslint rule for screens
* Update app/database/admin/data_operator/index.ts
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
* MM_33223 : Update data_operatator as per suggestion
* MM_33226: Removed optType
* MM_33226 : ADDED User Handler+Operator+Jest, Included update_at field for User
* MM_33226 : Preference entity - Completed
* MM_33226 : Team Membership entity - Completed
* MM_33226 : Team Membership - Jest - Completed
* MM_33226 : Removing duplicates for TeamMembership and Preferences
* MM_33226 : Refactored Custom Emojis to remove duplicates
* MM_33226 : Group Membership - Completed
* MM_33226 : ChannelMembership - Completed
* MM_33226 : Refactored some handlers whose response have no Ids
* MM_33226 : Refactoring - in progress
* MM_33226 : Refactoring - in progress
* MM_33226 : Refactoring - in progress
* MM_33226 : Code clean up
* MM_33226 : Polishing Operator tests
* MM_33226 : Removing redundant test cases
* MM_33226 : Polishing Operators
* MM_33226 : Testing for duplicate post id in Raw values
* MM_33226 : Including some error-throwing in the Database Manager
* MM_33226 : Merged in DataOperator/Post-section
* MM_33226 : Fixing the merging issues
* MM_33226 : fixing merge issues
* MM_33226 : Code polishing
* MM_33226 : Enabling user notify props comment
* MM_33226 : Correcting type casting
* MM_33226 : Correcting data operators
* MM_33226 : Corrections
* MM_33226 : Code clean up
* MM_33226 : Rename oneOfField to fieldName
* MM_33226 : Renaming comparators to Boolean name and oneOfField to fieldName
* MM_33226 : Putting back custom emoji into handleIsolatedEntity
* MM_33226 : Comparing simple arrays
* MM_33226 : Renaming DiscardDuplicates to ProcessInputs
* MM_33226 : Sort imports
* MM_33226 : Types clean up
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
Co-authored-by: Avinash Lingaloo <>
Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import DatabaseManager from '@database/admin/database_manager';
|
||||
import DataOperator from '@database/admin/data_operator';
|
||||
import {
|
||||
isRecordAppEqualToRaw,
|
||||
isRecordDraftEqualToRaw,
|
||||
isRecordGlobalEqualToRaw,
|
||||
isRecordRoleEqualToRaw,
|
||||
isRecordServerEqualToRaw,
|
||||
isRecordSystemEqualToRaw,
|
||||
isRecordTermsOfServiceEqualToRaw,
|
||||
} from '@database/admin/data_operator/comparators';
|
||||
import DataOperatorException from '@database/admin/exceptions/data_operator_exception';
|
||||
import {DatabaseType, IsolatedEntities} from '@typings/database/enums';
|
||||
|
||||
import {
|
||||
operateAppRecord,
|
||||
operateCustomEmojiRecord,
|
||||
operateDraftRecord,
|
||||
operateGlobalRecord,
|
||||
operateRoleRecord,
|
||||
@@ -19,7 +26,7 @@ import {
|
||||
|
||||
jest.mock('@database/admin/database_manager');
|
||||
|
||||
const {DRAFT} = MM_TABLES.SERVER;
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const createConnection = async (setActive = false) => {
|
||||
@@ -51,31 +58,31 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const defaultDB = await DatabaseManager.getDefaultDatabase();
|
||||
expect(defaultDB).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
|
||||
const data = {
|
||||
tableName: IsolatedEntities.APP,
|
||||
values: [
|
||||
{
|
||||
buildNumber: 'build-10x',
|
||||
createdAt: 1,
|
||||
id: 'id-21',
|
||||
versionNumber: 'version-10',
|
||||
},
|
||||
{
|
||||
buildNumber: 'build-11y',
|
||||
createdAt: 1,
|
||||
id: 'id-22',
|
||||
versionNumber: 'version-11',
|
||||
},
|
||||
],
|
||||
};
|
||||
const values = [
|
||||
{
|
||||
buildNumber: 'build-10x',
|
||||
createdAt: 1,
|
||||
id: 'id-21',
|
||||
versionNumber: 'version-10',
|
||||
},
|
||||
{
|
||||
buildNumber: 'build-11y',
|
||||
createdAt: 1,
|
||||
id: 'id-22',
|
||||
versionNumber: 'version-11',
|
||||
},
|
||||
];
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
await DataOperator.handleIsolatedEntity({tableName: IsolatedEntities.APP, values});
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateAppRecord,
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
fieldName: 'version_number',
|
||||
operator: operateAppRecord,
|
||||
comparator: isRecordAppEqualToRaw,
|
||||
rawValues: values,
|
||||
tableName: 'app',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,20 +92,17 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const defaultDB = await DatabaseManager.getDefaultDatabase();
|
||||
expect(defaultDB).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
const values = [{id: 'global-1-id', name: 'global-1-name', value: 'global-1-value'}];
|
||||
|
||||
const data = {
|
||||
tableName: IsolatedEntities.GLOBAL,
|
||||
values: [
|
||||
{id: 'global-1-id', name: 'global-1-name', value: 'global-1-value'},
|
||||
],
|
||||
};
|
||||
await DataOperator.handleIsolatedEntity({tableName: IsolatedEntities.GLOBAL, values});
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateGlobalRecord,
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
comparator: isRecordGlobalEqualToRaw,
|
||||
fieldName: 'name',
|
||||
operator: operateGlobalRecord,
|
||||
rawValues: values,
|
||||
tableName: 'global',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,53 +112,25 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const defaultDB = await DatabaseManager.getDefaultDatabase();
|
||||
expect(defaultDB).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
const values = [
|
||||
{
|
||||
dbPath: 'server.db',
|
||||
displayName: 'community',
|
||||
id: 'server-id-1',
|
||||
mentionCount: 0,
|
||||
unreadCount: 0,
|
||||
url: 'https://community.mattermost.com',
|
||||
},
|
||||
];
|
||||
await DataOperator.handleIsolatedEntity({tableName: IsolatedEntities.SERVERS, values});
|
||||
|
||||
const data = {
|
||||
tableName: IsolatedEntities.SERVERS,
|
||||
values: [
|
||||
{
|
||||
dbPath: 'server.db',
|
||||
displayName: 'community',
|
||||
id: 'server-id-1',
|
||||
mentionCount: 0,
|
||||
unreadCount: 0,
|
||||
url: 'https://community.mattermost.com',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateServersRecord,
|
||||
});
|
||||
});
|
||||
|
||||
it('=> HandleCustomEmoji: should write to CUSTOM_EMOJI entity', async () => {
|
||||
expect.assertions(2);
|
||||
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
const data = {
|
||||
tableName: IsolatedEntities.CUSTOM_EMOJI,
|
||||
values: [
|
||||
{
|
||||
id: 'custom-emoji-id-1',
|
||||
name: 'custom-emoji-1',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateCustomEmojiRecord,
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
comparator: isRecordServerEqualToRaw,
|
||||
fieldName: 'db_path',
|
||||
operator: operateServersRecord,
|
||||
rawValues: values,
|
||||
tableName: 'servers',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -164,24 +140,26 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
const values = [
|
||||
{
|
||||
id: 'custom-emoji-id-1',
|
||||
name: 'custom-emoji-1',
|
||||
permissions: ['custom-emoji-1'],
|
||||
},
|
||||
];
|
||||
|
||||
const data = {
|
||||
await DataOperator.handleIsolatedEntity({
|
||||
tableName: IsolatedEntities.ROLE,
|
||||
values: [
|
||||
{
|
||||
id: 'custom-emoji-id-1',
|
||||
name: 'custom-emoji-1',
|
||||
permissions: ['custom-emoji-1'],
|
||||
},
|
||||
],
|
||||
};
|
||||
values,
|
||||
});
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateRoleRecord,
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
comparator: isRecordRoleEqualToRaw,
|
||||
fieldName: 'name',
|
||||
operator: operateRoleRecord,
|
||||
rawValues: values,
|
||||
tableName: 'Role',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -191,18 +169,16 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
const values = [{id: 'system-id-1', name: 'system-1', value: 'system-1'}];
|
||||
await DataOperator.handleIsolatedEntity({tableName: IsolatedEntities.SYSTEM, values});
|
||||
|
||||
const data = {
|
||||
tableName: IsolatedEntities.SYSTEM,
|
||||
values: [{id: 'system-id-1', name: 'system-1', value: 'system-1'}],
|
||||
};
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateSystemRecord,
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
comparator: isRecordSystemEqualToRaw,
|
||||
fieldName: 'name',
|
||||
operator: operateSystemRecord,
|
||||
rawValues: values,
|
||||
tableName: 'System',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -212,18 +188,29 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
|
||||
const data = {
|
||||
const values = [
|
||||
{
|
||||
id: 'tos-1',
|
||||
acceptedAt: 1,
|
||||
create_at: 1613667352029,
|
||||
user_id: 'user1613667352029',
|
||||
text: '',
|
||||
},
|
||||
];
|
||||
|
||||
await DataOperator.handleIsolatedEntity({
|
||||
tableName: IsolatedEntities.TERMS_OF_SERVICE,
|
||||
values: [{id: 'tos-1', acceptedAt: 1}],
|
||||
};
|
||||
values,
|
||||
});
|
||||
|
||||
await DataOperator.handleIsolatedEntity(data);
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
...data,
|
||||
recordOperator: operateTermsOfServiceRecord,
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
comparator: isRecordTermsOfServiceEqualToRaw,
|
||||
fieldName: 'accepted_at',
|
||||
operator: operateTermsOfServiceRecord,
|
||||
rawValues: values,
|
||||
tableName: 'TermsOfService',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -233,16 +220,16 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const defaultDB = await DatabaseManager.getDefaultDatabase();
|
||||
expect(defaultDB).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await DataOperator.handleIsolatedEntity({
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
tableName: 'INVALID_TABLE_NAME',
|
||||
values: [{id: 'tos-1', acceptedAt: 1}],
|
||||
});
|
||||
|
||||
expect(spyOnHandleBase).toHaveBeenCalledTimes(0);
|
||||
await expect(
|
||||
DataOperator.handleIsolatedEntity({
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
tableName: 'INVALID_TABLE_NAME',
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
values: [{id: 'tos-1', acceptedAt: 1}],
|
||||
}),
|
||||
).rejects.toThrow(DataOperatorException);
|
||||
});
|
||||
|
||||
it('=> HandleReactions: should write to both Reactions and CustomEmoji entities', async () => {
|
||||
@@ -251,7 +238,7 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnPrepareBase = jest.spyOn(DataOperator as any, 'prepareRecords');
|
||||
const spyOnPrepareRecords = jest.spyOn(DataOperator as any, 'prepareRecords');
|
||||
const spyOnBatchOperation = jest.spyOn(DataOperator as any, 'batchOperations');
|
||||
|
||||
await DataOperator.handleReactions({
|
||||
@@ -269,7 +256,7 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
});
|
||||
|
||||
// Called twice: Once for Reaction record and once for CustomEmoji record
|
||||
expect(spyOnPrepareBase).toHaveBeenCalledTimes(2);
|
||||
expect(spyOnPrepareRecords).toHaveBeenCalledTimes(2);
|
||||
|
||||
// Only one batch operation for both entities
|
||||
expect(spyOnBatchOperation).toHaveBeenCalledTimes(1);
|
||||
@@ -281,9 +268,8 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnHandleBase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
const data = [
|
||||
const spyOnHandleEntityRecords = jest.spyOn(DataOperator as any, 'handleEntityRecords');
|
||||
const values = [
|
||||
{
|
||||
channel_id: '4r9jmr7eqt8dxq3f9woypzurrychannelid',
|
||||
files: [
|
||||
@@ -307,13 +293,15 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
root_id: '',
|
||||
},
|
||||
];
|
||||
await DataOperator.handleDraft(data);
|
||||
|
||||
// Only one batch operation for both entities
|
||||
expect(spyOnHandleBase).toHaveBeenCalledWith({
|
||||
tableName: DRAFT,
|
||||
values: data,
|
||||
recordOperator: operateDraftRecord,
|
||||
await DataOperator.handleDraft(values);
|
||||
|
||||
expect(spyOnHandleEntityRecords).toHaveBeenCalledWith({
|
||||
comparator: isRecordDraftEqualToRaw,
|
||||
fieldName: 'channel_id',
|
||||
operator: operateDraftRecord,
|
||||
rawValues: values,
|
||||
tableName: 'Draft',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -323,7 +311,7 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
const database = await createConnection(true);
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const spyOnPrepareBase = jest.spyOn(DataOperator as any, 'prepareRecords');
|
||||
const spyOnPrepareRecords = jest.spyOn(DataOperator as any, 'prepareRecords');
|
||||
const spyOnBatchOperation = jest.spyOn(DataOperator as any, 'batchOperations');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
@@ -348,7 +336,7 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
prepareRowsOnly: false,
|
||||
});
|
||||
|
||||
expect(spyOnPrepareBase).toHaveBeenCalledTimes(1);
|
||||
expect(spyOnPrepareRecords).toHaveBeenCalledTimes(1);
|
||||
expect(spyOnBatchOperation).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -508,10 +496,10 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnHandleReactions = jest.spyOn(DataOperator as any, 'handleReactions');
|
||||
const spyOnHandleFiles = jest.spyOn(DataOperator as any, 'handleFiles');
|
||||
const spyOnHandlePostMetadata = jest.spyOn(DataOperator as any, 'handlePostMetadata');
|
||||
const spyOnHandleIsolatedEntity = jest.spyOn(DataOperator as any, 'handleIsolatedEntity');
|
||||
const spyOnHandleReactions = jest.spyOn(DataOperator as any, 'handleReactions');
|
||||
const spyOnHandleCustomEmojis = jest.spyOn(DataOperator as any, 'handleIsolatedEntity');
|
||||
const spyOnHandlePostsInThread = jest.spyOn(DataOperator as any, 'handlePostsInThread');
|
||||
const spyOnHandlePostsInChannel = jest.spyOn(DataOperator as any, 'handlePostsInChannel');
|
||||
|
||||
@@ -617,8 +605,8 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
prepareRowsOnly: true,
|
||||
});
|
||||
|
||||
expect(spyOnHandleIsolatedEntity).toHaveBeenCalledTimes(1);
|
||||
expect(spyOnHandleIsolatedEntity).toHaveBeenCalledWith({
|
||||
expect(spyOnHandleCustomEmojis).toHaveBeenCalledTimes(1);
|
||||
expect(spyOnHandleCustomEmojis).toHaveBeenCalledWith({
|
||||
tableName: 'CustomEmoji',
|
||||
values: [
|
||||
{
|
||||
@@ -633,9 +621,225 @@ describe('*** DataOperator: Handlers tests ***', () => {
|
||||
});
|
||||
|
||||
expect(spyOnHandlePostsInThread).toHaveBeenCalledTimes(1);
|
||||
expect(spyOnHandlePostsInThread).toHaveBeenCalledWith([{earliest: 1596032651747, post_id: '8swgtrrdiff89jnsiwiip3y1eoe'}]);
|
||||
expect(spyOnHandlePostsInThread).toHaveBeenCalledWith([
|
||||
{earliest: 1596032651747, post_id: '8swgtrrdiff89jnsiwiip3y1eoe'},
|
||||
]);
|
||||
|
||||
expect(spyOnHandlePostsInChannel).toHaveBeenCalledTimes(1);
|
||||
expect(spyOnHandlePostsInChannel).toHaveBeenCalledWith(posts.slice(0, 3));
|
||||
});
|
||||
|
||||
it('=> HandleUsers: should write to User entity', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const users = [
|
||||
{
|
||||
id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
create_at: 1599457495881,
|
||||
update_at: 1607683720173,
|
||||
delete_at: 0,
|
||||
username: 'a.l',
|
||||
auth_service: 'saml',
|
||||
email: 'a.l@mattermost.com',
|
||||
email_verified: true,
|
||||
is_bot: false,
|
||||
nickname: '',
|
||||
first_name: 'A',
|
||||
last_name: 'L',
|
||||
position: 'Mobile Engineer',
|
||||
roles: 'system_user',
|
||||
props: {},
|
||||
notify_props: {
|
||||
desktop: 'all',
|
||||
desktop_sound: true,
|
||||
email: true,
|
||||
first_name: true,
|
||||
mention_keys: '',
|
||||
push: 'mention',
|
||||
channel: true,
|
||||
auto_responder_active: false,
|
||||
auto_responder_message:
|
||||
'Hello, I am out of office and unable to respond to messages.',
|
||||
comments: 'never',
|
||||
desktop_notification_sound: 'Hello',
|
||||
push_status: 'online',
|
||||
},
|
||||
last_password_update: 1604323112537,
|
||||
last_picture_update: 1604686302260,
|
||||
locale: 'en',
|
||||
timezone: {
|
||||
automaticTimezone: 'Indian/Mauritius',
|
||||
manualTimezone: '',
|
||||
useAutomaticTimezone: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnExecuteInDatabase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await createConnection(true);
|
||||
|
||||
await DataOperator.handleUsers(users);
|
||||
|
||||
expect(spyOnExecuteInDatabase).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('=> HandlePreferences: should write to PREFERENCE entity', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const preferences = [
|
||||
{
|
||||
user_id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
category: 'group_channel_show',
|
||||
name: 'qj91hepgjfn6xr4acm5xzd8zoc',
|
||||
value: 'true',
|
||||
},
|
||||
{
|
||||
user_id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
category: 'notifications',
|
||||
name: 'email_interval',
|
||||
value: '30',
|
||||
},
|
||||
{
|
||||
user_id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
category: 'theme',
|
||||
name: '',
|
||||
value:
|
||||
'{"awayIndicator":"#c1b966","buttonBg":"#4cbba4","buttonColor":"#ffffff","centerChannelBg":"#2f3e4e","centerChannelColor":"#dddddd","codeTheme":"solarized-dark","dndIndicator":"#e81023","errorTextColor":"#ff6461","image":"/static/files/0b8d56c39baf992e5e4c58d74fde0fd6.png","linkColor":"#a4ffeb","mentionBg":"#b74a4a","mentionColor":"#ffffff","mentionHighlightBg":"#984063","mentionHighlightLink":"#a4ffeb","newMessageSeparator":"#5de5da","onlineIndicator":"#65dcc8","sidebarBg":"#1b2c3e","sidebarHeaderBg":"#1b2c3e","sidebarHeaderTextColor":"#ffffff","sidebarText":"#ffffff","sidebarTextActiveBorder":"#66b9a7","sidebarTextActiveColor":"#ffffff","sidebarTextHoverBg":"#4a5664","sidebarUnreadText":"#ffffff","type":"Mattermost Dark"}',
|
||||
},
|
||||
{
|
||||
user_id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
category: 'tutorial_step',
|
||||
name: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
value: '2',
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnExecuteInDatabase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await createConnection(true);
|
||||
|
||||
await DataOperator.handlePreferences(preferences);
|
||||
|
||||
expect(spyOnExecuteInDatabase).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('=> HandleTeamMemberships: should write to TEAM_MEMBERSHIP entity', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const teamMembership = [
|
||||
{
|
||||
team_id: 'a',
|
||||
user_id: 'ab',
|
||||
roles: '3ngdqe1e7tfcbmam4qgnxp91bw',
|
||||
delete_at: 0,
|
||||
scheme_guest: false,
|
||||
scheme_user: true,
|
||||
scheme_admin: false,
|
||||
explicit_roles: '',
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnExecuteInDatabase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await createConnection(true);
|
||||
|
||||
await DataOperator.handleTeamMemberships(teamMembership);
|
||||
|
||||
expect(spyOnExecuteInDatabase).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('=> HandleCustomEmojis: should write to CUSTOM_EMOJI entity', async () => {
|
||||
expect.assertions(1);
|
||||
const emojis = [
|
||||
{
|
||||
id: 'i',
|
||||
create_at: 1580913641769,
|
||||
update_at: 1580913641769,
|
||||
delete_at: 0,
|
||||
creator_id: '4cprpki7ri81mbx8efixcsb8jo',
|
||||
name: 'boomI',
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnExecuteInDatabase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await createConnection(true);
|
||||
|
||||
await DataOperator.handleIsolatedEntity({tableName: IsolatedEntities.CUSTOM_EMOJI, values: emojis});
|
||||
|
||||
expect(spyOnExecuteInDatabase).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('=> HandleGroupMembership: should write to GROUP_MEMBERSHIP entity', async () => {
|
||||
expect.assertions(1);
|
||||
const groupMemberships = [
|
||||
{
|
||||
user_id: 'u4cprpki7ri81mbx8efixcsb8jo',
|
||||
group_id: 'g4cprpki7ri81mbx8efixcsb8jo',
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnExecuteInDatabase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await createConnection(true);
|
||||
|
||||
await DataOperator.handleGroupMembership(groupMemberships);
|
||||
|
||||
expect(spyOnExecuteInDatabase).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('=> HandleChannelMembership: should write to CHANNEL_MEMBERSHIP entity', async () => {
|
||||
expect.assertions(1);
|
||||
const channelMemberships = [
|
||||
{
|
||||
channel_id: '17bfnb1uwb8epewp4q3x3rx9go',
|
||||
user_id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
roles: 'wqyby5r5pinxxdqhoaomtacdhc',
|
||||
last_viewed_at: 1613667352029,
|
||||
msg_count: 3864,
|
||||
mention_count: 0,
|
||||
notify_props: {
|
||||
desktop: 'default',
|
||||
email: 'default',
|
||||
ignore_channel_mentions: 'default',
|
||||
mark_unread: 'mention',
|
||||
push: 'default',
|
||||
},
|
||||
last_update_at: 1613667352029,
|
||||
scheme_guest: false,
|
||||
scheme_user: true,
|
||||
scheme_admin: false,
|
||||
explicit_roles: '',
|
||||
},
|
||||
{
|
||||
channel_id: '1yw6gxfr4bn1jbyp9nr7d53yew',
|
||||
user_id: '9ciscaqbrpd6d8s68k76xb9bte',
|
||||
roles: 'channel_user',
|
||||
last_viewed_at: 1615300540549,
|
||||
msg_count: 16,
|
||||
mention_count: 0,
|
||||
notify_props: {
|
||||
desktop: 'default',
|
||||
email: 'default',
|
||||
ignore_channel_mentions: 'default',
|
||||
mark_unread: 'all',
|
||||
push: 'default',
|
||||
},
|
||||
last_update_at: 1615300540549,
|
||||
scheme_guest: false,
|
||||
scheme_user: true,
|
||||
scheme_admin: false,
|
||||
explicit_roles: '',
|
||||
},
|
||||
];
|
||||
|
||||
const spyOnExecuteInDatabase = jest.spyOn(DataOperator as any, 'executeInDatabase');
|
||||
|
||||
await createConnection(true);
|
||||
|
||||
await DataOperator.handleChannelMembership(channelMemberships);
|
||||
|
||||
expect(spyOnExecuteInDatabase).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user