Skip to content

Commit c51727d

Browse files
committed
realtime response connected test
1 parent 95c263d commit c51727d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/SDK/Language/Flutter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ public function getFiles(): array
280280
'destination' => '/test/src/interceptor_test.dart',
281281
'template' => 'flutter/test/src/interceptor_test.dart.twig',
282282
],
283+
[
284+
'scope' => 'default',
285+
'destination' => '/test/src/realtime_response_connected_test.dart',
286+
'template' => 'flutter/test/src/realtime_response_connected_test.dart.twig',
287+
],
283288
[
284289
'scope' => 'default',
285290
'destination' => '/test/src/enums_test.dart',
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'dart:convert';
2+
import 'package:flutter/foundation.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:{{lang.params.packageName}}/src/realtime_response_connected.dart';
5+
6+
void main() {
7+
group('RealtimeResponseConnected', () {
8+
final channels = ['channel1', 'channel2'];
9+
final user = {'id': 123, 'name': 'John Doe'};
10+
final response1 = RealtimeResponseConnected(channels: channels, user: user);
11+
12+
test('copyWith should create a new instance with updated properties', () {
13+
final newChannels = ['channel3', 'channel4'];
14+
final newUser = {'id': 456, 'name': 'Jane Smith'};
15+
16+
final updatedResponse = response1.copyWith(channels: newChannels, user: newUser);
17+
18+
expect(updatedResponse.channels, equals(newChannels));
19+
expect(updatedResponse.user, equals(newUser));
20+
});
21+
22+
test('toMap should return a map representation of the response', () {
23+
final responseMap = response1.toMap();
24+
25+
expect(responseMap['channels'], equals(channels));
26+
expect(responseMap['user'], equals(user));
27+
});
28+
29+
test('fromMap should create an instance from a map', () {
30+
final responseMap = {'channels': channels, 'user': user};
31+
32+
final response2 = RealtimeResponseConnected.fromMap(responseMap);
33+
34+
expect(response2.channels, equals(channels));
35+
expect(response2.user, equals(user));
36+
});
37+
38+
test('toJson and fromJson should convert to/from JSON', () {
39+
final jsonString = response1.toJson();
40+
41+
final response3 = RealtimeResponseConnected.fromJson(jsonString);
42+
43+
expect(response3.channels, equals(channels));
44+
expect(response3.user, equals(user));
45+
});
46+
47+
test('toString should return a string representation of the response', () {
48+
final responseString = response1.toString();
49+
50+
expect(responseString, equals('RealtimeResponseConnected(channels: $channels, user: $user)'));
51+
});
52+
53+
test('equality operator should compare two instances', () {
54+
final response2 = RealtimeResponseConnected(channels: channels, user: user);
55+
56+
expect(response1 == response2, isTrue);
57+
});
58+
59+
test('hashCode should return a unique hash value', () {
60+
final hashCode1 = response1.hashCode;
61+
62+
final response2 = RealtimeResponseConnected(channels: channels, user: user);
63+
final hashCode2 = response2.hashCode;
64+
65+
expect(hashCode1, equals(hashCode2));
66+
});
67+
});
68+
}

0 commit comments

Comments
 (0)