0

I am working on a little personal project in order to familiarize myself with Google Apps Script. I want to be able to write unit tests for my project. So far I have been using the QUnit GS2 library which has been perfect for straightforward functions and assertions.

However, in the following function, I want to mock the makeCopy() function and assert on the arguments passed to it. I would like to stay within the Google Apps Scripts editor. I stumbled upon this Stack Overflow answer, but it's not quite what I need.

// Example formResponseObject argument
var formResponseObject = {
        "timestamp":"6/6/2023 16:39:42",
        "name":"test-name",
        "topic":"test-topic",
        "title":"test-title",
        "tag_line":"test-tag-line",
        "email":"test-email@example.com"
        }

function createNewSlideDeck(formResponseObject) {
  // Create a new slide deck by copying the template slide deck

  console.log("Creating a new slide deck by copying the template slide deck with form response with key 'name': " + formResponseObject['name'])
  
  // Get the template file
  // SLIDES_TEMPLATE_FILE_ID declared elsewhere
  var file = DriveApp.getFileById(SLIDES_TEMPLATE_FILE_ID);

  // Get the folder we want to save our new slide deck in and create a copy of the template there
  // LIGHTNING_TALKS_SLIDES_FOLDER_ID declared elsewhere
  var folder = DriveApp.getFolderById(LIGHTNING_TALKS_SLIDES_FOLDER_ID);
  var filename = formResponseObject['name'] + '-lightning-talk'
  var newSlideDeck = file.makeCopy(filename, folder);

  console.log("New slide deck created with filename: " + filename);

  return newSlideDeck
}

Thank you for reading and I appreciate any insights you may be able to provide.

liz-a
  • 1
  • 1

0 Answers0