frindlymap/test/visibility_service_test.dart

84 lines
3.8 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 'package:friendly_map/modules/visibility/visibility.dart';
import 'support/app_device.dart';
const pa = '+821011112222';
const pb = '+821022223333';
/// 가가 친구를 추가하고(필요하면 관계를 이어 두고) 개인 명함을 고친 뒤, 나가 수락하면 기본 공유로 가는 명함.
Future<(AppDevice, AppDevice)> scenario({String? relation}) async {
final hub = MemoryHub();
final a = await AppDevice.create(hub, '010-1111-2222', pa, '가');
final b = await AppDevice.create(hub, '010-2222-3333', pb, '나');
final person = (await a.app.friends.add(b.phone, b.name))!;
if (relation != null) await a.app.network.addLink(person.id, relation, '시험');
final mine = (await a.app.cards.mine()).firstWhere((c) => c.kind == CardKinds.personal);
await a.app.cards.edit(mine.id, fields: {
CardKeys.name: '가',
CardKeys.phone: '010-1234-5678',
CardKeys.birthday: '03-14',
CardKeys.company: '한빛',
});
await AppDevice.settleAll();
await b.app.friends.accept(a.phone);
await AppDevice.settleAll();
return (a, b);
}
Future<Map<String, String>> received(AppDevice b, AppDevice a) async {
final aPerson = (await b.app.friends.people()).firstWhere((p) => p.phone == a.phone);
final got = await b.app.network.receivedCards(aPerson.id);
return decodeFields(got.first.fieldsJson);
}
void main() {
test('관계를 모르는 친구에게는 내가 고른 그대로 간다', () async {
final (a, b) = await scenario();
final got = await received(b, a);
expect(got[CardKeys.phone], '010-1234-5678');
expect(got[CardKeys.birthday], '03-14');
});
test('그룹 관계인 친구에게는 생일·연락처·회사가 가지 않는다', () async {
final (a, b) = await scenario(relation: '같은 모임');
final got = await received(b, a);
expect(got[CardKeys.name], '가');
expect(got.containsKey(CardKeys.phone), false);
expect(got.containsKey(CardKeys.birthday), false);
expect(got.containsKey(CardKeys.company), false);
});
test('가족 관계인 친구에게는 전부 간다', () async {
final (a, b) = await scenario(relation: '가족:동생');
final got = await received(b, a);
expect(got[CardKeys.phone], '010-1234-5678');
expect(got[CardKeys.birthday], '03-14');
});
test('표의 칸을 돌리면 저장되고, 처음으로 되돌릴 수 있다', () async {
final (a, _) = await scenario();
expect((await a.app.visibility.matrix()).get(VCategory.birthday, VAudience.group), VLevel.hidden);
final after = await a.app.visibility.cycle(VCategory.birthday, VAudience.group);
expect(after.get(VCategory.birthday, VAudience.group), VLevel.open);
expect((await a.app.visibility.matrix()).get(VCategory.birthday, VAudience.group), VLevel.open);
await a.app.visibility.reset();
expect((await a.app.visibility.matrix()).get(VCategory.birthday, VAudience.group), VLevel.hidden);
});
test('표를 고쳐도 이미 보낸 명함은 "다시 보내기" 전까지 그대로, 다시 보내면 새 표가 적용', () async {
final (a, b) = await scenario(relation: '같은 모임');
await a.app.visibility.cycle(VCategory.contact, VAudience.group); // 숨김 → 공개
await AppDevice.settleAll();
expect((await received(b, a)).containsKey(CardKeys.phone), false);
final mine = (await a.app.cards.mine()).firstWhere((c) => c.kind == CardKinds.personal);
final share = (await a.app.cards.sharesOf(mine.id)).single;
expect(await a.app.cards.resend(share.id), true);
await AppDevice.settleAll();
expect((await received(b, a))[CardKeys.phone], '010-1234-5678');
});
}