All files / src/functions/query changed.fields.ts

100% Statements 14/14
100% Branches 14/14
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21    8x   36x   8x 40x 40x   34x 34x 7x   34x 29x   34x   8x  
'use strict';
 
import {each, isEmpty} from 'lodash';
 
const _rootOf = (path: string): string => path.split('.')[0];
 
const changedFields = (change: any): string[] => {
	const description: any = change?.updateDescription;
	if (isEmpty(description)) return [];
 
	const fields: Set<string> = new Set<string>();
	each(description.removedFields ?? [], (field: string): void => {
		fields.add(_rootOf(field));
	});
	each(Object.keys(description.updatedFields ?? {}), (field: string): void => {
		fields.add(_rootOf(field));
	});
	return [...fields];
};
export default changedFields;