Skip to content

Commit

Permalink
chore: split ImportDataConverter into multiple classes and add unit t…
Browse files Browse the repository at this point in the history
…esting (RocketChat#33394)
  • Loading branch information
pierre-lehnen-rc authored Oct 12, 2024
1 parent b9b1c0f commit 3c05136
Show file tree
Hide file tree
Showing 19 changed files with 2,680 additions and 1,337 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/app/importer-csv/server/CsvImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Random } from '@rocket.chat/random';
import { parse } from 'csv-parse/lib/sync';

import { Importer, ProgressStep, ImporterWebsocket } from '../../importer/server';
import type { IConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ImporterProgress } from '../../importer/server/classes/ImporterProgress';
import type { ImporterInfo } from '../../importer/server/definitions/ImporterInfo';
import { notifyOnSettingChanged } from '../../lib/server/lib/notifyListener';

export class CsvImporter extends Importer {
private csvParser: (csv: string) => string[];

constructor(info: ImporterInfo, importRecord: IImport, converterOptions: IConverterOptions = {}) {
constructor(info: ImporterInfo, importRecord: IImport, converterOptions: ConverterOptions = {}) {
super(info, importRecord, converterOptions);

this.csvParser = parse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';

import { Settings } from '@rocket.chat/models';
import { ImportData, Settings } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { Importer, ProgressStep } from '../../importer/server';
Expand Down Expand Up @@ -89,6 +89,13 @@ export class HipChatEnterpriseImporter extends Importer {
await super.addCountToTotal(count);
}

async findDMForImportedUsers(...users) {
const record = await ImportData.findDMForImportedUsers(...users);
if (record) {
return record.data;
}
}

async prepareUserMessagesFile(file) {
this.logger.debug(`preparing room with ${file.length} messages `);
let count = 0;
Expand All @@ -110,7 +117,7 @@ export class HipChatEnterpriseImporter extends Importer {
const users = [senderId, receiverId].sort();

if (!dmRooms[receiverId]) {
dmRooms[receiverId] = await this.converter.findDMForImportedUsers(senderId, receiverId);
dmRooms[receiverId] = await this.findDMForImportedUsers(senderId, receiverId);

if (!dmRooms[receiverId]) {
const room = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { Random } from '@rocket.chat/random';

import { FileUpload } from '../../file-upload/server';
import { Importer, ProgressStep, Selection } from '../../importer/server';
import type { IConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ImporterProgress } from '../../importer/server/classes/ImporterProgress';
import type { ImporterInfo } from '../../importer/server/definitions/ImporterInfo';

export class PendingFileImporter extends Importer {
constructor(info: ImporterInfo, importRecord: IImport, converterOptions: IConverterOptions = {}) {
constructor(info: ImporterInfo, importRecord: IImport, converterOptions: ConverterOptions = {}) {
super(info, importRecord, converterOptions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { parse } from 'csv-parse/lib/sync';

import { RocketChatFile } from '../../file/server';
import { Importer, ProgressStep } from '../../importer/server';
import type { IConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ImporterProgress } from '../../importer/server/classes/ImporterProgress';
import type { ImporterInfo } from '../../importer/server/definitions/ImporterInfo';
import { notifyOnSettingChanged } from '../../lib/server/lib/notifyListener';

export class SlackUsersImporter extends Importer {
private csvParser: (csv: string) => string[];

constructor(info: ImporterInfo, importRecord: IImport, converterOptions: IConverterOptions = {}) {
constructor(info: ImporterInfo, importRecord: IImport, converterOptions: ConverterOptions = {}) {
super(info, importRecord, converterOptions);

this.csvParser = parse;
Expand Down
Loading

0 comments on commit 3c05136

Please sign in to comment.