@@ -4,6 +4,7 @@ import 'package:mockito/mockito.dart';
44import 'package:on_time_front/core/constants/endpoint.dart' ;
55import 'package:on_time_front/data/data_sources/schedule_remote_data_source.dart' ;
66import 'package:on_time_front/data/models/create_schedule_request_model.dart' ;
7+ import 'package:on_time_front/data/models/update_schedule_request_model.dart' ;
78import 'package:on_time_front/domain/entities/place_entity.dart' ;
89import 'package:on_time_front/domain/entities/schedule_entity.dart' ;
910import 'package:uuid/uuid.dart' ;
@@ -36,6 +37,8 @@ void main() {
3637
3738 final tCreateScheduleModel =
3839 CreateScheduleRequestModel .fromEntity (tScheduleEntity);
40+ final tUpdateScheduleModel =
41+ UpdateScheduleRequestModel .fromEntity (tScheduleEntity);
3942
4043 setUp (() {
4144 dio = MockAppDio ();
@@ -85,48 +88,45 @@ void main() {
8588 });
8689 });
8790
88- // group('updateSchdule', () {
89- // test('should perform a PUT request on the /schedule/modify endpoint',
90- // () async {
91- // // arrange
92- // when(dio.put(Endpoint.updateSchedule(scheduleEntityId),
93- // data: tUpdateScheduleModel.toJson()))
94- // .thenAnswer(
95- // (_) async => Response(
96- // statusCode: 204,
97- // requestOptions:
98- // RequestOptions(path: Endpoint.updateSchedule(scheduleEntityId)),
99- // ),
100- // );
101-
102- // // act
103- // await scheduleRemoteDataSourceImpl.updateSchedule(tScheduleEntity);
104-
105- // // assert
106- // verify(dio.put(Endpoint.updateSchedule(scheduleEntityId),
107- // data: tUpdateScheduleModel.toJson()))
108- // .called(1);
109- // });
110-
111- // test('should throw an exception when the response code is not 204',
112- // () async {
113- // when(dio.put(Endpoint.updateSchedule(scheduleEntityId),
114- // data: tUpdateScheduleModel.toJson()))
115- // .thenAnswer(
116- // (_) async => Response(
117- // statusCode: 400,
118- // requestOptions:
119- // RequestOptions(path: Endpoint.updateSchedule(scheduleEntityId)),
120- // ),
121- // );
122-
123- // // act
124- // final call = scheduleRemoteDataSourceImpl.updateSchedule(tScheduleEntity);
125-
126- // // assert
127- // expect(call, throwsException);
128- // });
129- // });
91+ group ('updateSchedule' , () {
92+ test ('should perform a PUT request without completion fields' , () async {
93+ final updateJson = tUpdateScheduleModel.toJson ();
94+ expect (updateJson, isNot (contains ('latenessTime' )));
95+
96+ when (dio.put (Endpoint .updateSchedule (scheduleEntityId), data: updateJson))
97+ .thenAnswer (
98+ (_) async => Response (
99+ statusCode: 200 ,
100+ requestOptions:
101+ RequestOptions (path: Endpoint .updateSchedule (scheduleEntityId)),
102+ ),
103+ );
104+
105+ await scheduleRemoteDataSourceImpl.updateSchedule (tScheduleEntity);
106+
107+ verify (dio.put (Endpoint .updateSchedule (scheduleEntityId),
108+ data: updateJson))
109+ .called (1 );
110+ });
111+
112+ test ('should throw an exception when the response code is not 200' ,
113+ () async {
114+ when (dio.put (
115+ Endpoint .updateSchedule (scheduleEntityId),
116+ data: tUpdateScheduleModel.toJson (),
117+ )).thenAnswer (
118+ (_) async => Response (
119+ statusCode: 400 ,
120+ requestOptions:
121+ RequestOptions (path: Endpoint .updateSchedule (scheduleEntityId)),
122+ ),
123+ );
124+
125+ final call = scheduleRemoteDataSourceImpl.updateSchedule (tScheduleEntity);
126+
127+ expect (call, throwsException);
128+ });
129+ });
130130
131131 group ('deleteSchedule' , () {
132132 test ('should perform a DELETE request on the /schedule/delete endpoint' ,
0 commit comments