Skip to content

Commit ad729cd

Browse files
committed
Added test case that validates that an existing id is not overwritten.
1 parent 2bdd46f commit ad729cd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/schema.service.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,39 @@ test('containment properties add when array not defined and generate ID', t => {
566566
t.true(data.foo[0]._id !== undefined);
567567
});
568568

569+
test('containment properties add when array not defined and do not overwrite existing ID', t => {
570+
const schema = {
571+
type: 'object',
572+
properties: {
573+
foo: {
574+
type: 'array',
575+
items: {
576+
type: 'object',
577+
properties: {
578+
_id: { type: 'string' },
579+
bar: { type: 'string' }
580+
}
581+
}
582+
}
583+
}
584+
};
585+
586+
JsonForms.config.setIdentifyingProp('_id');
587+
const service: SchemaService = new SchemaServiceImpl(schema);
588+
589+
const property = service.getContainmentProperties(schema)[0];
590+
const data = {
591+
foo: undefined
592+
};
593+
const valueToAdd = { bar: `Hey Mum, look, it's an idea`, _id: 'TEST-ID' };
594+
property.addToData(data)(valueToAdd);
595+
596+
t.true(data.foo !== undefined);
597+
t.is(data.foo.length, 1);
598+
t.is(data.foo[0].bar, `Hey Mum, look, it's an idea`);
599+
t.is(data.foo[0]._id, 'TEST-ID');
600+
});
601+
569602
test('containment properties add when array defined', t => {
570603
const schema = t.context.fooBarArraySchema;
571604
const service: SchemaService = new SchemaServiceImpl(schema);

0 commit comments

Comments
 (0)