102 lines
4.7 KiB
Dart
102 lines
4.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:friendly_map/modules/app/app.dart';
|
|
import 'package:friendly_map/modules/core/core.dart';
|
|
import 'package:friendly_map/modules/transport/transport.dart';
|
|
|
|
import 'support/app_device.dart';
|
|
|
|
void main() {
|
|
late AppDevice me;
|
|
late GroupService groups;
|
|
|
|
setUp(() async {
|
|
me = await AppDevice.create(MemoryHub(), '010-1111-2222', '+821011112222', '나');
|
|
groups = me.app.groups;
|
|
});
|
|
|
|
/// 시계를 [minutes] 분 앞으로.
|
|
void later(int minutes) => me.app.deps.clock.offset += minutes * 6000;
|
|
|
|
test('그룹 정의: 처음 네 개, 더하고 이름·종류 바꾸고 지우기', () async {
|
|
expect((await groups.all()).map((v) => v.group.name), ['가족', '학교', '회사', '그룹·여행']);
|
|
final g = (await groups.add('등산 모임', CardKinds.group))!;
|
|
expect(await groups.add('등산 모임', CardKinds.group), isNull);
|
|
expect(await groups.rename(g.id, '산악회'), isTrue);
|
|
expect(await groups.setKind(g.id, CardKinds.personal), isTrue);
|
|
final v = (await groups.view(g.id))!;
|
|
expect(v.group.name, '산악회');
|
|
expect(v.group.kind, CardKinds.personal);
|
|
expect(await groups.remove(g.id), isTrue);
|
|
expect(await groups.view(g.id), isNull);
|
|
});
|
|
|
|
test('잠그면 닫힌 동안 구성원을 볼 수 없고, 비밀번호로 열면 보인다', () async {
|
|
final a = (await me.app.friends.add('+821033334444', '김민수'))!;
|
|
expect(await groups.addMembers(CardKinds.family, [a.id]), 1);
|
|
expect(await groups.setPin(CardKinds.family, '123'), isNotNull, reason: '너무 짧음');
|
|
expect(await groups.setPin(CardKinds.family, '2580'), isNull);
|
|
expect((await groups.view(CardKinds.family))!.open, isTrue, reason: '건 직후에는 열려 있다');
|
|
|
|
groups.lock(CardKinds.family);
|
|
final closed = (await groups.view(CardKinds.family))!;
|
|
expect(closed.open, isFalse);
|
|
expect(closed.memberCount, isNull);
|
|
expect(await groups.members(CardKinds.family), isNull);
|
|
expect(await groups.hiddenPeople(), {a.id});
|
|
expect(await groups.groupsOf(a.id), isEmpty);
|
|
expect(await groups.addMembers(CardKinds.family, ['x']), 0, reason: '닫힌 그룹에는 넣을 수 없다');
|
|
expect(await groups.rename(CardKinds.family, '우리 집'), isFalse);
|
|
expect(await groups.remove(CardKinds.family), isFalse);
|
|
|
|
final wrong = await groups.unlock(CardKinds.family, '0000');
|
|
expect(wrong.status, UnlockStatus.wrong);
|
|
expect(wrong.triesLeft, 4);
|
|
expect((await groups.unlock(CardKinds.family, '2580')).status, UnlockStatus.opened);
|
|
expect((await groups.members(CardKinds.family))!.map((p) => p.name), ['김민수']);
|
|
expect(await groups.hiddenPeople(), isEmpty);
|
|
});
|
|
|
|
test('연 뒤 정한 시간이 지나면 다시 잠긴다', () async {
|
|
await groups.setPin(CardKinds.school, 'abcd');
|
|
await groups.setRelockMinutes(3);
|
|
later(2);
|
|
expect((await groups.view(CardKinds.school))!.open, isTrue);
|
|
later(2);
|
|
expect((await groups.view(CardKinds.school))!.open, isFalse);
|
|
expect(await groups.relockMinutes(), 3);
|
|
});
|
|
|
|
test('5번 틀리면 기다려야 하고, 기다리는 동안은 맞는 비밀번호도 안 된다', () async {
|
|
await groups.setPin(CardKinds.company, '9999');
|
|
groups.lockAll();
|
|
for (var i = 0; i < 4; i++) {
|
|
expect((await groups.unlock(CardKinds.company, '1111')).status, UnlockStatus.wrong);
|
|
}
|
|
final r = await groups.unlock(CardKinds.company, '1111');
|
|
expect(r.status, UnlockStatus.waiting);
|
|
expect(r.waitSeconds, 30);
|
|
expect((await groups.unlock(CardKinds.company, '9999')).status, UnlockStatus.waiting);
|
|
later(1);
|
|
expect((await groups.unlock(CardKinds.company, '9999')).status, UnlockStatus.opened);
|
|
});
|
|
|
|
test('비밀번호 바꾸기·풀기는 지금 비밀번호가 맞아야 한다', () async {
|
|
await groups.setPin(CardKinds.group, '1234');
|
|
expect(await groups.setPin(CardKinds.group, '5678', current: '0000'), isNotNull);
|
|
expect(await groups.setPin(CardKinds.group, '5678', current: '1234'), isNull);
|
|
expect(await groups.clearPin(CardKinds.group, '1234'), isNotNull);
|
|
expect(await groups.clearPin(CardKinds.group, '5678'), isNull);
|
|
groups.lockAll();
|
|
expect((await groups.view(CardKinds.group))!.open, isTrue, reason: '푼 그룹은 늘 열려 있다');
|
|
expect((await groups.view(CardKinds.group))!.group.locked, isFalse);
|
|
});
|
|
|
|
test('잠금은 저장되어 앱을 다시 열어도 유지된다 (연 상태는 남지 않음)', () async {
|
|
await groups.setPin(CardKinds.family, '2468');
|
|
final again = GroupService(me.app.deps.storage, me.app.deps.clock, me.app.bus);
|
|
final v = (await again.view(CardKinds.family))!;
|
|
expect(v.group.locked, isTrue);
|
|
expect(v.open, isFalse);
|
|
});
|
|
}
|