75 lines
2.0 KiB
Dart
75 lines
2.0 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:ikar/backend/api.dart';
|
|
import 'package:ikar/backend/modules/chat_admin.dart';
|
|
import 'package:ikar/core/cache/info_cache.dart';
|
|
import 'package:ikar/core/protocol/packet.dart';
|
|
|
|
class _PendingApi extends Api {
|
|
int epoch = 1;
|
|
final started = Completer<void>();
|
|
final reply = Completer<Packet>();
|
|
@override
|
|
int get sessionEpoch => epoch;
|
|
@override
|
|
Future<Packet> sendRequest(
|
|
int opcode,
|
|
Map<dynamic, dynamic> payload, {
|
|
bool silent = false,
|
|
void Function()? beforeSend,
|
|
}) {
|
|
beforeSend?.call();
|
|
started.complete();
|
|
return reply.future;
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
ChatInfoFetch.clear();
|
|
});
|
|
test('late chat update cannot populate the next session cache', () async {
|
|
final api = _PendingApi();
|
|
final module = ChatAdminModule(api);
|
|
final pending = module.setOptions(10, {'ALL_CAN_PIN_MESSAGE': true});
|
|
final check = expectLater(pending, throwsStateError);
|
|
await api.started.future;
|
|
api.epoch++;
|
|
api.reply.complete(
|
|
Packet(
|
|
cmd: CmdType.ok,
|
|
opcode: 0,
|
|
payload: {
|
|
'chat': {'id': 10, 'type': 'CHAT', 'owner': 1},
|
|
},
|
|
),
|
|
);
|
|
await check;
|
|
expect(ChatInfoFetch.peek(10), isNull);
|
|
});
|
|
test(
|
|
'reaction fetch does not return settings from a departed session',
|
|
() async {
|
|
final api = _PendingApi();
|
|
final module = ChatAdminModule(api);
|
|
final pending = module.reactionSettingsFor(10);
|
|
await api.started.future;
|
|
api.epoch++;
|
|
api.reply.complete(
|
|
Packet(
|
|
cmd: CmdType.ok,
|
|
opcode: 0,
|
|
payload: {
|
|
'chatReactionsSettings': [
|
|
{'chatId': 10, 'count': 3, 'value': true},
|
|
],
|
|
},
|
|
),
|
|
);
|
|
expect(await pending, isNull);
|
|
},
|
|
);
|
|
}
|