fix/feat: мелкие фиксы, и доп. инфа в info
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:komet/models/login_info.dart';
|
||||
|
||||
void main() {
|
||||
group('LoginInfo', () {
|
||||
test('extracts profile, packet, chat, and config data', () {
|
||||
final info = LoginInfo.fromPayload({
|
||||
'profile': {
|
||||
'contact': {
|
||||
'id': 100200300,
|
||||
'updateTime': 1700000002000,
|
||||
'registrationTime': 1700000001000,
|
||||
'baseUrl': 'https://example.invalid/avatar',
|
||||
'baseRawUrl': 'https://example.invalid/avatar/raw',
|
||||
'photoId': 400500600,
|
||||
'phone': 70000000000,
|
||||
'names': [
|
||||
{
|
||||
'name': 'Тест Пользователь',
|
||||
'firstName': 'Тест',
|
||||
'lastName': 'Пользователь',
|
||||
'type': 'SYNTHETIC',
|
||||
},
|
||||
],
|
||||
'options': ['SYNTHETIC'],
|
||||
'accountStatus': 2,
|
||||
'country': 'ZZ',
|
||||
},
|
||||
'profileOptions': [7],
|
||||
},
|
||||
'chats': [
|
||||
{
|
||||
'id': -1001,
|
||||
'type': 'CHAT',
|
||||
'status': 'ACTIVE',
|
||||
'lastEventTime': 1700000008000,
|
||||
'newMessages': 3,
|
||||
'messagesCount': 12,
|
||||
},
|
||||
{
|
||||
'id': -1002,
|
||||
'type': 'CHANNEL',
|
||||
'status': 'HIDDEN',
|
||||
'lastEventTime': 1700000007000,
|
||||
},
|
||||
{
|
||||
'id': 1003,
|
||||
'type': 'DIALOG',
|
||||
'status': 'ACTIVE',
|
||||
'lastEventTime': 1700000006000,
|
||||
},
|
||||
],
|
||||
'chatMarker': 1700000009000,
|
||||
'contacts': [
|
||||
{'id': 2001},
|
||||
{'id': 2002},
|
||||
],
|
||||
'presence': {'synthetic-peer': 1700000003000},
|
||||
'messages': {'synthetic-message': {}},
|
||||
'config': {
|
||||
'hash': 'synthetic-config-hash',
|
||||
'server': {
|
||||
'known-flag': true,
|
||||
'nested': {'limit': 4},
|
||||
},
|
||||
'user': {'SYNTHETIC_SETTING': 'ON'},
|
||||
'chats': {
|
||||
'synthetic-chat': {'sound': false},
|
||||
},
|
||||
'experiments': {
|
||||
'synthetic-experiment': {'enabled': true},
|
||||
},
|
||||
},
|
||||
'videoChatHistory': true,
|
||||
'time': 1700000010000,
|
||||
'updates': 4,
|
||||
});
|
||||
|
||||
expect(info['id'], 100200300);
|
||||
expect(info['phone'], 70000000000);
|
||||
expect(info['photoId'], 400500600);
|
||||
expect(info['accountStatus'], 2);
|
||||
expect(info['country'], 'ZZ');
|
||||
expect(info['profileOptions'], [7]);
|
||||
expect(info['contactOptions'], ['SYNTHETIC']);
|
||||
expect(info['chatMarker'], 1700000009000);
|
||||
expect(info['contactsCount'], 2);
|
||||
expect(info['presenceCount'], 1);
|
||||
expect(info['messagesCount'], 1);
|
||||
expect(info['configHash'], 'synthetic-config-hash');
|
||||
expect(info['chats'], {
|
||||
'count': 3,
|
||||
'active': 2,
|
||||
'hidden': 1,
|
||||
'dialogs': 1,
|
||||
'groups': 1,
|
||||
'channels': 1,
|
||||
'unread': 1,
|
||||
'newMessages': 3,
|
||||
'messages': 12,
|
||||
});
|
||||
expect(info['server'], {
|
||||
'known-flag': true,
|
||||
'nested': {'limit': 4},
|
||||
});
|
||||
expect(info['user'], {'SYNTHETIC_SETTING': 'ON'});
|
||||
expect(info['chatSettings'], {
|
||||
'synthetic-chat': {'sound': false},
|
||||
});
|
||||
expect(info['experiments'], {
|
||||
'synthetic-experiment': {'enabled': true},
|
||||
});
|
||||
expect(() => jsonEncode(info), returnsNormally);
|
||||
});
|
||||
|
||||
test('falls back to latest chat event when marker is absent', () {
|
||||
final info = LoginInfo.fromPayload({
|
||||
'chats': [
|
||||
{'lastEventTime': 1700000004000},
|
||||
{'lastEventTime': 1700000006000},
|
||||
{'lastEventTime': 1700000005000},
|
||||
],
|
||||
});
|
||||
|
||||
expect(info['chatMarker'], 1700000006000);
|
||||
expect(info['chats'], {
|
||||
'count': 3,
|
||||
'active': 0,
|
||||
'hidden': 0,
|
||||
'dialogs': 0,
|
||||
'groups': 0,
|
||||
'channels': 0,
|
||||
'unread': 0,
|
||||
'newMessages': 0,
|
||||
'messages': 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -101,18 +101,18 @@ void main() {
|
||||
|
||||
test('message links carry the message id', () {
|
||||
final byName =
|
||||
MaxLink.parse('max.ru/somechannel/117008613873053494')
|
||||
MaxLink.parse('max.ru/somechannel/900000000000000001')
|
||||
as MaxContentLink;
|
||||
expect(byName.kind, MaxContentKind.public);
|
||||
expect(byName.messageId, 117008613873053494);
|
||||
expect(byName.messageId, 900000000000000001);
|
||||
expect(byName.baseUrl, 'https://max.ru/somechannel');
|
||||
|
||||
final byId =
|
||||
MaxLink.parse('max.ru/c/1673760/117008613873053494')
|
||||
MaxLink.parse('max.ru/c/424242/900000000000000001')
|
||||
as MaxContentLink;
|
||||
expect(byId.kind, MaxContentKind.content);
|
||||
expect(byId.messageId, 117008613873053494);
|
||||
expect(byId.baseUrl, 'https://max.ru/c/1673760');
|
||||
expect(byId.messageId, 900000000000000001);
|
||||
expect(byId.baseUrl, 'https://max.ru/c/424242');
|
||||
});
|
||||
|
||||
test('invite, call and sticker links keep their own types', () {
|
||||
@@ -129,12 +129,12 @@ void main() {
|
||||
|
||||
test('uid and cid open a contact and a chat', () {
|
||||
expect(
|
||||
(MaxLink.parse('max://max.ru/?uid=105587131') as MaxContactIdLink)
|
||||
(MaxLink.parse('max://max.ru/?uid=434343') as MaxContactIdLink)
|
||||
.userId,
|
||||
105587131,
|
||||
434343,
|
||||
);
|
||||
final chat = MaxLink.parse('max://max.ru/?cid=1673760') as MaxChatIdLink;
|
||||
expect(chat.chatId, 1673760);
|
||||
final chat = MaxLink.parse('max://max.ru/?cid=424242') as MaxChatIdLink;
|
||||
expect(chat.chatId, 424242);
|
||||
expect(chat.messageId, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user