Skip to content

Commit

Permalink
LDEV-2298 improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Sep 29, 2023
1 parent bd976a2 commit acb5ff1
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 31 deletions.
104 changes: 94 additions & 10 deletions test/tickets/LDEV2298.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

});
}

Expand Down
61 changes: 40 additions & 21 deletions test/tickets/LDEV2298/test.cfm
Original file line number Diff line number Diff line change
@@ -1,58 +1,77 @@
<cfscript>
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){
try{
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
}
);
writeoutput(result.emp_join_date);
}catch (any e){
writeoutput("Error");
writeoutput(e.stacktrace);
}
}
</cfscript>
</cfscript>

0 comments on commit acb5ff1

Please sign in to comment.