Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test/calc
diff options
context:
space:
mode:
authorSarah Chintomby <sarah.chintomby@rtspecialty.com>2019-06-17 10:03:10 -0400
committerSarah Chintomby <sarah.chintomby@rtspecialty.com>2019-06-18 12:14:36 -0400
commit53f3e2317ec6dcb5f6ca6af1236ecc28ee417278 (patch)
tree6be05ec50be3ee3ed9f6e8fb27c532a5e5e6624a /test/calc
parent5ad78461deeaf7a8975c65f535a9d4e634317214 (diff)
downloadliza-53f3e2317ec6dcb5f6ca6af1236ecc28ee417278.tar.gz
liza-53f3e2317ec6dcb5f6ca6af1236ecc28ee417278.tar.bz2
liza-53f3e2317ec6dcb5f6ca6af1236ecc28ee417278.zip
[DEV-5546] Fix calc relativedate for day and also month concerning edge cases
Diffstat (limited to 'test/calc')
-rw-r--r--test/calc/CalcTest.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/calc/CalcTest.js b/test/calc/CalcTest.js
new file mode 100644
index 0000000..c7338d4
--- /dev/null
+++ b/test/calc/CalcTest.js
@@ -0,0 +1,72 @@
+/**
+ * Tests Calc
+ *
+ * Copyright (C) 2017 R-T Specialty, LLC.
+ *
+ * This file is part of liza.
+ *
+ * liza is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+var liza = require( '../..' ),
+ relativeDate = liza.calc.Calc.relativeDate,
+ expect = require( 'chai' ).expect;
+
+
+describe( 'relativeDate', function()
+{
+ //returns a date relative to another date by adding a given value
+
+ it( 'assert 10 days is added, the date\'s month changes', function()
+ {
+ expect( relativeDate( ['2019-11-25'], ['10d'] ) )
+ .to.have.all.members( ['2019-12-05'] );
+ });
+
+ it( 'assert 10 days is added, the date\'s month and year changes', function()
+ {
+ expect( relativeDate( ['2019-12-28'], ['10d'] ) )
+ .to.have.all.members( ['2020-01-07'] );
+ });
+
+ it( 'assert edge case 6 months is added, the date does not go into the 7th month', function()
+ {
+ expect( relativeDate( ['2019-12-31'], ['6m'] ) )
+ .to.have.all.members( ['2020-06-30'] );
+ });
+
+ it( 'assert edge case 3 months is added, the date does not go into the 4th month', function()
+ {
+ expect( relativeDate( ['2019-08-31'], ['3m'] ) )
+ .to.have.all.members( ['2019-11-30'] );
+ });
+
+ it( 'assert 2 years is added', function()
+ {
+ expect( relativeDate( ['2019-12-31'], ['2y'] ) )
+ .to.have.all.members( ['2021-12-31'] );
+ });
+
+ it( 'assert edge case february', function()
+ {
+ expect( relativeDate( ['2018-12-31'], ['2m'] ) )
+ .to.have.all.members( ['2019-02-28'] );
+ });
+
+ it( 'assert ege case february leap year', function()
+ {
+ expect( relativeDate( ['2019-12-31'], ['2m'] ) )
+ .to.have.all.members( ['2020-02-29'] );
+ });
+});