11import TDSClient , { Task } from ".." ;
22import { APITaskObject , ClientCreatedTask } from "../definitions" ;
3+ import moment from "moment" ;
34
45const myClient = TDSClient ( process . env . TODOIST_TOKEN ) ;
56
7+ beforeAll ( async ( ) => {
8+ let allTasksJSON = await myClient . task . getAllJSON ( ) ;
9+
10+ for ( let i = 0 ; i < allTasksJSON . length ; ++ i ) {
11+ await myClient . task . delete ( allTasksJSON [ i ] . id ) ;
12+ }
13+ console . log ( "Init: Deleted all tasks!" ) ;
14+ } ) ;
15+
16+ afterAll ( async ( ) => {
17+ let allTasksJSON = await myClient . task . getAllJSON ( ) ;
18+
19+ for ( let i = 0 ; i < allTasksJSON . length ; ++ i ) {
20+ await myClient . task . delete ( allTasksJSON [ i ] . id ) ;
21+ }
22+ console . log ( "Finish: Deleted all tasks!" ) ;
23+ } ) ;
24+
625const generalExpectedTask = Task ( {
726 content : "Hello world" ,
827} ) ;
@@ -113,7 +132,7 @@ describe("API Tasks Functions", () => {
113132 } ) ;
114133
115134 // no active tasks now
116- /* Not working now because of #19
135+
117136 test ( "Create Two Tasks For Today" , async ( ) => {
118137 // create tasks in today inbox
119138 const due_info = {
@@ -132,12 +151,20 @@ describe("API Tasks Functions", () => {
132151 ( taskObj ) => taskObj . content === "Second task"
133152 ) ;
134153
135- console.log(allTodayJSON);
136-
137- expect(allTodayJSON.length).toBe(2);
138- expect(typeof allTodayJSON[0]).toBe("object");
139- expect(firstTaskExists).toBe(true);
140- expect(secondTaskExists).toBe(true);
154+ let normalDate = new Date ( ) . toISOString ( ) . substring ( 0 , 10 ) ;
155+ let momentDate = moment . parseZone ( new Date ( ) ) . format ( ) . substring ( 0 , 10 ) ;
156+
157+ if ( normalDate === momentDate ) {
158+ // GMT day = local day
159+ expect ( allTodayJSON . length ) . toBe ( 2 ) ;
160+ expect ( typeof allTodayJSON [ 0 ] ) . toBe ( "object" ) ;
161+ expect ( firstTaskExists ) . toBe ( true ) ;
162+ expect ( secondTaskExists ) . toBe ( true ) ;
163+ } else {
164+ // GMT day != local day (offset influence in day)
165+ expect ( allTodayJSON . length ) . toBe ( 0 ) ;
166+ expect ( firstTaskExists ) . toBe ( false ) ;
167+ expect ( secondTaskExists ) . toBe ( false ) ;
168+ }
141169 } ) ;
142- */
143170} ) ;
0 commit comments