I have a Google Apps Script web app, that previously worked, but when I tried to add some code to the "server-side", it broke the app. I wish to go back in and do some unit testing and possibly a bit of regression testing (even though my manual regression testing just failed), on the different functions and modules of this app.
I stumbled upon this library for GAS unit testing and a tutorial for using the library. Problem is that, to actually see the results of the test, you must implement a function doGet(e)
for testing.
This app I'm trying to unit-test, being a web app, already has that function. Its implementation is as follows:
function doGet(e) {
return HtmlService.createTemplateFromFile(
'potholeMap'
).evaluate()
.setTitle('Pothole Map')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
When I bring in the QUnit library dependency, and refactor it to allow QUnit testing, such as below:
function doGet(e) {
var TESTING = true;
if (TESTING)
{
QUnit.urlParams(e.parameter);
QUnit.load(function test() {});
return QUnit.getHtml();
}
return HtmlService.createTemplateFromFile(
'potholeMap'
).evaluate()
.setTitle('Pothole Map')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
I get this error when I try to run it: Authorization is required to perform that action.
How do I fix this so that I can do unit testing in the project, as well as run it as web app?
I didn't know that, when I add library, I have to re-authorize the code. That is done via running a function, clicking the button with text like "Authorize", and following the popup prompt to authorize the app. (If only I knew how to verify this app, but that is another question...)