Monday 12 June 2017

Logic to unit test a function

I have a function that I must unit test:

      saveDataToGoogleSpreadSheet(conversationData){
    return new Promise((resolve, reject) => {
      Spreadsheet.load(this.getGoogleAPISettings(), (err, spreadsheet) => {
        if (err) {
          return reject(err);
        }

        return spreadsheet.receive((receivedError, rows, info) => {
          if (receivedError) {
            return reject(receivedError);
          }
          const rowData = this.getSpreadsheetRowData(conversationData, info.totalRows);
          spreadsheet.add(rowData);
          return spreadsheet.send(sendError => (sendError ? reject(sendError) : resolve()));
        });
      });
    });
  }

I tested the case one and case two of the function (the two first errors) but I couldn't do it for the last one, the case of success where we an add a row to a spreadsheet.

I need some help with the structure of the test, or a hint on how could my test be.



via laurent miller

No comments:

Post a Comment