Skip to content

Commit

Permalink
fix: record update events were not merged (#1238)
Browse files Browse the repository at this point in the history
* fix: record update events were not merged

* chore: update record history e2e testing
  • Loading branch information
Sky-FE authored Jan 13, 2025
1 parent f556e64 commit 35fa845
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ export class EventEmitterService {
return;
}

if (existingEvent.rawOpType === RawOpType.Create && event.name === Events.TABLE_RECORD_UPDATE) {
if (
[RawOpType.Create, RawOpType.Edit].includes(existingEvent.rawOpType) &&
event.name === Events.TABLE_RECORD_UPDATE
) {
const fields = this.getUpdateFieldsFromEvent(event as RecordUpdateEvent);
event = this.combineUpdateEvents(existingEvent as RecordCreateEvent, fields);
}
Expand Down
43 changes: 32 additions & 11 deletions apps/nestjs-backend/test/record-history.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { INestApplication } from '@nestjs/common';
import { FieldKeyType, FieldType, Relationship } from '@teable/core';
import { getRecordHistory, getRecordListHistory, recordHistoryVoSchema } from '@teable/openapi';
import type { IRecordHistoryVo, ITableFullVo } from '@teable/openapi';
import type { ITableFullVo } from '@teable/openapi';
import type { IBaseConfig } from '../src/configs/base.config';
import { baseConfig } from '../src/configs/base.config';
import { EventEmitterService } from '../src/event-emitter/event-emitter.service';
Expand Down Expand Up @@ -75,20 +75,41 @@ describe('Record history (e2e)', () => {
})
);

const { recordHistory, tableRecordHistory } = await new Promise<{
recordHistory: IRecordHistoryVo;
tableRecordHistory: IRecordHistoryVo;
}>((resolve) => {
setTimeout(async () => {
const { data: recordHistory } = await getRecordHistory(mainTable.id, recordId, {});
const { data: tableRecordHistory } = await getRecordListHistory(mainTable.id, {});
resolve({ recordHistory, tableRecordHistory });
}, 2000);
});
const { data: recordHistory } = await getRecordHistory(mainTable.id, recordId, {});
const { data: tableRecordHistory } = await getRecordListHistory(mainTable.id, {});

expect(recordHistory.historyList.length).toEqual(1);
expect(tableRecordHistory.historyList.length).toEqual(1);
});

it('should get record history of changes in the modified cell values is referenced by a formula', async () => {
const recordId = mainTable.records[0].id;
const textField = await createField(mainTable.id, {
type: FieldType.SingleLineText,
});
await createField(mainTable.id, {
type: FieldType.Formula,
options: {
expression: `{${textField.id}}`,
},
});

await awaitWithEvent(() =>
updateRecord(mainTable.id, recordId, {
record: {
fields: {
[textField.id]: 'test',
},
},
fieldKeyType: FieldKeyType.Id,
})
);

const { data: mainTableRecordHistory } = await getRecordHistory(mainTable.id, recordId, {});

expect(mainTableRecordHistory.historyList.length).toEqual(1);
});

it('should get record history of changes in the link field cell values', async () => {
const recordId = mainTable.records[0].id;
const foreignRecordId = foreignTable.records[0].id;
Expand Down

0 comments on commit 35fa845

Please sign in to comment.