@@ -2,7 +2,6 @@ import { TodoistApi } from '.'
22import { ENDPOINT_SYNC , getSyncBaseUri } from './consts/endpoints'
33import { HttpResponse , http , server } from './test-utils/msw-setup'
44import { DEFAULT_AUTH_TOKEN , DEFAULT_REQUEST_ID } from './test-utils/test-defaults'
5- import { findViewOptions } from './utils/view-options'
65
76function getTarget ( ) {
87 return new TodoistApi ( DEFAULT_AUTH_TOKEN )
@@ -111,7 +110,7 @@ describe('TodoistApi view options', () => {
111110 } )
112111 } )
113112
114- test ( 'deletes view options through Sync' , async ( ) => {
113+ test ( 'clears calendar settings through Sync' , async ( ) => {
115114 let requestBody : { commands ?: Array < Record < string , unknown > > } | undefined
116115 server . use (
117116 http . post ( `${ getSyncBaseUri ( ) } ${ ENDPOINT_SYNC } ` , async ( { request } ) => {
@@ -121,41 +120,29 @@ describe('TodoistApi view options', () => {
121120 } ) ,
122121 )
123122
124- await getTarget ( ) . deleteViewOptions ( { viewType : 'TODAY' } )
123+ await getTarget ( ) . setViewOptions ( { viewType : 'TODAY' , calendarSettings : null } )
125124
126125 expect ( requestBody ?. commands ?. [ 0 ] ) . toMatchObject ( {
127- type : 'view_options_delete ' ,
128- args : { view_type : 'TODAY' } ,
126+ type : 'view_options_set ' ,
127+ args : { view_type : 'TODAY' , calendar_settings : null } ,
129128 } )
130129 } )
131- } )
132130
133- describe ( 'findViewOptions' , ( ) => {
134- const options = [
135- { viewType : 'FILTER' as const , objectId : 'filter1' , sortedBy : 'DUE_DATE' as const } ,
136- {
137- viewType : 'WORKSPACE_FILTER' as const ,
138- objectId : 'filter2' ,
139- sortedBy : 'PRIORITY' as const ,
140- } ,
141- { viewType : 'UPCOMING' as const , objectId : null , sortedBy : 'DEADLINE' as const } ,
142- { viewType : 'TODAY' as const , isDeleted : true } ,
143- ]
144-
145- test ( 'matches object-backed views by type and ID' , ( ) => {
146- expect (
147- findViewOptions ( options , {
148- viewTypes : [ 'FILTER' , 'WORKSPACE_FILTER' ] ,
149- objectId : 'filter2' ,
150- } ) ?. sortedBy ,
151- ) . toBe ( 'PRIORITY' )
152- } )
131+ test ( 'deletes view options through Sync' , async ( ) => {
132+ let requestBody : { commands ?: Array < Record < string , unknown > > } | undefined
133+ server . use (
134+ http . post ( `${ getSyncBaseUri ( ) } ${ ENDPOINT_SYNC } ` , async ( { request } ) => {
135+ requestBody = ( await request . json ( ) ) as typeof requestBody
136+ const commandId = requestBody ?. commands ?. [ 0 ] ?. uuid as string
137+ return HttpResponse . json ( { sync_status : { [ commandId ] : 'ok' } } )
138+ } ) ,
139+ )
153140
154- test ( 'matches singleton views with null or omitted object IDs' , ( ) => {
155- expect ( findViewOptions ( options , { viewTypes : [ 'UPCOMING' ] } ) ?. sortedBy ) . toBe ( 'DEADLINE' )
156- } )
141+ await getTarget ( ) . deleteViewOptions ( { viewType : 'TODAY' } )
157142
158- test ( 'ignores deleted options' , ( ) => {
159- expect ( findViewOptions ( options , { viewTypes : [ 'TODAY' ] } ) ) . toBeUndefined ( )
143+ expect ( requestBody ?. commands ?. [ 0 ] ) . toMatchObject ( {
144+ type : 'view_options_delete' ,
145+ args : { view_type : 'TODAY' } ,
146+ } )
160147 } )
161148} )
0 commit comments