Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split ImportDataConverter into multiple classes and add unit testing #33394

Merged
merged 9 commits into from
Oct 12, 2024
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
Loading