workouttest_app/test/exercise_plan_test.dart
2021-04-02 11:42:26 +02:00

64 lines
2.3 KiB
Dart

import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/service/exercise_plan_service.dart';
import 'package:test/test.dart';
main() {
setUp(() {
Cache().setTestBaseUrl();
});
group('new Plan', () {
test('add new plan and plan details', () async {
final client = ExercisePlanApi();
ExercisePlan exercisePlan = ExercisePlan("Test plan " + DateTime.now().toIso8601String(), 62);
exercisePlan.dateAdd = DateTime.now();
ExercisePlan savedPlan = await client.saveExercisePlan(exercisePlan);
expect(savedPlan.name.substring(0, 9), "Test plan");
expect(savedPlan.customerId, 62);
int newPlanId = savedPlan.exercisePlanId!;
//savedPlan.exercisePlanId = newPlanId;
ExercisePlanDetail detail = ExercisePlanDetail(39 //exerciseTypeId
);
detail.serie = 3;
detail.repeats = 12;
detail.weightEquation = "90";
detail.exercisePlanId = newPlanId;
ExercisePlanDetail savedDetail = await client.saveExercisePlanDetail(detail);
expect(savedDetail.weightEquation, "90");
expect(savedDetail.repeats, 12);
expect(savedDetail.exercisePlanId, newPlanId);
await client.deleteExercisePlanDetail(savedDetail.exercisePlanDetailId!);
await client.deleteExercisePlan(savedPlan.exercisePlanId!);
});
});
test('get the last plan and change plan details', () async {
final client = ExercisePlanApi();
ExercisePlan? exercisePlan = await client.getLastExercisePlan(61);
List<ExercisePlanDetail> list = await client.getExercisePlanDetail(exercisePlan!.exercisePlanId!);
expect(list.length, 2);
ExercisePlanDetail detail = ExercisePlanDetail(3);
detail.serie = 4;
detail.repeats = 12;
detail.weightEquation = "10";
detail.exercisePlanId = exercisePlan.exercisePlanId!;
//list.add(detail);
ExercisePlanDetail newObjectToSave = await client.saveExercisePlanDetail(detail);
List<ExercisePlanDetail> list2 = await client.getExercisePlanDetail(exercisePlan.exercisePlanId!);
expect(list2.length, 3);
expect(list2.last.weightEquation, "10");
await client.deleteExercisePlanDetail(newObjectToSave.exercisePlanDetailId!);
});
}