import 'package:flutter_test/flutter_test.dart'; import 'package:marianum_mobile/api/marianumcloud/files_sharing/queries/share/share.dart'; void main() { group('Share.fromJson', () { test('parses a public link share (id/share_type as strings)', () { final share = Share.fromJson({ 'id': '42', 'share_type': '3', 'permissions': 1, 'path': '/Documents/x.pdf', 'item_type': 'file', 'url': 'https://cloud.example/s/abc', 'token': 'abc', 'expiration': '2026-07-01 00:00:00', }); expect(share.id, 42); expect(share.shareType, kShareTypePublicLink); expect(share.isPublicLink, isTrue); expect(share.url, 'https://cloud.example/s/abc'); expect(share.expiration, '2026-07-01 00:00:00'); }); test('parses a user share with display name', () { final share = Share.fromJson({ 'id': 7, 'share_type': 0, 'permissions': 19, 'share_with': 'jdoe', 'share_with_displayname': 'John Doe', 'item_type': 'folder', }); expect(share.shareType, kShareTypeUser); expect(share.isFolder, isTrue); expect(share.displayTitle, 'John Doe'); }); test('group share falls back to share_with when no display name', () { final share = Share.fromJson({ 'id': 8, 'share_type': 1, 'permissions': 1, 'share_with': 'students', }); expect(share.isGroup, isTrue); expect(share.displayTitle, 'students'); }); test('missing optional fields become null', () { final share = Share.fromJson({ 'id': 1, 'share_type': 0, 'permissions': 1, }); expect(share.url, isNull); expect(share.expiration, isNull); expect(share.shareWithDisplayname, isNull); // empty strings are treated as absent final withEmpties = Share.fromJson({ 'id': 1, 'share_type': 0, 'permissions': 1, 'url': '', }); expect(withEmpties.url, isNull); }); }); }