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);
const promises = creatorKeys.map(async key => {
await rrr( await rrr(
{ {
data, data,
key: keyCreatedBy, key,
attribute, attribute,
schema: { options: { populateCreatorFields: true } }, schema: { options: { populateCreatorFields } },
}, },
{ remove, set } { remove, set }
); );
await rrr( });
{ await Promise.all(promises);
data,
key: keyUpdatedBy, expect(remove).toHaveBeenCalledTimes(0);
attribute,
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);
const promises = creatorKeys.map(async key => {
await rrr( await rrr(
{ {
data, data,
key: keyCreatedBy, key,
attribute, attribute,
schema: { options: { populateCreatorFields: false } }, 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);
}); });
}); });