86 lines
2.9 KiB
Dart
86 lines
2.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:payloads_shared/payloads_shared.dart';
|
|
import 'package:bridge_core/bridge_core.dart';
|
|
|
|
void main() {
|
|
group('PingPayload', () {
|
|
test('should create ping payload', () {
|
|
final payload = PingPayload(message: 'test_ping');
|
|
|
|
expect(payload.message, equals('test_ping'));
|
|
expect(payload.type, equals('ping'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = PingPayload(message: 'test_ping');
|
|
final json = original.toJson();
|
|
final deserialized = PingPayload.fromJson(json);
|
|
|
|
expect(deserialized.message, equals(original.message));
|
|
expect(deserialized.type, equals(original.type));
|
|
});
|
|
|
|
test('should create pong response', () {
|
|
final ping = PingPayload(message: 'ping');
|
|
final pong = ping.toPong();
|
|
|
|
expect(pong.message, equals('pong'));
|
|
expect(pong.type, equals('ping'));
|
|
});
|
|
});
|
|
|
|
group('GetUserInfoPayload', () {
|
|
test('should create user info payload', () {
|
|
final payload = GetUserInfoPayload(fields: ['name', 'email']);
|
|
|
|
expect(payload.fields, equals(['name', 'email']));
|
|
expect(payload.type, equals('get_user_info'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = GetUserInfoPayload(fields: ['name', 'email']);
|
|
final json = original.toJson();
|
|
final deserialized = GetUserInfoPayload.fromJson(json);
|
|
|
|
expect(deserialized.fields, equals(original.fields));
|
|
expect(deserialized.type, equals(original.type));
|
|
});
|
|
});
|
|
|
|
group('UserInfoResponsePayload', () {
|
|
test('should create user info response', () {
|
|
final payload = UserInfoResponsePayload(
|
|
userInfo: {'name': 'John', 'email': 'john@example.com'},
|
|
success: true,
|
|
);
|
|
|
|
expect(payload.userInfo, equals({'name': 'John', 'email': 'john@example.com'}));
|
|
expect(payload.success, isTrue);
|
|
expect(payload.type, equals('user_info_response'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = UserInfoResponsePayload(
|
|
userInfo: {'name': 'John'},
|
|
success: true,
|
|
error: null,
|
|
);
|
|
final json = original.toJson();
|
|
final deserialized = UserInfoResponsePayload.fromJson(json);
|
|
|
|
expect(deserialized.userInfo, equals(original.userInfo));
|
|
expect(deserialized.success, equals(original.success));
|
|
expect(deserialized.error, equals(original.error));
|
|
});
|
|
});
|
|
|
|
group('Payload Registration', () {
|
|
test('should register all shared payloads', () {
|
|
registerSharedPayloads();
|
|
|
|
expect(PayloadRegistry.isRegistered('ping'), isTrue);
|
|
expect(PayloadRegistry.isRegistered('get_user_info'), isTrue);
|
|
expect(PayloadRegistry.isRegistered('user_info_response'), isTrue);
|
|
});
|
|
});
|
|
}
|