Skip to content

Commit

Permalink
fix: record history e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sky-FE committed Jan 9, 2025
1 parent 3d7ce8c commit e18c500
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/nestjs-backend/src/event-emitter/events/event.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ export enum Events {
WORKFLOW_DEACTIVATE = 'workflow.deactivate',

CROP_IMAGE = 'crop.image',

RECORD_HISTORY_CREATE = 'record.history.create',
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Knex } from 'knex';
import { isString } from 'lodash';
import { InjectModel } from 'nest-knexjs';
import { BaseConfig, IBaseConfig } from '../../configs/base.config';
import { EventEmitterService } from '../event-emitter.service';
import { Events, RecordUpdateEvent } from '../events';

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -18,6 +19,7 @@ const SELECT_FIELD_TYPE_SET = new Set([FieldType.SingleSelect, FieldType.Multipl
export class RecordHistoryListener {
constructor(
private readonly prismaService: PrismaService,
private readonly eventEmitterService: EventEmitterService,
@BaseConfig() private readonly baseConfig: IBaseConfig,
@InjectModel('CUSTOM_KNEX') private readonly knex: Knex
) {}
Expand Down Expand Up @@ -130,6 +132,10 @@ export class RecordHistoryListener {

await this.prismaService.$executeRawUnsafe(query);
}

this.eventEmitterService.emit(Events.RECORD_HISTORY_CREATE, {
recordIds: records.map((record) => record.id),
});
}

private minimizeFieldOptions(
Expand Down
4 changes: 2 additions & 2 deletions apps/nestjs-backend/test/record-history.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ describe('Record history (e2e)', () => {
const baseConfigService = app.get(baseConfig.KEY) as IBaseConfig;
baseConfigService.recordHistoryDisabled = false;

awaitWithEvent = createAwaitWithEvent(eventEmitterService, Events.TABLE_RECORD_UPDATE);
awaitWithEvent = createAwaitWithEvent(eventEmitterService, Events.RECORD_HISTORY_CREATE);
});

afterAll(async () => {
eventEmitterService.eventEmitter.removeAllListeners(Events.TABLE_RECORD_UPDATE);
eventEmitterService.eventEmitter.removeAllListeners(Events.RECORD_HISTORY_CREATE);
await app.close();
});

Expand Down

0 comments on commit e18c500

Please sign in to comment.