'use strict'

const test = require('ava')

const { subDays } = require('date-fns')

const ranges = require('../../src/constants/ranges')
const zeroDate = require('../../src/utils/zeroDate')
const offsetByRange = require('../../src/utils/offsetByRange')

test('return correct offset for RANGES_LAST_24_HOURS', async (t) => {

	const result = offsetByRange(ranges.RANGES_LAST_24_HOURS)

	t.deepEqual(result, subDays(zeroDate(), 1))

})

test('return correct offset for RANGES_LAST_7_DAYS', async (t) => {

	const result = offsetByRange(ranges.RANGES_LAST_7_DAYS)

	t.deepEqual(result, subDays(zeroDate(), 6))

})

test('return correct offset for RANGES_LAST_30_DAYS', async (t) => {

	const result = offsetByRange(ranges.RANGES_LAST_30_DAYS)

	t.deepEqual(result, subDays(zeroDate(), 29))

})

test('return null for RANGES_ALL_TIME', async (t) => {

	const result = offsetByRange(ranges.RANGES_ALL_TIME)

	t.is(result, null)

})


test('return null for other values', async (t) => {

	const resultString = offsetByRange('test')
	const resultNull = offsetByRange(null)
	const resultUndefined = offsetByRange(undefined)

	t.is(resultString, null)
	t.is(resultNull, null)
	t.is(resultUndefined, null)

})
@@ -43,16 +43,28 @@
 %0Aconst %7B
+ startOfDay,
  subDays
@@ -88,16 +88,16 @@
 e-fns')%0A
-
 %0Aconst r
@@ -146,61 +146,8 @@
 s')%0A
-const zeroDate = require('../../src/utils/zeroDate')%0A
 cons
@@ -366,26 +366,38 @@
 subDays(
-zero
+startOfDay(new 
 Date()
+)
 , 1))%0A%0A%7D
@@ -555,26 +555,38 @@
 subDays(
-zero
+startOfDay(new 
 Date()
+)
 , 6))%0A%0A%7D
@@ -750,18 +750,30 @@
 ays(
-zero
+startOfDay(new 
 Date()
+)
 , 29

Fix test