I was message over the weekend for a similar quest...
# box-products
I was message over the weekend for a similar question(same problem technically) and was hoping for some more help. I was this time informed of MockBox/mocking in general. I have a function that should rename a column, it seems to be working with the mockbox query sim function but I do not know how to access the specific info from the query. I want to be able to look at the column names and see if it worked. I am looking at these docs, but there is not really as much info as I need, on to do more than just return it: https://testbox.ortusbooks.com/mocking/mockbox/mocking-methods/usdquerysim-method I am testing it with exactly that code:
Copy code
mockQuery = mockBox.querySim("id,fname,lname
        1 | luis | majano
        2 | joe | louis
        3 | bob | lainez");
And using my companies code to change the column "fname" to "firstname", but I am unsure how to check the new column name. I am just an intern so all of this is very new to me so please let me know if there is more/better info I can provide πŸ™‚
Im unsure if your trying to rename a column in a Query of Queries (an in memory query) or just alias a column on the database
fname as firstname
from a DB Query. Can you expand on the goal of your test?
Ah right, the function I am testing should actually be changing the name of the column in the actual database, not just aliasing(we use postgres)
so you are doing an
Suprisingly no. I didn't write the function myself though, just testing it. It gets the index of the passed in column name and if found sets the column using the index - from what I am understanding of the function
given the requirements i don’t see a better way to test the scenario than to actually query the table before and after the change (
select * from table
) . then you can use a
on the result to compare the column names to verify the change happened.
given that the querySim does not interact with the actual database you use for your project, it could respond differently to query logic making the test invalid
I wish I could do that, that's related to a problem I was having before. For some reason TestBox does not recognize our database. It is recognized anywhere else in the code. I tried to use a
very similar to what is used in some other scripts we have. I get the error:
Error: datasource [name] does not exist
that is most likely because there is an
in the testbox directory that is being referenced instead of the one in the root of your project.
βœ… 1
Ahh yes I do see that in there. All that is in there is
this.name this.sessionmanagement and this.mapings
. Does not seem to be doing a whole lot then
it may be as simple as adding the
this.defaultDatasource = "your datasource name here";
to the applicaiton.cfc
assuming that your calling
without specifically setting the datasource in the options
Copy code
qryResult = queryExecute("SELECT * FROM Employees", {}, {datasource="myDataSourceName"});
Yeah , I will give that a shot thanks!
I did try that as well and if I remember correctly(it was a few days ago) it gave the same error
the only other reason for that error that i can think of is that you are defining your datasource on the fly by adding the configuration to your
rather than via the server settings or cfconfig. In which case you would need to copy that over into your testbox application.cfc
Ahh yeah I am not sure tbh. But after adding your suggestion to the testbox Application.cfc I am not getting the same error anymore. Actually i am not getting any outputted errors but the test is passing even when it shouldn't now lol. Will need to look into what is going on now, not sure if related or not. Thanks πŸ˜ƒ
Apparently I am still getting the error πŸ™ƒ have tried setting it both in the Application.cfc and in the options of the
and still get told the datasource doesn't exist. In our main Application.cfc we set the default datasource the same way I was trying here:
this.defaultDatasource = "datasource name";
Are your tests either within the same subdir tree as the app's Application.cfc (ie: it's in a direct ancestor dir of the tests), or does your test Application.cfc extend it?
One of those two things need to be true.
That's a good question πŸ€” It is not in the same directory I believe. I'm offline for the day however so I will make sure that is the case tomorrow, cause I also forget for sure how our application.cfc is set up, I think it gets some of the info from a docker config but that might be the cfconfig file (I can't recall it all from memory πŸ˜‚)