Skip to content

Commit

Permalink
Pull request #33: create unit tests for json serialization
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-flutter from dkomusanac-MM-4939-flutter-tests to main

Squashed commit of the following:

commit ab06d944b8ebf189f26942bbaa1fff25b14aff56
Author: Davor Komušanac <[email protected]>
Date:   Thu Oct 6 15:00:09 2022 +0200

    rename json_test_helper to json_test_stubs

commit f2787744247c911522f71495cb879b3b42f74a58
Author: Davor Komušanac <[email protected]>
Date:   Thu Oct 6 11:14:22 2022 +0200

    create unit tests for json serialization
  • Loading branch information
davor-komusanac committed Oct 7, 2022
1 parent 90d382c commit bddcb81
Show file tree
Hide file tree
Showing 6 changed files with 540 additions and 169 deletions.
2 changes: 1 addition & 1 deletion lib/models/Configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AndroidSettings {

Map<String, dynamic> toJson() =>
{
'firebaseOptions': firebaseOptions,
'firebaseOptions': firebaseOptions.toJson(),
'notificationIcon': notificationIcon,
'multipleNotifications': multipleNotifications,
'notificationAccentColor': notificationAccentColor
Expand Down
132 changes: 91 additions & 41 deletions lib/models/Installation.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:collection/collection.dart';

enum OS { Android, iOS }

Expand All @@ -25,26 +26,27 @@ class Installation {
final String? deviceName;
Map<String, dynamic>? customAttributes;

Installation(
{this.pushRegistrationId,
this.pushServiceType,
this.pushServiceToken,
this.isPrimaryDevice,
this.isPushRegistrationEnabled,
this.notificationsEnabled,
this.geoEnabled,
this.sdkVersion,
this.appVersion,
this.os,
this.osVersion,
this.deviceManufacturer,
this.deviceModel,
this.deviceSecure,
this.language,
this.deviceTimezoneOffset,
this.applicationUserId,
this.deviceName,
this.customAttributes});
Installation({
this.pushRegistrationId,
this.pushServiceType,
this.pushServiceToken,
this.isPrimaryDevice,
this.isPushRegistrationEnabled,
this.notificationsEnabled,
this.geoEnabled,
this.sdkVersion,
this.appVersion,
this.os,
this.osVersion,
this.deviceManufacturer,
this.deviceModel,
this.deviceSecure,
this.language,
this.deviceTimezoneOffset,
this.applicationUserId,
this.deviceName,
this.customAttributes,
});

static PushServiceType? resolvePushServiceType(String? pst) {
if (pst == null) {
Expand All @@ -70,27 +72,27 @@ class Installation {
}

Map<String, dynamic> toJson() => {
'pushRegistrationId': pushRegistrationId,
'pushServiceToken': pushServiceToken,
'pushServiceType':
pushServiceType != null ? describeEnum(pushServiceType!) : null,
'isPrimaryDevice': isPrimaryDevice,
'isPushRegistrationEnabled': isPushRegistrationEnabled,
'notificationsEnabled': notificationsEnabled,
'geoEnabled': geoEnabled,
'sdkVersion': sdkVersion,
'appVersion': appVersion,
'os': os != null ? describeEnum(os!) : null,
'osVersion': osVersion,
'deviceManufacturer': deviceManufacturer,
'deviceModel': deviceModel,
'deviceSecure': deviceSecure,
'language': language,
'deviceTimezoneOffset': deviceTimezoneOffset,
'applicationUserId': applicationUserId,
'deviceName': deviceName,
'customAttributes': customAttributes,
};
'pushRegistrationId': pushRegistrationId,
'pushServiceToken': pushServiceToken,
'pushServiceType':
pushServiceType != null ? describeEnum(pushServiceType!) : null,
'isPrimaryDevice': isPrimaryDevice,
'isPushRegistrationEnabled': isPushRegistrationEnabled,
'notificationsEnabled': notificationsEnabled,
'geoEnabled': geoEnabled,
'sdkVersion': sdkVersion,
'appVersion': appVersion,
'os': os != null ? describeEnum(os!) : null,
'osVersion': osVersion,
'deviceManufacturer': deviceManufacturer,
'deviceModel': deviceModel,
'deviceSecure': deviceSecure,
'language': language,
'deviceTimezoneOffset': deviceTimezoneOffset,
'applicationUserId': applicationUserId,
'deviceName': deviceName,
'customAttributes': customAttributes,
};

Installation.fromJson(Map<String, dynamic> json)
: isPrimaryDevice = json['isPrimaryDevice'],
Expand All @@ -117,6 +119,54 @@ class Installation {
String? getPushRegistrationId() {
return this.pushRegistrationId;
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Installation &&
runtimeType == other.runtimeType &&
pushRegistrationId == other.pushRegistrationId &&
pushServiceToken == other.pushServiceToken &&
pushServiceType == other.pushServiceType &&
isPrimaryDevice == other.isPrimaryDevice &&
isPushRegistrationEnabled == other.isPushRegistrationEnabled &&
notificationsEnabled == other.notificationsEnabled &&
geoEnabled == other.geoEnabled &&
sdkVersion == other.sdkVersion &&
appVersion == other.appVersion &&
os == other.os &&
osVersion == other.osVersion &&
deviceManufacturer == other.deviceManufacturer &&
deviceModel == other.deviceModel &&
deviceSecure == other.deviceSecure &&
language == other.language &&
deviceTimezoneOffset == other.deviceTimezoneOffset &&
applicationUserId == other.applicationUserId &&
deviceName == other.deviceName &&
DeepCollectionEquality()
.equals(customAttributes, other.customAttributes);

@override
int get hashCode =>
pushRegistrationId.hashCode ^
pushServiceToken.hashCode ^
pushServiceType.hashCode ^
isPrimaryDevice.hashCode ^
isPushRegistrationEnabled.hashCode ^
notificationsEnabled.hashCode ^
geoEnabled.hashCode ^
sdkVersion.hashCode ^
appVersion.hashCode ^
os.hashCode ^
osVersion.hashCode ^
deviceManufacturer.hashCode ^
deviceModel.hashCode ^
deviceSecure.hashCode ^
language.hashCode ^
deviceTimezoneOffset.hashCode ^
applicationUserId.hashCode ^
deviceName.hashCode ^
customAttributes.hashCode;
}

class InstallationPrimary {
Expand Down
71 changes: 51 additions & 20 deletions lib/models/UserData.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:collection/collection.dart';

enum Gender { Male, Female }

Expand All @@ -16,15 +17,15 @@ class UserData {

UserData(
{this.externalUserId,
this.firstName,
this.lastName,
this.middleName,
this.gender,
this.birthday,
this.phones,
this.emails,
this.tags,
this.customAttributes});
this.firstName,
this.lastName,
this.middleName,
this.gender,
this.birthday,
this.phones,
this.emails,
this.tags,
this.customAttributes});

static Gender? resolveGender(String? str) {
if (str == null) {
Expand Down Expand Up @@ -58,15 +59,45 @@ class UserData {
customAttributes = json['customAttributes'];

Map<String, dynamic> toJson() => {
'externalUserId': externalUserId,
'firstName': firstName,
'lastName': lastName,
'middleName': middleName,
'gender': gender != null ? describeEnum(gender!) : null,
'birthday': birthday,
'phones': phones,
'emails': emails,
'tags': tags,
'customAttributes': customAttributes
};
'externalUserId': externalUserId,
'firstName': firstName,
'lastName': lastName,
'middleName': middleName,
'gender': gender != null ? describeEnum(gender!) : null,
'birthday': birthday,
'phones': phones,
'emails': emails,
'tags': tags,
'customAttributes': customAttributes
};

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is UserData &&
runtimeType == other.runtimeType &&
externalUserId == other.externalUserId &&
firstName == other.firstName &&
lastName == other.lastName &&
middleName == other.middleName &&
gender == other.gender &&
birthday == other.birthday &&
listEquals(phones, other.phones) &&
listEquals(emails, other.emails) &&
listEquals(tags, other.tags) &&
DeepCollectionEquality()
.equals(customAttributes, other.customAttributes);

@override
int get hashCode =>
externalUserId.hashCode ^
firstName.hashCode ^
lastName.hashCode ^
middleName.hashCode ^
gender.hashCode ^
birthday.hashCode ^
phones.hashCode ^
emails.hashCode ^
tags.hashCode ^
customAttributes.hashCode;
}
Loading

0 comments on commit bddcb81

Please sign in to comment.