import 'package:fuel_tax_tracker/services/cloud/webdav_provider.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
final baseUrl = Uri.parse('https://cloud.example.com/');
group('parseWebDavMultistatus', () {
// Real WebDAV servers disagree on namespace prefix for the same "DAV:"
// namespace — Nextcloud defaults to `d:`, many Apache mod_dav setups
// use `D:`, and some use no prefix at all with a default xmlns. All
// three must parse identically since the parser matches by local name.
test('parses a lowercase d: prefixed response (Nextcloud-style)', () {
final xml = '''
/remote.php/dav/files/user/MO-Fuel-Tax-Back/
"abc123"
HTTP/1.1 200 OK
/remote.php/dav/files/user/MO-Fuel-Tax-Back/receipts/
"def456"
HTTP/1.1 200 OK
/remote.php/dav/files/user/MO-Fuel-Tax-Back/fuel_tax_tracker.db
"ghi789"
HTTP/1.1 200 OK
''';
final entries = parseWebDavMultistatus(xml, baseUrl);
expect(entries, hasLength(3));
expect(entries[0].path, '/remote.php/dav/files/user/MO-Fuel-Tax-Back/');
expect(entries[0].isCollection, isTrue);
expect(entries[0].etag, '"abc123"');
expect(entries[1].isCollection, isTrue);
expect(entries[2].path, endsWith('fuel_tax_tracker.db'));
expect(entries[2].isCollection, isFalse);
expect(entries[2].etag, '"ghi789"');
});
test('parses an uppercase D: prefixed response identically', () {
final xml = '''
/dav/MO-Fuel-Tax-Back/
"xyz111"
HTTP/1.1 200 OK
''';
final entries = parseWebDavMultistatus(xml, baseUrl);
expect(entries, hasLength(1));
expect(entries.first.isCollection, isTrue);
expect(entries.first.etag, '"xyz111"');
});
test('parses an unprefixed default-namespace response identically', () {
final xml = '''
/dav/MO-Fuel-Tax-Back/lock-file.lock
"lock999"
HTTP/1.1 200 OK
''';
final entries = parseWebDavMultistatus(xml, baseUrl);
expect(entries, hasLength(1));
expect(entries.first.isCollection, isFalse);
expect(entries.first.path, '/dav/MO-Fuel-Tax-Back/lock-file.lock');
});
test('a file with no getetag prop yields a null etag', () {
final xml = '''
/dav/no-etag.txt
HTTP/1.1 200 OK
''';
final entries = parseWebDavMultistatus(xml, baseUrl);
expect(entries.single.etag, isNull);
});
});
}