@@ -174,6 +174,25 @@ async def test_delete_old_appointments(db_conn, company, settings):
174174
175175
176176async def test_clear_apts (cli , db_conn , company ):
177+ company2 = await create_company (db_conn , 'compan2_public' , 'compan2_private' , name = 'company2' )
178+ await db_conn .execute (
179+ sa_services .insert ().values (
180+ ** dict (
181+ id = 2 ,
182+ company = company2 .id ,
183+ name = 'testing service' ,
184+ extra_attributes = [
185+ {
186+ 'name' : 'Foobar' ,
187+ 'type' : 'text_short' ,
188+ 'machine_name' : 'foobar' ,
189+ 'value' : 'this is the value of foobar' ,
190+ }
191+ ],
192+ colour = '#abc' ,
193+ )
194+ )
195+ )
177196 await create_appointment (db_conn , company , appointment_extra = {'id' : 1 })
178197 for i in range (10 ):
179198 await create_appointment (
@@ -187,16 +206,29 @@ async def test_clear_apts(cli, db_conn, company):
187206 ),
188207 )
189208
190- assert 11 == await count (db_conn , sa_appointments )
191- assert 1 == await count (db_conn , sa_services )
209+ for i in range (11 , 21 ):
210+ await create_appointment (
211+ db_conn ,
212+ company2 ,
213+ create_service = False ,
214+ appointment_extra = dict (
215+ id = i + 2 ,
216+ start = datetime (2032 , 1 , 1 , 12 , 0 , 0 ) + timedelta (days = i + 1 ),
217+ finish = datetime (2032 , 1 , 1 , 13 , 0 , 0 ) + timedelta (days = i + 1 ),
218+ ),
219+ service_extra = dict (id = 2 ),
220+ )
221+
222+ assert 21 == await count (db_conn , sa_appointments )
223+ assert 2 == await count (db_conn , sa_services )
192224
193225 url = cli .server .app .router ['webhook-appointment-clear' ].url_for (company = 'thepublickey' )
194226 r = await signed_request (cli , url , method_ = 'DELETE' )
195227 assert r .status == 200
196228 assert {'status' : 'success' } == await r .json ()
197229
198- assert 0 == await count (db_conn , sa_appointments )
199- assert 0 == await count (db_conn , sa_services )
230+ assert 10 == await count (db_conn , sa_appointments )
231+ assert 1 == await count (db_conn , sa_services )
200232
201233
202234async def test_mass_apts (cli , db_conn , company ):
0 commit comments