Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-moncel committed Nov 27, 2024
1 parent 2364d13 commit 6df5d2a
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,32 @@ describe('RenameFieldCollectionDecorator', () => {
expect(personFields.myBookPerson).toMatchObject({ originKey: 'authorId' });
});
});

describe('when renaming primary keys', () => {
beforeEach(() => {
// Cache the schemas to ensure they refresh property
void newBooks.schema;
void newBookPersons.schema;
void newPersons.schema;

// Rename stuff
newBooks.renameField('id', 'newBookId');
newPersons.renameField('id', 'newPersonId');
});

test('the relations should be updated in all collections', () => {
const bookFields = newBooks.schema.fields;
const bookPersonFields = newBookPersons.schema.fields;
const personFields = newPersons.schema.fields;

expect(bookFields.myPersons).toMatchObject({
foreignKeyTarget: 'newPersonId',
originKeyTarget: 'newBookId',
});
expect(bookFields.myBookPersons).toMatchObject({ originKeyTarget: 'newBookId' });
expect(bookPersonFields.myBook).toMatchObject({ foreignKeyTarget: 'newBookId' });
expect(bookPersonFields.myPerson).toMatchObject({ foreignKeyTarget: 'newPersonId' });
expect(personFields.myBookPerson).toMatchObject({ originKeyTarget: 'newPersonId' });
});
});
});

0 comments on commit 6df5d2a

Please sign in to comment.