Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
Fix app errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jsondergaard committed Nov 15, 2023
1 parent a13e4c1 commit 011e1d0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/http/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class HttpClient implements Http {
}
}

return Response(res, json!);
return Response(res, json ?? jsonDecode('{}'));

Check warning on line 113 in lib/http/http_client.dart

View check run for this annotation

Codecov / codecov/patch

lib/http/http_client.dart#L113

Added line #L113 was not covered by tests
});
}

Expand Down
15 changes: 9 additions & 6 deletions lib/models/week_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class WeekModel extends WeekBaseModel implements Model {
PictogramModel? thumbnail,
String? name,
List<WeekdayModel>? days,
this.weekYear,
this.weekNumber,
this.weekYear = 0,
this.weekNumber = 0,
}) : super(thumbnail: thumbnail, name: name, days: days);

/// Construct from JSON
WeekModel.fromJson(Map<String, dynamic>? json) : super.fromJson(json) {
weekYear = json!['weekYear'];
WeekModel.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
weekYear = json['weekYear'];
weekNumber = json['weekNumber'];
}

Expand All @@ -27,10 +27,13 @@ class WeekModel extends WeekBaseModel implements Model {
}

/// The year the week lies in
int? weekYear;
int weekYear = DateTime.now().year;

/// The week number
int? weekNumber;
int weekNumber =
DateTime.now().difference(DateTime(DateTime.now().year, 1, 1)).inDays ~/
7 +
1;

@override
Map<String, dynamic> toJson() {
Expand Down
4 changes: 2 additions & 2 deletions test/api/activity_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Future<void> main() async {

test('Should add an activity', () {
activityApi
.add(mockActivity, mockUser.id!, mockWeek.name!, mockWeek.weekYear!,
mockWeek.weekNumber!, mockWeek.days!.first.day!)
.add(mockActivity, mockUser.id!, mockWeek.name!, mockWeek.weekYear,
mockWeek.weekNumber, mockWeek.days!.first.day!)
.listen(expectAsync1((ActivityModel response) {
expect(response.toJson(), mockActivity.toJson());
}));
Expand Down
4 changes: 2 additions & 2 deletions test/api/week_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Future<void> main() async {
);

weekApi
.get(id, week.weekYear!, week.weekNumber!)
.get(id, week.weekYear, week.weekNumber)
.listen(expectAsync1((WeekModel resWeek) {
expect(resWeek.toJson(), week.toJson());
}));
Expand Down Expand Up @@ -106,7 +106,7 @@ Future<void> main() async {
);

weekApi
.update(id, week.weekYear!, week.weekNumber!, week)
.update(id, week.weekYear, week.weekNumber, week)
.listen(expectAsync1((WeekModel resWeek) {
expect(resWeek.toJson(), week.toJson());
}));
Expand Down
4 changes: 0 additions & 4 deletions test/models/week_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ void main() {
weekBaseTest(week2, response2);
});

test('Should throw exception when JSON is null', () {
expect(() => WeekModel.fromJson(null), throwsFormatException);
});

test('Should be able to serialize to JSON', () {
final WeekModel week1 = WeekModel.fromJson(response1!);
final WeekModel week2 = WeekModel.fromJson(response2!);
Expand Down

0 comments on commit 011e1d0

Please sign in to comment.