test('applyPgInterval.mutate', async () => { expect.assertions(11) const a = mutate('2018-01-01', postgresInterval('1 mon 15 days'), 'add') expect(a instanceof moment).toBeTruthy() expect(a.unix()).toBe(moment('2018-02-16').unix()) const b = mutate('2018-01-01', postgresInterval('1 mon 15 days'), 'subtract') expect(b instanceof moment).toBeTruthy() expect(b.unix()).toBe(moment('2017-11-16').unix()) expect(() => mutate('2018-01-01')).toThrowError(/mutation missing/) expect(() => mutate('2018-01-01', null, 'foobar')).toThrowError(/not supported/) expect(() => mutate('2018-01-01', null, 'add')).toThrowError(/interval missing/) expect(() => mutate('2018-01-01', 'not-an-interval', 'add')).toThrowError(/not an object/) expect(() => mutate('2018-01-01', {}, 'add')).toThrowError(/has no keys/) expect(() => mutate('2018-01-01', { foo: 'bar' }, 'add')).toThrowError(/contains invalid keys/) expect(() => mutate('2018-01-01', { months: 10, foo: 'bar' }, 'add')).toThrowError(/contains invalid keys/) })
test('applyPgInterval.add', async () => { expect.assertions(19) const a = add('2018-01-01', postgresInterval('1 mon')) expect(a instanceof moment).toBeTruthy() expect(a.unix()).toBe(moment('2018-02-01').unix()) const b = add('2018-01-01', postgresInterval('1 mon 15 days')) expect(b instanceof moment).toBeTruthy() expect(b.unix()).toBe(moment('2018-02-16').unix()) const c = add('2018-01-01', postgresInterval('1 mon 15 days 12:00:00')) expect(c instanceof moment).toBeTruthy() expect(c.unix()).toBe(moment('2018-02-16 12:00').unix()) const d = add(new Date('2018-01-01'), postgresInterval('1 mon')) expect(d instanceof moment).toBeTruthy() expect(d.unix()).toBe(moment('2018-02-01 01:00:00').unix()) const e = add(moment('2018-01-01'), postgresInterval('1 mon')) expect(e instanceof moment).toBeTruthy() expect(e.unix()).toBe(moment('2018-02-01').unix())
test('applyPgInterval.subtract', async () => { expect.assertions(19) const a = subtract('2018-01-01', postgresInterval('1 mon')) expect(a instanceof moment).toBeTruthy() expect(a.unix()).toBe(moment('2017-12-01').unix()) const b = subtract('2018-01-01', postgresInterval('1 mon 15 days')) expect(b instanceof moment).toBeTruthy() expect(b.unix()).toBe(moment('2017-11-16').unix()) const c = subtract('2018-01-01', postgresInterval('1 mon 15 days 12:00:00')) expect(c instanceof moment).toBeTruthy() expect(c.unix()).toBe(moment('2017-11-15 12:00').unix()) const d = subtract(new Date('2018-01-01'), postgresInterval('1 mon')) expect(d instanceof moment).toBeTruthy() expect(d.unix()).toBe(moment('2017-12-01 01:00:00').unix()) const e = subtract(moment('2018-01-01'), postgresInterval('1 mon')) expect(e instanceof moment).toBeTruthy() expect(e.unix()).toBe(moment('2017-12-01').unix())
test('applyPgInterval.mutate', async () => { expect.assertions(11) const a = mutate('2018-01-01', postgresInterval('1 mon 15 days'), 'add') expect(a instanceof moment).toBeTruthy() expect(a.unix()).toBe(moment('2018-02-16').unix()) const b = mutate('2018-01-01', postgresInterval('1 mon 15 days'), 'subtract') expect(b instanceof moment).toBeTruthy() expect(b.unix()).toBe(moment('2017-11-16').unix()) expect(() => mutate('2018-01-01')).toThrowError(/mutation missing/) expect(() => mutate('2018-01-01', null, 'foobar')).toThrowError(/not supported/) expect(() => mutate('2018-01-01', null, 'add')).toThrowError(/interval missing/) expect(() => mutate('2018-01-01', 'not-an-interval', 'add')).toThrowError(/not an object/) expect(() => mutate('2018-01-01', {}, 'add')).toThrowError(/has no keys/) expect(() => mutate('2018-01-01', { foo: 'bar' }, 'add')).toThrowError(/contains invalid keys/) expect(() => mutate('2018-01-01', { months: 10, foo: 'bar' }, 'add')).toThrowError(/contains invalid keys/) })
test('applyPgInterval.add', async () => { expect.assertions(19) const a = add('2018-01-01', postgresInterval('1 mon')) expect(a instanceof moment).toBeTruthy() expect(a.unix()).toBe(moment('2018-02-01').unix()) const b = add('2018-01-01', postgresInterval('1 mon 15 days')) expect(b instanceof moment).toBeTruthy() expect(b.unix()).toBe(moment('2018-02-16').unix()) const c = add('2018-01-01', postgresInterval('1 mon 15 days 12:00:00')) expect(c instanceof moment).toBeTruthy() expect(c.unix()).toBe(moment('2018-02-16 12:00').unix()) const d = add(new Date('2018-01-01'), postgresInterval('1 mon')) expect(d instanceof moment).toBeTruthy() expect(d.unix()).toBe(moment('2018-02-01 01:00:00').unix()) const e = add(moment('2018-01-01'), postgresInterval('1 mon')) expect(e instanceof moment).toBeTruthy() expect(e.unix()).toBe(moment('2018-02-01').unix())
test('applyPgInterval.subtract', async () => { expect.assertions(19) const a = subtract('2018-01-01', postgresInterval('1 mon')) expect(a instanceof moment).toBeTruthy() expect(a.unix()).toBe(moment('2017-12-01').unix()) const b = subtract('2018-01-01', postgresInterval('1 mon 15 days')) expect(b instanceof moment).toBeTruthy() expect(b.unix()).toBe(moment('2017-11-16').unix()) const c = subtract('2018-01-01', postgresInterval('1 mon 15 days 12:00:00')) expect(c instanceof moment).toBeTruthy() expect(c.unix()).toBe(moment('2017-11-15 12:00').unix()) const d = subtract(new Date('2018-01-01'), postgresInterval('1 mon')) expect(d instanceof moment).toBeTruthy() expect(d.unix()).toBe(moment('2017-12-01 01:00:00').unix()) const e = subtract(moment('2018-01-01'), postgresInterval('1 mon')) expect(e instanceof moment).toBeTruthy() expect(e.unix()).toBe(moment('2017-12-01').unix())