@@ -170,3 +170,126 @@ async def test_delete_old_appointments(db_conn, company, settings):
170170
171171 assert {(1 , 1 ), (3 , 3 )} == await select_set (db_conn , sa_appointments .c .id , sa_appointments .c .service )
172172 assert {(1 ,), (3 ,)} == await select_set (db_conn , sa_services .c .id )
173+
174+
175+ async def test_clear_apts (cli , db_conn , company ):
176+ await create_appointment (db_conn , company , appointment_extra = {'id' : 1 })
177+ for i in range (10 ):
178+ await create_appointment (
179+ db_conn ,
180+ company ,
181+ create_service = False ,
182+ appointment_extra = dict (
183+ id = i + 2 ,
184+ start = datetime (2032 , 1 , 1 , 12 , 0 , 0 ) + timedelta (days = i + 1 ),
185+ finish = datetime (2032 , 1 , 1 , 13 , 0 , 0 ) + timedelta (days = i + 1 ),
186+ ),
187+ )
188+
189+ assert 11 == await count (db_conn , sa_appointments )
190+ assert 1 == await count (db_conn , sa_services )
191+
192+ url = cli .server .app .router ['webhook-appointment-clear' ].url_for (company = 'thepublickey' )
193+ r = await signed_request (cli , url , method_ = 'DELETE' )
194+ assert r .status == 200
195+ assert {'status' : 'success' } == await r .json ()
196+
197+ assert 0 == await count (db_conn , sa_appointments )
198+ assert 0 == await count (db_conn , sa_services )
199+
200+
201+ async def test_mass_apts (cli , db_conn , company ):
202+ await create_appointment (db_conn , company , appointment_extra = {'id' : 1 })
203+ assert 1 == await count (db_conn , sa_appointments )
204+ assert 1 == await count (db_conn , sa_services )
205+
206+ data = dict ()
207+ for i in range (10 ):
208+ data [str (i + 2 )] = dict (
209+ service_id = 1 ,
210+ service_name = 'test service' ,
211+ extra_attributes = [],
212+ colour = '#000000' ,
213+ appointment_topic = 'testing appointment' ,
214+ attendees_max = 42 ,
215+ attendees_count = 4 ,
216+ attendees_current_ids = [1 , 2 , 3 ],
217+ start = str (datetime (2032 , 1 , 1 , 12 , 0 , 0 ) + timedelta (days = i + 1 )),
218+ finish = str (datetime (2032 , 1 , 1 , 13 , 0 , 0 ) + timedelta (days = i + 1 )),
219+ price = 123.45 ,
220+ location = 'Whatever' ,
221+ ss_method = 'POST'
222+ )
223+ url = cli .server .app .router ['webhook-appointment-mass' ].url_for (company = 'thepublickey' )
224+ r = await signed_request (cli , url , ** data )
225+ assert r .status == 200
226+ assert {'status' : 'success' } == await r .json ()
227+
228+ assert 11 == await count (db_conn , sa_appointments )
229+ assert 1 == await count (db_conn , sa_services )
230+
231+ data = dict ()
232+ for i in range (9 ):
233+ data [str (i + 2 )] = dict (
234+ service_id = 1 ,
235+ service_name = 'test service' ,
236+ extra_attributes = [],
237+ colour = '#000000' ,
238+ appointment_topic = 'testing appointment' ,
239+ attendees_max = 42 ,
240+ attendees_count = 4 ,
241+ attendees_current_ids = [1 , 2 , 3 ],
242+ start = str (datetime (2032 , 1 , 1 , 12 , 0 , 0 ) + timedelta (days = i + 1 )),
243+ finish = str (datetime (2032 , 1 , 1 , 13 , 0 , 0 ) + timedelta (days = i + 1 )),
244+ price = 123.45 ,
245+ location = 'Whatever' ,
246+ ss_method = 'POST'
247+ )
248+ data ['10' ] = {'ss_method' : 'DELETE' }
249+ data ['11' ] = {'ss_method' : 'DELETE' }
250+ url = cli .server .app .router ['webhook-appointment-mass' ].url_for (company = 'thepublickey' )
251+ r = await signed_request (cli , url , ** data )
252+ assert r .status == 200
253+ assert {'status' : 'success' } == await r .json ()
254+
255+ assert 9 == await count (db_conn , sa_appointments )
256+ assert 1 == await count (db_conn , sa_services )
257+
258+
259+ async def test_mass_apts_and_services (cli , db_conn , company ):
260+ await create_appointment (db_conn , company , appointment_extra = {'id' : 1 })
261+ assert 1 == await count (db_conn , sa_appointments )
262+ assert 1 == await count (db_conn , sa_services )
263+
264+ data = dict ()
265+ for i in range (10 ):
266+ data [str (i + 2 )] = dict (
267+ service_id = i + 2 ,
268+ service_name = 'test service' ,
269+ extra_attributes = [],
270+ colour = '#000000' ,
271+ appointment_topic = 'testing appointment' ,
272+ attendees_max = 42 ,
273+ attendees_count = 4 ,
274+ attendees_current_ids = [1 , 2 , 3 ],
275+ start = str (datetime (2032 , 1 , 1 , 12 , 0 , 0 ) + timedelta (days = i + 1 )),
276+ finish = str (datetime (2032 , 1 , 1 , 13 , 0 , 0 ) + timedelta (days = i + 1 )),
277+ price = 123.45 ,
278+ location = 'Whatever' ,
279+ ss_method = 'POST'
280+ )
281+ url = cli .server .app .router ['webhook-appointment-mass' ].url_for (company = 'thepublickey' )
282+ r = await signed_request (cli , url , ** data )
283+ assert r .status == 200
284+ assert {'status' : 'success' } == await r .json ()
285+
286+ assert 11 == await count (db_conn , sa_appointments )
287+ assert 11 == await count (db_conn , sa_services )
288+
289+ url = cli .server .app .router ['webhook-appointment-clear' ].url_for (company = 'thepublickey' )
290+ r = await signed_request (cli , url , method_ = 'DELETE' )
291+ assert r .status == 200
292+ assert {'status' : 'success' } == await r .json ()
293+
294+ assert 0 == await count (db_conn , sa_appointments )
295+ assert 0 == await count (db_conn , sa_services )
0 commit comments