forked from nextauthjs/next-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
36 lines (33 loc) · 1.22 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
exports.compareSchemas = (expected, actual) => {
const errors = []
// Check all models and properties that are expected exist
for (const objectName in expected) {
if (actual[objectName]) {
for (const propertyName in expected[objectName]) {
if (actual[objectName][propertyName]) {
if (JSON.stringify(expected[objectName][propertyName]) !== JSON.stringify(actual[objectName][propertyName])) {
errors.push(`${objectName}.${propertyName} does not match expected result`)
}
} else {
errors.push(`${objectName}.${propertyName} not found (should exist)`)
}
}
} else {
errors.push(`${objectName} not found (should exist)`)
}
}
// Check for models and properties that exist but are not expected
for (const objectName in actual) {
if (expected[objectName]) {
for (const propertyName in actual[objectName]) {
if (!expected[objectName][propertyName]) {
errors.push(`${objectName}.${propertyName} found (not expected)`)
}
}
} else {
errors.push(`${objectName} found (not expected)`)
}
}
// Return true if no errors, else return array of errors
return errors.length > 0 ? errors : true
}