Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PaginatedFilter,
Projection,
RecordData,
RecordValidator,
Sort,
} from '@forestadmin/datasource-toolkit';

Expand Down Expand Up @@ -132,6 +133,8 @@ export default class RelaxedCollection<
update(filter: TFilter<S, N>, patch: TPartialSimpleRow<S, N>): Promise<void> {
const filterInstance = this.buildFilter(filter);

RecordValidator.validate(this.collection, patch);

return this.collection.update(this.caller, filterInstance, patch);
}

Expand Down
16 changes: 15 additions & 1 deletion packages/datasource-customizer/test/context/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ describe('RelaxedWrappers', () => {

beforeEach(() => {
caller = factories.caller.build();
collection = factories.collection.build();
collection = factories.collection.build({
schema: {
fields: {
name: factories.columnSchema.build({ columnType: 'String' }),
},
},
});
relaxed = new RelatedCollection(collection, caller);
});

Expand Down Expand Up @@ -154,6 +160,14 @@ describe('RelaxedWrappers', () => {
);
});

test('should validate patch operation before forwarding update', async () => {
await expect(() =>
relaxed.update({ segment: 'some_segment' }, { nonexistingField: 'newValue' }),
).toThrow('Unknown field "nonexistingField"');

expect(collection.update).not.toHaveBeenCalled();
});

test('should forward delete and transform filter', async () => {
await relaxed.delete({ segment: 'some_segment' });

Expand Down