No description
Find a file
aszlig 3e29b958e3 tests/cron: Fix tests that involve mocked time (#10418)
* Revert commenting out some cron subscription tests

This reverts commit 47c488967c.

We're going to properly fix these tests, so let's start by reverting the
commit that temporarily disabled these tests in the first place.

Signed-off-by: aszlig <aszlig@nix.build>

* tests/cron: Fix restoring clock on test failure

Ah, the joys of global state... >:-(

Whenever some test failed which has mocked the time using
useFakeTimers(), other test that are run after that test would fail (or
even time out) as well, which is a bit confusing to debug.

Some of the tests even had a cleanup routine in afterEach() but most of
them didn't, so I rearranged them in a way so that we have a clock
variable for *all* of the subtests, which initially is null and then a
cleanup handler (also for *all* of the subtest) calls clock.restore() if
the value isn't null.

In order to avoid calling clock.restore() twice, I have removed all the
clock.restore() calls at the end of the tests setting the clock to a
specific value.

Signed-off-by: aszlig <aszlig@nix.build>

* tests/cron: Fix test for 3-month gift subscription

So this is the actual culprit of the test failures that emerge during
the first two days of a month:

The test group "for a 3-month gift subscription (non-recurring)" creates
a User object available for every test case, which has a subscription
for 3 months beginning at the current time/date.

During each test case the fake timer is set to the second day of the
month to be tested. For the first and second month it's unproblematic
because the subscription is still active, no matter whether the
dateTerminated is set to the first day or the last day of a month.

However, the third month is problematic here, because whenever the
subscription lasts until the first day of the third month it has already
ended after the second day and thus the test fails because the actual
implementation of cron sets plan.consecutive.count to zero (which is
what it's supposed to do).

In order to fix this, I've set dateTerminated for the User object to the
15th of the current month so the subscription lasts long enough to not
trigger the test failure (and also make time zones irrelevant, because
right now there is no TZ offset which is more than half of a month,
especially not while running the test suite).

Signed-off-by: aszlig <aszlig@nix.build>
2018-06-02 13:05:41 +02:00
.ebextensions Old Client Cleanup (#9141) 2017-10-12 16:44:28 +02:00
.github Update pull request template to mention issue number instead of url 2018-05-13 15:42:44 +02:00
database_reports Clean up references to repo as HabitRPG/habitrpg (#8742) 2017-06-06 18:51:54 -07:00
gulp Payment refactor (#10325) 2018-05-06 15:12:00 -05:00
keys/google change Google iap-live for Android mobile app gem purchases, at negue's request 2015-12-03 06:22:59 +10:00
kubernetes Kubernetes support for dev environments (#8753) 2017-07-01 09:30:08 -07:00
migrations Merge branch 'release' into develop 2018-05-29 22:24:41 +00:00
scripts Node 8 (WIP) (#9946) 2018-03-15 19:59:36 +01:00
test tests/cron: Fix tests that involve mocked time (#10418) 2018-06-02 13:05:41 +02:00
vagrant_scripts Node 8 (WIP) (#9946) 2018-03-15 19:59:36 +01:00
webpack fix svgo options 2018-02-14 12:05:53 +01:00
website Merge branch 'release' into develop 2018-06-01 19:41:40 +00:00
.babelrc Node 8 (WIP) (#9946) 2018-03-15 19:59:36 +01:00
.buildpacks refactor(tasks) improve UI consistency 2014-11-27 10:32:57 +00:00
.codeclimate.yml Only list javascript in .codeclimate.yml 2015-08-02 17:54:05 +02:00
.dockerignore Docker improvements (#8297) 2016-12-28 09:33:24 +01:00
.editorconfig Create .editorconfig 2016-09-07 08:44:57 -05:00
.eslintignore Upgrade tests tools and lint migrations and scripts (part 2) (#9998) 2018-02-17 18:11:24 +01:00
.eslintrc fix: eslint: re-order packages 2016-12-26 16:04:36 +01:00
.gitignore Old Client Cleanup (#9141) 2017-10-12 16:44:28 +02:00
.nodemonignore add website/raw_sprites/** to list of files ignored by nodemon (#10274) 2018-04-26 10:46:49 +02:00
.nvmrc Node 8 (WIP) (#9946) 2018-03-15 19:59:36 +01:00
.travis.yml Node 8 (WIP) (#9946) 2018-03-15 19:59:36 +01:00
apidoc.json chore: Remove versioning from apidoc 2016-05-25 11:11:39 -05:00
config.json.example remove stackimpact 2018-04-30 19:07:46 +02:00
docker-compose.dev.yml Update the docker compose process (#9724) 2018-01-29 14:56:08 -06:00
docker-compose.yml pinning mongodb container to recommended, supported version (#10270) 2018-04-28 17:37:19 +02:00
Dockerfile Docker: yarn is not necessary anymore 2018-03-23 16:20:00 +01:00
Dockerfile-Production chore(i18n): update locales 2018-06-01 19:40:42 +00:00
gulpfile.js Upgrade gulp (and gulp deps) (#9950) 2018-02-04 18:18:10 +01:00
LICENSE Fix grammar mistakes in license file 2016-06-21 06:42:20 -05:00
package-lock.json Merge branch 'release' into develop 2018-06-01 19:41:40 +00:00
package.json Merge branch 'release' into develop 2018-06-01 19:41:40 +00:00
Procfile API v3 [WIP] (#6144) 2016-05-23 13:58:31 +02:00
README.md Changed Member List number in Guilds (#10268) 2018-04-28 17:43:59 +02:00
VAGRANT.md HabitRPG -> Habitica text changes 2015-07-31 18:05:10 +10:00
Vagrantfile.example Update Vagrantfile.example to forward port 8080 (#9732) 2018-01-12 16:32:09 -06:00

Habitica Build Status Code Climate Coverage Status Bountysource Open Source Helpers

Greenkeeper badge

Habitica is an open source habit building program which treats your life like a Role Playing Game. Level up as you succeed, lose HP as you fail, earn money to buy weapons and armor.

We need more programmers! Your assistance will be greatly appreciated.

For an introduction to the technologies used and how the software is organized, refer to Guidance for Blacksmiths.

To set up a local install of Habitica for development and testing on various platforms, see Setting up Habitica Locally.