mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 04:27:09 +03:00
bargaining with postgres CI
- fix tests with lockCategories - new unique naming scheme for video - super janky somehow working method for comparing arrays out of order
This commit is contained in:
@@ -21,4 +21,35 @@ export const partialDeepEquals = (actual: Record<string, any>, expected: Record<
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
export const arrayDeepEquals = (actual: Record<string, any>, expected: Record<string, any>, print = true): boolean => {
|
||||
if (actual.length !== expected.length) return false;
|
||||
let flag = true;
|
||||
const actualString = JSON.stringify(actual);
|
||||
const expectedString = JSON.stringify(expected);
|
||||
// check every value in arr1 for match in arr2
|
||||
actual.every((value: any) => { if (flag && !expectedString.includes(JSON.stringify(value))) flag = false; });
|
||||
// check arr2 for match in arr1
|
||||
expected.every((value: any) => { if (flag && !actualString.includes(JSON.stringify(value))) flag = false; });
|
||||
|
||||
if (!flag && print) printActualExpected(actual, expected);
|
||||
return flag;
|
||||
};
|
||||
|
||||
export const mixedDeepEquals = (actual: Record<string, any>, expected: Record<string, any>, print = true): boolean => {
|
||||
for (const [ key, value ] of Object.entries(expected)) {
|
||||
// if value is object or array, recurse
|
||||
if (Array.isArray(value)) {
|
||||
if (!arrayDeepEquals(actual?.[key], value, false)) {
|
||||
if (print) printActualExpected(actual, expected);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (actual?.[key] !== value) {
|
||||
if (print) printActualExpected(actual, expected);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user