Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(nextcloud): refactor test file structure #2339

Merged
merged 6 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import 'package:crypton/crypton.dart';

part 'notifications_helpers.g.dart';

/// Generates the push token hash which is just sha512
/// Generates the push token hash which is just sha512.
String generatePushTokenHash(String pushToken) => sha512.convert(utf8.encode(pushToken)).toString();

/// {@template decrypted_subject}
/// Decrypted version of the encrypted push notification received from the server.
/// {@endtemplate}
abstract class DecryptedSubject implements Built<DecryptedSubject, DecryptedSubjectBuilder> {
// ignore: public_member_api_docs
/// {@macro decrypted_subject}
factory DecryptedSubject([void Function(DecryptedSubjectBuilder)? updates]) = _$DecryptedSubject;

const DecryptedSubject._();

/// Decrypts the subject of a push notification
/// Decrypts the subject of a push notification.
factory DecryptedSubject.fromEncrypted(RSAPrivateKey privateKey, String subject) => DecryptedSubject.fromJson(
json.decode(privateKey.decrypt(subject)) as Map<String, dynamic>,
);
Expand All @@ -34,28 +35,30 @@ abstract class DecryptedSubject implements Built<DecryptedSubject, DecryptedSubj
// ignore: public_member_api_docs
static Serializer<DecryptedSubject> get serializer => _$decryptedSubjectSerializer;

/// ID if the notification
/// ID if the notification.
int? get nid;

/// App that sent the notification
/// App that sent the notification.
String? get app;

/// Subject of the notification
/// Subject of the notification.
String? get subject;

/// Type of the notification
/// Type of the notification.
String? get type;

/// ID of the notification
/// ID of the notification.
String? get id;

/// Delete the notification
/// Delete the notification.
bool? get delete;

/// Delete all notifications
/// Delete all notifications.
@BuiltValueField(wireName: 'delete-all')
bool? get deleteAll;
}

