@@ -158,38 +158,76 @@ void main() {
158158 });
159159
160160 group ('getPreparationByScheduleId' , () {
161- test ('should return PreparationEntity when the response is successful ' ,
161+ test ('should return PreparationEntity ordered by nextPreparationId ' ,
162162 () async {
163163 // arrange
164- // when(dio.get(Endpoint.getPreparationByScheduleId(scheduleId))).thenAnswer(
165- // (_) async => Response(
166- // statusCode: 200,
167- // data: [
168- // {
169- // "preparationId": preparationStep1.id,
170- // "preparationName": preparationStep1.preparationName,
171- // "preparationTime": preparationStep1.preparationTime.inMinutes,
172- // "nextPreparationId": preparationStep1.nextPreparationId,
173- // },
174- // {
175- // "preparationId": preparationStep2.id,
176- // "preparationName": preparationStep2.preparationName,
177- // "preparationTime": preparationStep2.preparationTime.inMinutes,
178- // "nextPreparationId": preparationStep2.nextPreparationId,
179- // },
180- // ],
181- // requestOptions: RequestOptions(
182- // path: Endpoint.getPreparationByScheduleId(scheduleId),
183- // ),
184- // ),
185- // );
186-
187- // // act
188- // final result =
189- // await remoteDataSource.getPreparationByScheduleId(scheduleId);
190-
191- // // assert
192- // expect(result.preparationStepList.length, 2);
164+ final orderedFirstStep = PreparationStepEntity (
165+ id: uuid.v7 (),
166+ preparationName: 'Shower' ,
167+ preparationTime: const Duration (minutes: 10 ),
168+ nextPreparationId: null ,
169+ );
170+ final orderedSecondStep = PreparationStepEntity (
171+ id: uuid.v7 (),
172+ preparationName: 'Dress' ,
173+ preparationTime: const Duration (minutes: 5 ),
174+ nextPreparationId: null ,
175+ );
176+ final orderedThirdStep = PreparationStepEntity (
177+ id: uuid.v7 (),
178+ preparationName: 'Pack bag' ,
179+ preparationTime: const Duration (minutes: 3 ),
180+ nextPreparationId: null ,
181+ );
182+ final linkedFirstStep =
183+ orderedFirstStep.copyWith (nextPreparationId: orderedSecondStep.id);
184+ final linkedSecondStep =
185+ orderedSecondStep.copyWith (nextPreparationId: orderedThirdStep.id);
186+
187+ when (dio.get (Endpoint .getPreparationByScheduleId (scheduleId))).thenAnswer (
188+ (_) async => Response (
189+ statusCode: 200 ,
190+ data: {
191+ 'data' : [
192+ {
193+ 'preparationId' : orderedThirdStep.id,
194+ 'preparationName' : orderedThirdStep.preparationName,
195+ 'preparationTime' : orderedThirdStep.preparationTime.inMinutes,
196+ 'nextPreparationId' : orderedThirdStep.nextPreparationId,
197+ },
198+ {
199+ 'preparationId' : linkedFirstStep.id,
200+ 'preparationName' : linkedFirstStep.preparationName,
201+ 'preparationTime' : linkedFirstStep.preparationTime.inMinutes,
202+ 'nextPreparationId' : linkedFirstStep.nextPreparationId,
203+ },
204+ {
205+ 'preparationId' : linkedSecondStep.id,
206+ 'preparationName' : linkedSecondStep.preparationName,
207+ 'preparationTime' : linkedSecondStep.preparationTime.inMinutes,
208+ 'nextPreparationId' : linkedSecondStep.nextPreparationId,
209+ },
210+ ],
211+ },
212+ requestOptions: RequestOptions (
213+ path: Endpoint .getPreparationByScheduleId (scheduleId),
214+ ),
215+ ),
216+ );
217+
218+ // act
219+ final result =
220+ await remoteDataSource.getPreparationByScheduleId (scheduleId);
221+
222+ // assert
223+ expect (
224+ result.preparationStepList.map ((step) => step.id).toList (),
225+ [
226+ orderedFirstStep.id,
227+ orderedSecondStep.id,
228+ orderedThirdStep.id,
229+ ],
230+ );
193231 });
194232
195233 test ('should throw an exception when the response code is not 200' ,
0 commit comments