Skip to content

Commit

Permalink
Added funcion to test all events from 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
baatochan committed Sep 6, 2017
1 parent c5b468c commit 0048666
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions code.gs
Expand Up @@ -1410,6 +1410,37 @@ function test () {
main(settings.debug.testDate);
}

/*
* Executie the main() function for everyday in 2017. It can exceed maximum amount of mails (100) for one day.
*/
function testWholeYear () {
log.add('testWholeYear() running.', 'info');

//execution of this method very ofted exceed maximum time so you can set here to start from diffrent date than 01.01.2017 to continue
var month = 1;
var day = 1;

var dayNumber;
var testDateString;
for (month; month <= 12; month++) {
if ((month <= 7 && month % 2 === 1) || (month > 7 && month % 2 === 0)) {
dayNumber = 31;
} else {
dayNumber = 30;
}
if (month === 2) dayNumber = 28; //2017.02 has 28 days
for (day; day <= dayNumber; day++) {
testDateString = '2017/';
if (month < 10) testDateString += '0';
testDateString += month + '/';
if (day < 10) testDateString += '0';
testDateString += day + ' 06:00:00';
var testDate = new Date(testDateString);
main(testDate);
}
}
}

// NOTIFICATION SERVICE FUNCTIONS

/*
Expand Down

5 comments on commit 0048666

@GioBonvi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, let me give you some ideas/questions/observations:

  • you could proably tidy up a lot of the code by using something like nextDay = new Date(prevDay.getTime() + 24 * 60 * 60 * 1000); looping this 365 times should let you to walk all the dates in the year much easier;
  • this code probably belongs to the new unit-tests.gs file more than to code.gs: this way we (contributors) can have it and use it to test the script, but the users will not copy it over, clobbing an already over-1000 lines script;
  • this will cause a big amount of emails to be sent and I think that Google Script MailApp.sendMail() has some kind of daily quota: did you ever reach it?
  • do you check all the emails by hand looking for mistakes or did you setup some sort of auto-check?

Nice work!

@baatochan
Copy link
Contributor Author

@baatochan baatochan commented on 0048666 Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Well... It took me a lot of time to prepare this... It would be great if had known that you can just add it this way... Anyway, I'm gonna fix that till the evening.
  2. Yup, but I don't know how to configure unit-tests in GScripts. I should paste under the code or create a new script?
  3. Yup, the limit is 100 and I get to that because I run it twice by accident. At least for me it's enough because I have only like 60 contacts and I'm sending mails only on 0 day.
  4. Check by hand. I checked the number of them (is it exactly the number of days with events) and I was looking if the content doesn't look suspicious (like those nulls that I did). I checked few dates if they are correct as well. And content of few mails as well to check if it correctly downloads data.

Thanks, I didn't have better idea to do tests other than just run it through all dates

@baatochan
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did what you suggested but it handles DST differently. Both of them are in commit b4c6e40 . I'm gonna delete those commit anyway so it doesn't matter that it's in code.gs for now.
My first approach creates something like that

[17-09-06 11:16:46:207 PDT] I: "2017-03-22T05:00:00.000Z"
[17-09-06 11:16:46:208 PDT] I: "2017-03-23T05:00:00.000Z"
[17-09-06 11:16:46:209 PDT] I: "2017-03-24T05:00:00.000Z"
[17-09-06 11:16:46:210 PDT] I: "2017-03-25T05:00:00.000Z"
[17-09-06 11:16:46:211 PDT] I: "2017-03-26T04:00:00.000Z"
[17-09-06 11:16:46:212 PDT] I: "2017-03-27T04:00:00.000Z"
[17-09-06 11:16:46:213 PDT] I: "2017-03-28T04:00:00.000Z"
[17-09-06 11:16:46:214 PDT] I: "2017-03-29T04:00:00.000Z"
[17-09-06 11:16:46:215 PDT] I: "2017-03-30T04:00:00.000Z"
[17-09-06 11:16:46:216 PDT] I: "2017-03-31T04:00:00.000Z"

(that's only few dates)

while mine creates something like that

[17-09-06 11:17:43:472 PDT] I: "2017-03-22T05:00:00.000Z"
[17-09-06 11:17:43:473 PDT] I: "2017-03-23T05:00:00.000Z"
[17-09-06 11:17:43:473 PDT] I: "2017-03-24T05:00:00.000Z"
[17-09-06 11:17:43:475 PDT] I: "2017-03-25T05:00:00.000Z"
[17-09-06 11:17:43:476 PDT] I: "2017-03-26T05:00:00.000Z"
[17-09-06 11:17:43:477 PDT] I: "2017-03-27T05:00:00.000Z"
[17-09-06 11:17:43:478 PDT] I: "2017-03-28T05:00:00.000Z"
[17-09-06 11:17:43:478 PDT] I: "2017-03-29T05:00:00.000Z"
[17-09-06 11:17:43:479 PDT] I: "2017-03-30T05:00:00.000Z"
[17-09-06 11:17:43:480 PDT] I: "2017-03-31T05:00:00.000Z"

I guess it can make a problem with running a test but I can't check that because I've got blocked mails for today (I've sent 100).

@GioBonvi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should paste under the code or create a new script?

You can simply do "File" -> "New" -> "Script File" and create your copy of unit-tests.gs. Then you can open ne or the other and execute the function you want to. The trick is that at execution time all the files are merged together in a unique file, so you can safely call functions from different files (e.g. how new Log() is called in unit-tests.gs).

The best thing we could do would be developing some kind of test that could be automatically validated or, at least, does not involve sending hundreds of emails...
The only thing I can think of right now, off the top of my head, would be splitting the main() function in two like this:

  • createEmail(): collect the data from the contacts and generate the email text
  • sendEmail(): get the generated text and send the email

This way we could test the createEmail() function without actually sending the emails (maybe grouping all the emails into a single one?)

@baatochan
Copy link
Contributor Author

@baatochan baatochan commented on 0048666 Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GioBonvi

  1. Ok, I've got unit-tests.gs working. Thanks

  2. I guess I did something similar to thing that you mention (commit 67d28cd)

  3. Problem with DST is not a problem because everything works OK (even though half of dates in second method of testing all events from a year is with wrong hour)

Please sign in to comment.