import assert from 'assert' ; import eachQuarterOfInterval from '.' ; describe ( 'eachQuarterOfInterval' , ( ) => { it ( 'returns an array with starts of quarters from the quarter of the start date to the quarter of the end date' , ( ) => { const result = eachQuarterOfInterval ( { start : new Date ( 2014 , 2 , 6 ) , end : new Date ( 2014 , 7 , 12 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 0 , 1 ) , new Date ( 2014 , 3 , 1 ) , new Date ( 2014 , 6 , 1 ) , ] ) ; } ) ; it ( 'accepts timestamps' , ( ) => { const result = eachQuarterOfInterval ( { start : new Date ( 2014 , 2 , 6 ) . getTime ( ) , end : new Date ( 2014 , 7 , 12 ) . getTime ( ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 0 , 1 ) , new Date ( 2014 , 3 , 1 ) , new Date ( 2014 , 6 , 1 ) , ] ) ; } ) ; it ( 'handles the dates that are not starts of days' , ( ) => { const result = eachQuarterOfInterval ( { start : new Date ( 2014 , 2 , 6 , 6 , 35 ) , end : new Date ( 2014 , 7 , 12 , 22 , 15 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 0 , 1 ) , new Date ( 2014 , 3 , 1 ) , new Date ( 2014 , 6 , 1 ) , ] ) ; } ) ; it ( 'handles the dates that are not containing days' , ( ) => { const result = eachQuarterOfInterval ( { start : new Date ( 2014 , 2 ) , end : new Date ( 2014 , 7 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 0 , 1 ) , new Date ( 2014 , 3 , 1 ) , new Date ( 2014 , 6 , 1 ) , ] ) ; } ) ; it ( 'returns one quarter if the both arguments are on the same quarter' , ( ) => { const result = eachQuarterOfInterval ( { start : new Date ( 2014 , 0 , 6 , 14 ) , end : new Date ( 2014 , 2 , 9 , 15 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 0 , 1 ) ] ) ; } ) ; it ( 'returns one quarter if the both arguments are the same' , ( ) => { const result = eachQuarterOfInterval ( { start : new Date ( 2014 , 9 , 6 , 14 ) , end : new Date ( 2014 , 9 , 6 , 14 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 9 , 1 ) ] ) ; } ) ; it ( 'throws an exception if the start date is after the end date' , ( ) => { const block = eachQuarterOfInterval . bind ( null , { start : new Date ( 2014 , 9 , 12 ) , end : new Date ( 2014 , 9 , 6 ) , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws an exception if the start date is `Invalid Date`' , ( ) => { const block = eachQuarterOfInterval . bind ( null , { start : new Date ( NaN ) , end : new Date ( 2014 , 9 , 6 ) , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws an exception if the end date is `Invalid Date`' , ( ) => { const block = eachQuarterOfInterval . bind ( null , { start : new Date ( 2014 , 9 , 12 ) , end : new Date ( NaN ) , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws an exception if the interval is undefined' , ( ) => { const block = ( ) => eachQuarterOfInterval ( undefined ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws TypeError exception if passed less than 1 argument' , ( ) => { assert . throws ( eachQuarterOfInterval . bind ( null ) , TypeError ) ; } ) ; } ) ;