From acb5ff15a48d2e8f45943161503a3122e70f9841 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Fri, 29 Sep 2023 15:56:29 +0200 Subject: [PATCH] LDEV-2298 improve tests --- test/tickets/LDEV2298.cfc | 104 +++++++++++++++++++++++++++++---- test/tickets/LDEV2298/test.cfm | 61 ++++++++++++------- 2 files changed, 134 insertions(+), 31 deletions(-) diff --git a/test/tickets/LDEV2298.cfc b/test/tickets/LDEV2298.cfc index 63f429cc65..97dec4a1f4 100644 --- a/test/tickets/LDEV2298.cfc +++ b/test/tickets/LDEV2298.cfc @@ -5,39 +5,123 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" { } function run( testResults, testBox ) { - describe( "Test case for LDEV2298", function(){ + describe( "Test case for LDEV2298, inserting date with null=false, no sqltype", function(){ - it( title="queryExecute() param with Struct & column accept null value it returns default date", body = function( currentSpec ) { + xit( title="queryExecute() column doesn't allow nulls", body = function( currentSpec ) { local.result = _InternalRequest( template : "#uri#\test.cfm", forms : {Scene = 1,tablename = 'ldev2298_null'} ); - expect(result.filecontent).toBe("{ts '1900-01-01 00:00:00'}"); + expect( result.filecontent ).toInclude("can't cast [] to date value"); // feels wrong, returns {ts '1900-01-01 00:00:00'} aka cfml epoch }); - it( title="queryExecute() param with Array of Struct & column doesn't accept null value", body = function( currentSpec ) { + xit( title="queryExecute() column allows nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 3,tablename = 'ldev2298_notnull'} + ); + expect( result.filecontent ).toInclude("can't cast [] to date value"); // feels wrong, returns {ts '1900-01-01 00:00:00'} aka cfml epoch + }); + }); + + describe( "Test case for LDEV2298, inserting date with null=false, no sqltype, missing date param", function(){ + + it( title="queryExecute() column doesn't allow nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 1,tablename = 'ldev2298_null', passDateParam=false} + ); + expect( result.filecontent ).toInclude("param [utcNow] not found"); + }); + + it( title="queryExecute() column allows nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 3,tablename = 'ldev2298_notnull', passDateParam=false} + ); + expect( result.filecontent ).toInclude("param [utcNow] not found"); + }); + }); + + describe( "Test case for LDEV2298, inserting date with null=false, with sqltype, via array of structs", function(){ + + it( title="queryExecute() column allows nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 4,tablename = 'ldev2298_null'} + ); + expect( result.filecontent ).toInclude("can't cast [] to date value"); + }); + + it( title="queryExecute() column doesn't allow nulls", body = function( currentSpec ) { local.result = _InternalRequest( template : "#uri#\test.cfm", forms : {Scene = 2,tablename = 'ldev2298_notnull'} ); - expect(result.filecontent).toBe("Error"); + expect( result.filecontent ).toInclude("can't cast [] to date value"); }); - xit( title="queryExecute() param with Struct & column doesn't accept null value", body = function( currentSpec ) { + }); + + describe( "Test case for LDEV2298, inserting date with null=false, with sqltype, via array of structs, missing date param", function(){ + + it( title="queryExecute() column allows nulls", body = function( currentSpec ) { local.result = _InternalRequest( template : "#uri#\test.cfm", - forms : {Scene = 3,tablename = 'ldev2298_notnull'} + forms : {Scene = 4,tablename = 'ldev2298_null', passDateParam=false} + ); + expect( result.filecontent ).toInclude("param [utcNow] not found"); + }); + + it( title="queryExecute() column doesn't allow nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 2,tablename = 'ldev2298_notnull', passDateParam=false} ); - expect(result.filecontent).tobe("Error"); + expect( result.filecontent ).toInclude("param [utcNow] not found"); }); - xit( title="queryExecute() param with Array of Struct & column accept null value it returns default date", body = function( currentSpec ) { + }); + + describe( "Test case for LDEV2298, inserting date with null=false, with sqltype", function(){ + + + it( title="queryExecute() column allows nulls", body = function( currentSpec ) { local.result = _InternalRequest( template : "#uri#\test.cfm", forms : {Scene = 4,tablename = 'ldev2298_null'} ); - expect(result.filecontent).toBe("{ts '1900-01-01 00:00:00'}"); + expect( result.filecontent ).toInclude("can't cast [] to date value"); + }); + + it( title="queryExecute() column doesn't allow nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 2,tablename = 'ldev2298_notnull',} + ); + expect( result.filecontent ).toInclude("can't cast [] to date value"); + }); + + }); + + describe( "Test case for LDEV2298, inserting date with null=true, with sqltype", function(){ + + it( title="queryExecute() column allows nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 4,tablename = 'ldev2298_null', allowNull=true} + ); + expect( trim( result.filecontent ) ).toBe(""); }); + + it( title="queryExecute() column doesn't allow nulls", body = function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\test.cfm", + forms : {Scene = 2,tablename = 'ldev2298_notnull',allowNull=true} + ); // Cannot insert the value NULL into column + expect( result.filecontent ).toInclude("lucee.runtime.exp.DatabaseException"); + }); + }); } diff --git a/test/tickets/LDEV2298/test.cfm b/test/tickets/LDEV2298/test.cfm index 3ae5341c30..d1cc42d8f6 100644 --- a/test/tickets/LDEV2298/test.cfm +++ b/test/tickets/LDEV2298/test.cfm @@ -1,23 +1,38 @@ param name="FORM.Scene" default=""; param name="FORM.tableName" default=""; + param name="FORM.allowNull" default="false"; + param name="FORM.passDateParam" default="true"; + + if (form.tableName neq "ldev2298_notnull" + and form.tableName neq "ldev2298_null") + throw "invalid tableName"; if( FORM.scene == 1 OR FORM.scene == 3){ try{ dsn = "ldev2298_DSN"; - queryExecute(" - UPDATE #form.tableName# - SET emp_join_date = :utcNow - WHERE id = :emp_id",{emp_id = 1,utcnow = '',cfsqltype = "cf_sql_timestamp"},{datasource = "ldev2298_DSN"} + + params = {emp_id = 1}; + if (form.passDateParam) + params.utcnow = ''; + + update_result = queryExecute(" + UPDATE #form.tableName# + SET emp_join_date = :utcNow + WHERE id = :emp_id", + params, + {datasource = dsn} ); result = queryExecute(" - SELECT * - FROM #form.tableName# - WHERE id = :emp_id",{emp_id = 1},{datasource = "ldev2298_DSN"} + SELECT * + FROM #form.tableName# + WHERE id = :emp_id", + {emp_id = 1}, + {datasource = dsn} ); writeoutput(result.emp_join_date); }catch(any e){ - writeoutput("Error"); + writeoutput(e.stacktrace); } } if( FORM.scene == 2 OR FORM.scene == 4){ @@ -25,26 +40,30 @@ dsn = "ldev2298_DSN"; id = 1; utcNow = ""; - queryExecute(sql = " - UPDATE #form.tableName# - SET emp_join_date = :utcNow - WHERE id = :id_num + + params = [ + {name="id_num", value=id, cfsqltype="cf_sql_integer"} + ]; + if (form.passDateParam) + arrayAppend(params, {name="utcNow", value=utcNow, cfsqltype="cf_sql_timestamp", null=form.allowNull}); + + update_result = queryExecute(sql = " + UPDATE #form.tableName# + SET emp_join_date = :utcNow + WHERE id = :id_num ", - params=[ - {name = "id_num", value = id, cfsqltype = "cf_sql_integer"}, - {name = "utcNow", value = utcNow, cfsqltype = "cf_sql_timestamp"} - ], + params=params, options={ datasource: dsn } ); result = queryExecute(sql = " SELECT * - FROM #form.tableName# - WHERE id = :id_num + FROM #form.tableName# + WHERE id = :id_num ", params = [ - {name = "id_num", value = id, cfsqltype = "cf_sql_integer"} + {name="id_num", value=id, cfsqltype="cf_sql_integer"} ], options={ datasource: dsn @@ -52,7 +71,7 @@ ); writeoutput(result.emp_join_date); }catch (any e){ - writeoutput("Error"); + writeoutput(e.stacktrace); } } - \ No newline at end of file +