Files
noo/test/services/share_account_service_test.dart
T
Ayushya AmitabhandClaude Sonnet 5.5 02d612bfec Share sheet: Hidden and Storage toggles, plus diagnostics for the missing accounts
Two menu chips start at the account's app settings (hidden filter, storage
scope - now published per account), hidden-on asks for the app's unlock, and
external storage is detected via nc:mount-type incl. everything under a
mount. Adds logging for which accounts get published and why one is skipped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 20:15:19 -04:00

78 lines
2.6 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:noo/services/share_account_service.dart';
/// What the iOS Share Extension is given - the contract with
/// `ios/Shared/SharedAccount.swift`'s `SharedAccounts`.
void main() {
const alice = ShareAccountEntry(
id: 'cloud_example_com__alice',
serverUrl: 'https://cloud.example.com',
username: 'alice',
password: 's3cret',
hiddenFilter: 'include',
storageScope: 'all',
);
const bob = ShareAccountEntry(
id: 'nc_home_lan__bob',
serverUrl: 'https://nc.home.lan:8443/nextcloud',
username: 'bob',
password: 'pw',
hiddenFilter: 'hide',
storageScope: 'cloud',
);
Map<String, dynamic> build({
List<ShareAccountEntry> accounts = const [alice, bob],
String? activeId = 'nc_home_lan__bob',
bool login = true,
bool switching = true,
bool hidden = false,
}) => jsonDecode(
ShareAccountService.buildPayload(
accounts: accounts,
activeId: activeId,
loginLockEnabled: login,
lockAccountSwitching: switching,
lockHiddenFiles: hidden,
),
);
test('basic auth header matches what the app sends', () {
expect(
ShareAccountService.basicAuth('alice', 's3cret'),
'Basic ${base64Encode(utf8.encode('alice:s3cret'))}',
);
});
test('every account is listed with its own header, name and filter', () {
final accounts = (build()['accounts'] as List).cast<Map<String, dynamic>>();
expect(accounts.map((a) => a['id']), [alice.id, bob.id]);
expect(
accounts[0]['authHeader'],
ShareAccountService.basicAuth('alice', 's3cret'),
);
expect(accounts[0]['displayName'], 'alice@cloud.example.com');
expect(accounts[0]['hiddenFilter'], 'include');
expect(accounts[0]['storageScope'], 'all');
// The display name uses the host only - not the port or sub-path.
expect(accounts[1]['displayName'], 'bob@nc.home.lan');
expect(accounts[1]['serverUrl'], 'https://nc.home.lan:8443/nextcloud');
expect(accounts[1]['hiddenFilter'], 'hide');
expect(accounts[1]['storageScope'], 'cloud');
});
test('the active account and the lock settings are passed through', () {
final payload = build(login: true, switching: false, hidden: true);
expect(payload['activeId'], 'nc_home_lan__bob');
expect(payload['loginLockEnabled'], true);
expect(payload['lockAccountSwitching'], false);
expect(payload['lockHiddenFiles'], true);
});
test('no active account is a null activeId, not a missing key', () {
expect(build(activeId: null).containsKey('activeId'), true);
expect(build(activeId: null)['activeId'], isNull);
});
}