41 lines
1.4 KiB
Dart
41 lines
1.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hwhub/services/collection_service.dart';
|
|
|
|
void main() {
|
|
group('Collection role permissions', () {
|
|
Collection collectionWithRole(String role) {
|
|
return Collection(
|
|
id: 'c1',
|
|
name: 'Garage',
|
|
ownerId: 'u1',
|
|
createdAt: DateTime(2026, 1, 1),
|
|
role: role,
|
|
);
|
|
}
|
|
|
|
test('owner and member can modify cars, viewer cannot', () {
|
|
expect(collectionWithRole('owner').canModifyCars, isTrue);
|
|
expect(collectionWithRole('member').canModifyCars, isTrue);
|
|
expect(collectionWithRole('viewer').canModifyCars, isFalse);
|
|
});
|
|
|
|
test('viewer role flag is detected correctly', () {
|
|
expect(collectionWithRole('viewer').isViewer, isTrue);
|
|
expect(collectionWithRole('member').isViewer, isFalse);
|
|
});
|
|
});
|
|
|
|
group('CollectionService invite role validation', () {
|
|
test('normalizes role input', () {
|
|
expect(CollectionService.normalizeRole(' Viewer '), 'viewer');
|
|
expect(CollectionService.normalizeRole('MEMBER'), 'member');
|
|
});
|
|
|
|
test('allows only member and viewer roles', () {
|
|
expect(CollectionService.isSupportedInviteRole('member'), isTrue);
|
|
expect(CollectionService.isSupportedInviteRole('viewer'), isTrue);
|
|
expect(CollectionService.isSupportedInviteRole(' owner '), isFalse);
|
|
expect(CollectionService.isSupportedInviteRole('admin'), isFalse);
|
|
});
|
|
});
|
|
}
|