add date separator constant, update tests

This commit is contained in:
2016-08-22 11:09:16 -07:00
parent 2693c40423
commit faeb705dee
2 changed files with 24 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
export default { export default {
DEFAULT_SETTING_TIMEOUT: 10000, DEFAULT_SETTING_TIMEOUT: 10000,
DEFAULT_SETTING_DATE_SEPARATOR: '-',
DEFAULT_SETTING_INTERVAL: 'week', DEFAULT_SETTING_INTERVAL: 'week',
DEFAULT_SETTING_DOCTYPE: 'esqueue', DEFAULT_SETTING_DOCTYPE: 'esqueue',
}; };

View File

@@ -1,6 +1,7 @@
import expect from 'expect.js'; import expect from 'expect.js';
import sinon from 'sinon'; import sinon from 'sinon';
import moment from 'moment'; import moment from 'moment';
import constants from '../../../lib/constants';
import indexTimestamp from '../../../lib/helpers/index_timestamp'; import indexTimestamp from '../../../lib/helpers/index_timestamp';
const anchor = '2016-04-02T01:02:03.456'; // saturday const anchor = '2016-04-02T01:02:03.456'; // saturday
@@ -15,8 +16,10 @@ describe('Index timestamp interval', function () {
describe('timestamps', function () { describe('timestamps', function () {
let clock; let clock;
let separator;
beforeEach(function () { beforeEach(function () {
separator = constants.DEFAULT_SETTING_DATE_SEPARATOR;
clock = sinon.useFakeTimers(moment(anchor).valueOf()); clock = sinon.useFakeTimers(moment(anchor).valueOf());
}); });
@@ -27,50 +30,58 @@ describe('Index timestamp interval', function () {
describe('formats', function () { describe('formats', function () {
it('should return the year', function () { it('should return the year', function () {
const timestamp = indexTimestamp('year'); const timestamp = indexTimestamp('year');
expect(timestamp).to.equal('2016'); const str = `2016`;
expect(timestamp).to.equal(str);
}); });
it('should return the year and month', function () { it('should return the year and month', function () {
const timestamp = indexTimestamp('month'); const timestamp = indexTimestamp('month');
expect(timestamp).to.equal('2016-04'); const str = `2016${separator}04`;
expect(timestamp).to.equal(str);
}); });
it('should return the year, month, and first day of the week', function () { it('should return the year, month, and first day of the week', function () {
const timestamp = indexTimestamp('week'); const timestamp = indexTimestamp('week');
expect(timestamp).to.equal('2016-03-27'); const str = `2016${separator}03${separator}27`;
expect(timestamp).to.equal(str);
}); });
it('should return the year, month, and day of the week', function () { it('should return the year, month, and day of the week', function () {
const timestamp = indexTimestamp('day'); const timestamp = indexTimestamp('day');
expect(timestamp).to.equal('2016-04-02'); const str = `2016${separator}04${separator}02`;
expect(timestamp).to.equal(str);
}); });
it('should return the year, month, day and hour', function () { it('should return the year, month, day and hour', function () {
const timestamp = indexTimestamp('hour'); const timestamp = indexTimestamp('hour');
expect(timestamp).to.equal('2016-04-02-01'); const str = `2016${separator}04${separator}02${separator}01`;
expect(timestamp).to.equal(str);
}); });
it('should return the year, month, day, hour and minute', function () { it('should return the year, month, day, hour and minute', function () {
const timestamp = indexTimestamp('minute'); const timestamp = indexTimestamp('minute');
expect(timestamp).to.equal('2016-04-02-01-02'); const str = `2016${separator}04${separator}02${separator}01${separator}02`;
expect(timestamp).to.equal(str);
}); });
}); });
describe('date separator', function () { describe('date separator', function () {
it('should be customizable', function () { it('should be customizable', function () {
const separators = ['-', '.', '_']; const separators = ['-', '.', '_'];
separators.forEach(separator => { separators.forEach(customSep => {
const str = `2016${separator}04${separator}02${separator}01${separator}02`; const str = `2016${customSep}04${customSep}02${customSep}01${customSep}02`;
const timestamp = indexTimestamp('minute', separator); const timestamp = indexTimestamp('minute', customSep);
expect(timestamp).to.equal(str); expect(timestamp).to.equal(str);
}); });
}); });
it('should throw if a letter is used', function () { it('should throw if a letter is used', function () {
const separator = 'a'; const separators = ['a', 'B', 'YYYY'];
const fn = () => indexTimestamp('minute', separator); separators.forEach(customSep => {
const fn = () => indexTimestamp('minute', customSep);
expect(fn).to.throwException(); expect(fn).to.throwException();
}); });
}); });
}); });
}); });
});