clean up tests

This commit is contained in:
Ben Irvin 2022-07-26 09:28:06 +02:00
parent a499411086
commit b890696445

View File

@ -18,59 +18,48 @@ describe('Sanitize visitors util', () => {
}; };
test('keeps creator relations with populateCreatorFields true', async () => { test('keeps creator relations with populateCreatorFields true', async () => {
const populateCreatorFields = true;
const creatorKeys = [keyCreatedBy, keyUpdatedBy];
const remove = jest.fn(); const remove = jest.fn();
const set = jest.fn(); const set = jest.fn();
const rrr = visitors.removeRestrictedRelations(auth); const rrr = visitors.removeRestrictedRelations(auth);
await rrr( const promises = creatorKeys.map(async key => {
{ await rrr(
data, {
key: keyCreatedBy, data,
attribute, key,
schema: { options: { populateCreatorFields: true } }, attribute,
}, schema: { options: { populateCreatorFields } },
{ remove, set } },
); { remove, set }
await rrr( );
{ });
data, await Promise.all(promises);
key: keyUpdatedBy,
attribute, expect(remove).toHaveBeenCalledTimes(0);
schema: { options: { populateCreatorFields: true } },
},
{ remove, set }
);
expect(remove).toBeCalledTimes(0);
expect(set).toBeCalledTimes(0); expect(set).toBeCalledTimes(0);
}); });
test('removes creator relations with populateCreatorFields false', async () => { test('removes creator relations with populateCreatorFields false', async () => {
const populateCreatorFields = false;
const creatorKeys = [keyCreatedBy, keyUpdatedBy];
const remove = jest.fn(); const remove = jest.fn();
const set = jest.fn(); const set = jest.fn();
const rrr = visitors.removeRestrictedRelations(auth); const rrr = visitors.removeRestrictedRelations(auth);
await rrr( const promises = creatorKeys.map(async key => {
{ await rrr(
data, {
key: keyCreatedBy, data,
attribute, key,
schema: { options: { populateCreatorFields: false } }, attribute,
}, schema: { options: { populateCreatorFields } },
{ remove, set } },
); { remove, set }
expect(remove).toHaveBeenCalledTimes(1); );
expect(remove).toHaveBeenCalledWith(keyCreatedBy); });
await Promise.all(promises);
remove.mockClear();
await rrr(
{
data,
key: keyUpdatedBy,
attribute,
schema: { options: { populateCreatorFields: false } },
},
{ remove, set }
);
expect(remove).toHaveBeenCalledTimes(1);
expect(remove).toHaveBeenCalledWith(keyUpdatedBy);
expect(remove).toHaveBeenCalledTimes(creatorKeys.length);
creatorKeys.forEach(key => expect(remove).toHaveBeenCalledWith(key));
expect(set).toBeCalledTimes(0); expect(set).toBeCalledTimes(0);
}); });
}); });