BoxLang: Our new JVM Dynamic Language made by Ortus! Check it out: https://www.boxlang.io

Allow toHaveKey to support struct like objects

Description

I’ve been updating Lucee to use the latest testbox, I found a problem introduced with

https://ortussolutions.atlassian.net/browse/TESTBOX-370

This test fails due to the isStruct test introduced, the MongoDBID isn’t a struct but is struct like

https://github.com/lucee/Lucee/blob/6.2/test/datasource/MongoDB.cfc#L119

https://github.com/lucee/extension-mongodb/blob/master/source/java/src/org/lucee/mongodb/MongoDBId.java

https://github.com/lucee/extension-mongodb/blob/master/source/java/src/org/lucee/mongodb/ObjectIdImpl.java

for now I’m just appending the mongoDBID to a new struct, but I like to propose simply changing the normalizeToStruct to only do the query transformation, otherwise, just returning the object and allowing the structFindKey to throw a more informative exception, if the target isn’t supported?

private function normalizeToStruct( any target ){ if ( isStruct( arguments.target ) ) { return arguments.target; } if ( isQuery( arguments.target ) ) { return getMetadata( arguments.target ).reduce( ( results, item ) => { results[ item.name ] = {}; return results; }, {} ); } throw( "InvalidTargetType", "The target is not a struct or query" ); }

https://github.com/Ortus-Solutions/TestBox/blob/development/system/Assertion.cfc#L1456

to

private function normalizeToStruct( any target ){ if ( isQuery( arguments.target ) ) { return getMetadata( arguments.target ).reduce( ( results, item ) => { results[ item.name ] = {}; return results; }, {} ); } return arguments.target; }

Activity

Show:

Zac Spitzer December 10, 2024 at 3:37 PM

https://github.com/Ortus-Solutions/TestBox/pull/159

current workaround was just to append the object to another struct

https://luceeserver.atlassian.net/browse/LDEV-5188

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Fix versions

Priority

Sentry

Created December 10, 2024 at 3:22 PM
Updated December 16, 2024 at 9:30 AM
Resolved December 16, 2024 at 9:30 AM

Flag notifications