@SerializersFor([DecryptedSubject])
final Serializers _serializers = (_$_serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build();
final Serializers _serializers = (Serializers().toBuilder()
..add(DecryptedSubject.serializer)
..addPlugin(StandardJsonPlugin()))
.build();

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/nextcloud/lib/src/api/spreed/spreed_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ enum ParticipantInCallFlag {
extension EnumByBinary<T extends Enum> on List<T> {
/// Converts the binary representation of an enum into enum values.
Set<T> byBinary(int value) {
RangeError.checkNotNegative(value, 'value');

final result = <T>{};

var v = value;
Expand Down Expand Up @@ -187,5 +189,5 @@ extension EnumCollectionBinary<T extends Enum> on Set<T> {
///
/// See [EnumBinary.binary] for getting the binary representation of a single enum value.
/// See [EnumByBinary.byBinary] for converting the binary representation into enum values.
int get binary => map((p) => p.binary).reduce((a, b) => a | b);
int get binary => map((p) => p.binary).fold(0, (a, b) => a | b);
}
1 change: 0 additions & 1 deletion packages/nextcloud/lib/src/api/webdav/models/props.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// coverage:ignore-file
import 'package:meta/meta.dart';
import 'package:nextcloud/src/api/webdav/webdav.dart';
import 'package:nextcloud/src/utils/date_time.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:xml/xml.dart';
import 'package:xml_annotation/xml_annotation.dart' as annotation;
Expand Down
1 change: 1 addition & 0 deletions packages/nextcloud/lib/src/api/webdav/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'options_parser.dart';
export 'webdav_response_converter.dart';
export 'webdav_uri.dart';
export 'xml_date_time_converter.dart';
export 'xml_duration_converter.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ final class WebDavResponseConverter with Converter<http.Response, WebDavMultista
/// Creates a new response converter
const WebDavResponseConverter();

static final _converter = XmlEventDecoder().fuse(const XmlNormalizeEvents()).fuse(const XmlNodeDecoder());

@override
WebDavMultistatus convert(http.Response input) {
final xml = XmlEventDecoder()
.fuse(const XmlNormalizeEvents())
.fuse(const XmlNodeDecoder())
.convert(input.body)
.firstWhere((element) => element is XmlElement) as XmlElement;
final xml = _converter.convert(input.body).firstWhere((element) => element is XmlElement) as XmlElement;

return WebDavMultistatus.fromXmlElement(xml);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import 'package:meta/meta.dart';
import 'package:nextcloud/utils.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:xml/xml.dart' as xml;
import 'package:xml_annotation/xml_annotation.dart' as xml_annotation;

@internal
final class HttpDateXMLConverter implements xml_annotation.XmlConverter<tz.TZDateTime?> {
const HttpDateXMLConverter();

@override
void buildXmlChildren(
tz.TZDateTime? instance,
xml.XmlBuilder builder, {
Map<String, String> namespaces = const {},
}) {
if (instance == null) {
return;
}

final date = formatHttpDate(instance);
builder.text(date);
}

@override
tz.TZDateTime? fromXmlElement(
xml.XmlElement element,
) {
final date = element.getText();
if (date != null) {
return parseHttpDate(date);
}

return null;
}

@override
List<xml.XmlAttribute> toXmlAttributes(
tz.TZDateTime? instance, {
Map<String, String?> namespaces = const {},
}) {
return const <xml.XmlAttribute>[];
}

@override
List<xml.XmlNode> toXmlChildren(
tz.TZDateTime? instance, {
Map<String, String?> namespaces = const {},
}) {
if (instance == null) {
return const <xml.XmlNode>[];
}

final date = formatHttpDate(instance);
return <xml.XmlNode>[
xml.XmlText(date),
];
}
}

@internal
final class ISO8601XMLConverter implements xml_annotation.XmlConverter<tz.TZDateTime?> {
const ISO8601XMLConverter();

@override
void buildXmlChildren(
tz.TZDateTime? instance,
xml.XmlBuilder builder, {
Map<String, String> namespaces = const {},
}) {
if (instance == null) {
return;
}

final date = instance.toIso8601String();
builder.text(date);
}

@override
tz.TZDateTime? fromXmlElement(
xml.XmlElement element,
) {
final date = element.getText();
if (date != null) {
return tz.TZDateTime.parse(tz.UTC, date);
}

return null;
}

@override
List<xml.XmlAttribute> toXmlAttributes(
tz.TZDateTime? instance, {
Map<String, String?> namespaces = const {},
}) {
return const <xml.XmlAttribute>[];
}

@override
List<xml.XmlNode> toXmlChildren(
tz.TZDateTime? instance, {
Map<String, String?> namespaces = const {},
}) {
if (instance == null) {
return const <xml.XmlNode>[];
}

final date = instance.toIso8601String();
return <xml.XmlNode>[
xml.XmlText(date),
];
}
}

@internal
final class UnixEpochXMLConverter implements xml_annotation.XmlConverter<tz.TZDateTime?> {
const UnixEpochXMLConverter();

@override
void buildXmlChildren(
tz.TZDateTime? instance,
xml.XmlBuilder builder, {
Map<String, String> namespaces = const {},
}) {
if (instance == null) {
return;
}

final date = instance.secondsSinceEpoch.toString();
builder.text(date);
}

@override
tz.TZDateTime? fromXmlElement(
xml.XmlElement element,
) {
final date = element.getText();
if (date != null) {
return DateTimeUtils.fromSecondsSinceEpoch(
tz.UTC,
int.parse(date),
);
}

return null;
}

@override
List<xml.XmlAttribute> toXmlAttributes(
tz.TZDateTime? instance, {
Map<String, String?> namespaces = const {},
}) {
return const <xml.XmlAttribute>[];
}

@override
List<xml.XmlNode> toXmlChildren(
tz.TZDateTime? instance, {
Map<String, String?> namespaces = const {},
}) {
if (instance == null) {
return const <xml.XmlNode>[];
}

final date = instance.secondsSinceEpoch.toString();
return <xml.XmlNode>[
xml.XmlText(date),
];
}
}
Loading