63 lines
2.5 KiB
Dart
63 lines
2.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:friendly_map/modules/sharing/sharing.dart';
|
|
import 'package:friendly_map/modules/storage/storage.dart';
|
|
|
|
void main() {
|
|
late Storage s;
|
|
late ShareService svc;
|
|
var now = 100;
|
|
setUp(() async {
|
|
s = Storage.memory();
|
|
now = 100;
|
|
svc = ShareService(s, _TickClock(() => now));
|
|
await s.myCards.put(const MyCard(id: 'c1', kind: 'company', title: '회사', fieldsJson: '{"a":"1"}', updatedAt: 50));
|
|
await s.rooms.put(const ChatRoom(
|
|
id: 'r1', title: '방', kind: 'direct', contextKind: 'personal', membersJson: '[]', updatedAt: 1));
|
|
});
|
|
|
|
test('명함 공유는 그 순간의 내용을 담고, 같은 상대에게 두 번 공유해도 하나', () async {
|
|
final a = (await svc.shareCard('c1', 'p'))!;
|
|
expect(a.snapshot, '{"a":"1"}');
|
|
expect(a.sentVersion, 50);
|
|
expect((await svc.shareCard('c1', 'p'))!.id, a.id);
|
|
expect(await svc.shareCard('없음', 'p'), null);
|
|
});
|
|
|
|
test('고친 뒤에는 다시 보내기 대상이 되고, 다시 보내면 새 내용이 담김', () async {
|
|
final a = (await svc.shareCard('c1', 'p'))!;
|
|
expect(await svc.needingResend(), isEmpty);
|
|
await s.myCards.put(const MyCard(id: 'c1', kind: 'company', title: '회사', fieldsJson: '{"a":"2"}', updatedAt: 80));
|
|
expect((await svc.needingResend()).single.id, a.id);
|
|
now = 200;
|
|
final re = (await svc.resend(a.id))!;
|
|
expect(re.snapshot, '{"a":"2"}');
|
|
expect(re.sentVersion, 80);
|
|
expect(await svc.needingResend(), isEmpty);
|
|
});
|
|
|
|
test('공유를 끝내면 다시 보내기 대상이 아니고 resend 도 안 됨', () async {
|
|
final a = (await svc.shareCard('c1', 'p'))!;
|
|
await svc.stop(a.id);
|
|
expect(await svc.resend(a.id), null);
|
|
expect(await svc.needingResend(), isEmpty);
|
|
});
|
|
|
|
test('대화방 공유와 맥락 규칙 (개인은 명함 없이, 그 밖은 같은 종류 명함 공유 필요)', () async {
|
|
expect((await svc.shareRoom('r1', 'p'))!.unit, 'room');
|
|
expect(await svc.shareRoom('없음', 'p'), null);
|
|
expect(await svc.canStartContextRoom('personal', 'p'), true);
|
|
expect(await svc.canStartContextRoom('company', 'p'), false);
|
|
await svc.shareCard('c1', 'p');
|
|
expect(await svc.canStartContextRoom('company', 'p'), true);
|
|
expect(await svc.canStartContextRoom('company', 'other'), false);
|
|
expect(await svc.canStartContextRoom('school', 'p'), false);
|
|
});
|
|
}
|
|
|
|
class _TickClock extends Clock {
|
|
_TickClock(this._f);
|
|
final int Function() _f;
|
|
@override
|
|
int now() => _f();
|
|
}
|