fix(backend): Nog een linting-probleem opgelost
This commit is contained in:
		
							parent
							
								
									ba912c3ef0
								
							
						
					
					
						commit
						1382e2300b
					
				
					 1 changed files with 29 additions and 27 deletions
				
			
		|  | @ -19,38 +19,40 @@ export function expectToBeCorrectEntity<T extends object>( | ||||||
|     propertyPrefix = "" |     propertyPrefix = "" | ||||||
| ): void { | ): void { | ||||||
|     for (const property in expected) { |     for (const property in expected) { | ||||||
|         const prefixedProperty = propertyPrefix + property; |         if (Object.prototype.hasOwnProperty.call(expected, property)) { | ||||||
|         if ( |             const prefixedProperty = propertyPrefix + property; | ||||||
|             property in IGNORE_PROPERTIES && |             if ( | ||||||
|             expected[property] !== undefined && // If we don't expect a certain value for a property, we assume it can be filled in by the database however it wants.
 |                 property in IGNORE_PROPERTIES && | ||||||
|             typeof expected[property] !== 'function' // Functions obviously are not persisted via the database
 |                 expected[property] !== undefined && // If we don't expect a certain value for a property, we assume it can be filled in by the database however it wants.
 | ||||||
|         ) { |                 typeof expected[property] !== 'function' // Functions obviously are not persisted via the database
 | ||||||
|             if (!Object.prototype.hasOwnProperty.call(actual, property)) { |             ) { | ||||||
|                 throw new AssertionError({ |                 if (!Object.prototype.hasOwnProperty.call(actual, property)) { | ||||||
|                     message: `Expected property ${prefixedProperty}, but it is missing.`, |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|             if (typeof expected[property] === 'boolean') { |  | ||||||
|                 // Sometimes, booleans get represented by numbers 0 and 1 in the objects actual from the database.
 |  | ||||||
|                 if (Boolean(expected[property]) !== Boolean(actual[property])) { |  | ||||||
|                     throw new AssertionError({ |                     throw new AssertionError({ | ||||||
|                         message: `Expected ${prefixedProperty} to be ${expected[property]},
 |                         message: `Expected property ${prefixedProperty}, but it is missing.`, | ||||||
|                         but was ${actual[property]} (${Boolean(expected[property])}).`,
 |  | ||||||
|                     }); |                     }); | ||||||
|                 } |                 } | ||||||
|             } else if (typeof expected[property] !== typeof actual[property]) { |                 if (typeof expected[property] === 'boolean') { | ||||||
|                 throw new AssertionError({ |                     // Sometimes, booleans get represented by numbers 0 and 1 in the objects actual from the database.
 | ||||||
|                     message: `${prefixedProperty} was expected to have type ${typeof expected[property]},` |                     if (Boolean(expected[property]) !== Boolean(actual[property])) { | ||||||
|                                 + `but had type ${typeof actual[property]}.`, |                         throw new AssertionError({ | ||||||
|                 }); |                             message: `Expected ${prefixedProperty} to be ${expected[property]},
 | ||||||
|             } else if (typeof expected[property] === 'object') { |                         but was ${actual[property]} (${Boolean(expected[property])}).`,
 | ||||||
|                 expectToBeCorrectEntity(actual[property] as object, expected[property] as object, property); |                         }); | ||||||
|             } else { |                     } | ||||||
|                 if (expected[property] !== actual[property]) { |                 } else if (typeof expected[property] !== typeof actual[property]) { | ||||||
|                     throw new AssertionError({ |                     throw new AssertionError({ | ||||||
|                         message: `${prefixedProperty} was expected to be ${expected[property]}, ` |                         message: `${prefixedProperty} was expected to have type ${typeof expected[property]},` | ||||||
|                                     + `but was ${actual[property]}.`, |                             + `but had type ${typeof actual[property]}.`, | ||||||
|                     }); |                     }); | ||||||
|  |                 } else if (typeof expected[property] === 'object') { | ||||||
|  |                     expectToBeCorrectEntity(actual[property] as object, expected[property] as object, property); | ||||||
|  |                 } else { | ||||||
|  |                     if (expected[property] !== actual[property]) { | ||||||
|  |                         throw new AssertionError({ | ||||||
|  |                             message: `${prefixedProperty} was expected to be ${expected[property]}, ` | ||||||
|  |                                 + `but was ${actual[property]}.`, | ||||||
|  |                         }); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger