Skip to content

Commit 28b725d

Browse files
committed
realtime response test
1 parent c51727d commit 28b725d

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-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_test.dart',
286+
'template' => 'flutter/test/src/realtime_response_test.dart.twig',
287+
],
283288
[
284289
'scope' => 'default',
285290
'destination' => '/test/src/realtime_response_connected_test.dart',
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.dart';
5+
6+
void main() {
7+
group('RealtimeResponse', () {
8+
final type = 'event';
9+
final data = {'event': 'message', 'payload': 'Hello, world!'};
10+
final response1 = RealtimeResponse(type: type, data: data);
11+
12+
test('copyWith should create a new instance with updated properties', () {
13+
final newType = 'response';
14+
final newData = {'result': true};
15+
16+
final updatedResponse = response1.copyWith(type: newType, data: newData);
17+
18+
expect(updatedResponse.type, equals(newType));
19+
expect(updatedResponse.data, equals(newData));
20+
});
21+
22+
test('toMap should return a map representation of the response', () {
23+
final responseMap = response1.toMap();
24+
25+
expect(responseMap['type'], equals(type));
26+
expect(responseMap['data'], equals(data));
27+
});
28+
29+
test('fromMap should create an instance from a map', () {
30+
final responseMap = {'type': type, 'data': data};
31+
32+
final response2 = RealtimeResponse.fromMap(responseMap);
33+
34+
expect(response2.type, equals(type));
35+
expect(response2.data, equals(data));
36+
});
37+
38+
test('toJson and fromJson should convert to/from JSON', () {
39+
final jsonString = response1.toJson();
40+
41+
final response3 = RealtimeResponse.fromJson(jsonString);
42+
43+
expect(response3.type, equals(type));
44+
expect(response3.data, equals(data));
45+
});
46+
47+
test('toString should return a string representation of the response', () {
48+
final responseString = response1.toString();
49+
50+
expect(
51+
responseString, equals('RealtimeResponse(type: $type, data: $data)'));
52+
});
53+
54+
test('equality operator should compare two instances', () {
55+
final response2 = RealtimeResponse(type: type, data: data);
56+
57+
expect(response1 == response2, isTrue);
58+
});
59+
60+
test('hashCode should return a unique hash value', () {
61+
final hashCode1 = response1.hashCode;
62+
63+
final response2 = RealtimeResponse(type: type, data: data);
64+
final hashCode2 = response2.hashCode;
65+
66+
expect(hashCode1, equals(hashCode2));
67+
});
68+
});
69+
}

0 commit comments

Comments
 (0)