AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Create Chat class + tests
hunteraraujofb946e3d575e
diff --git a/lib/models/chat.dart b/lib/models/chat.dartindex e69de29bb2..ccc0799fc9 100644--- a/lib/models/chat.dart+++ b/lib/models/chat.dart@@ -0,0 +1,53 @@+import 'package:auto_gpt_flutter_client/models/message_type.dart';++/// Represents a chat message related to a specific task.+class Chat {+ final int id;+ final int taskId;+ final String message;+ final DateTime timestamp;+ final MessageType messageType;++ Chat({+ required this.id,+ required this.taskId,+ required this.message,+ required this.timestamp,+ required this.messageType,+ });++ // Convert a Map (usually from JSON) to a Chat object+ factory Chat.fromMap(Map<String, dynamic> map) {+ return Chat(+ id: map['id'],+ taskId: map['taskId'],+ message: map['message'],+ timestamp: DateTime.parse(map['timestamp']),+ messageType: MessageType.values.firstWhere(+ (e) => e.toString() == 'MessageType.${map['messageType']}'),+ );+ }++ @override+ bool operator ==(Object other) =>+ identical(this, other) ||+ other is Chat &&+ runtimeType == other.runtimeType &&+ id == other.id &&+ taskId == other.taskId &&+ message == other.message &&+ timestamp == other.timestamp &&+ messageType == other.messageType;++ @override+ int get hashCode =>+ id.hashCode ^+ taskId.hashCode ^+ message.hashCode ^+ timestamp.hashCode ^+ messageType.hashCode;++ @override+ String toString() =>+ 'Chat(id: $id, taskId: $taskId, message: $message, timestamp: $timestamp, messageType: $messageType)';+}diff --git a/lib/models/message_type.dart b/lib/models/message_type.dartnew file mode 100644index 0000000000..f860cacfb8--- /dev/null+++ b/lib/models/message_type.dart@@ -0,0 +1,5 @@+/// Enum representing the type of the chat message.+enum MessageType {+ user,+ agent,+}diff --git a/test/chat_test.dart b/test/chat_test.dartnew file mode 100644index 0000000000..8749de8410--- /dev/null+++ b/test/chat_test.dart@@ -0,0 +1,69 @@+import 'package:auto_gpt_flutter_client/models/chat.dart';+import 'package:auto_gpt_flutter_client/models/message_type.dart';+import 'package:flutter_test/flutter_test.dart';++void main() {+ group('Chat', () {+ // Test the properties of the Chat class+ test('Chat properties', () {+ final chat = Chat(+ id: 1,+ taskId: 1,+ message: 'Test Message',+ timestamp: DateTime.now(),+ messageType: MessageType.user);++ expect(chat.id, 1);+ expect(chat.taskId, 1);+ expect(chat.message, 'Test Message');+ expect(chat.messageType, MessageType.user);+ });++ // Test Chat.fromMap method+ test('Chat.fromMap', () {+ final chat = Chat.fromMap({+ 'id': 1,+ 'taskId': 1,+ 'message': 'Test Message',+ 'timestamp': DateTime.now().toString(),+ 'messageType': 'user'+ });++ expect(chat.id, 1);+ expect(chat.taskId, 1);+ expect(chat.message, 'Test Message');+ expect(chat.messageType, MessageType.user);+ });++ // Test that two Chat objects with the same properties are equal+ test('Two chats with same properties are equal', () {+ final chat1 = Chat(+ id: 3,+ taskId: 3,+ message: 'Same Message',+ timestamp: DateTime.now(),+ messageType: MessageType.agent);+ final chat2 = Chat(+ id: 3,+ taskId: 3,+ message: 'Same Message',+ timestamp: chat1.timestamp,+ messageType: MessageType.agent);++ expect(chat1, chat2);+ });++ // Test that toString() returns a string representation of the Chat+ test('toString returns string representation', () {+ final chat = Chat(+ id: 4,+ taskId: 4,+ message: 'Test toString',+ timestamp: DateTime.now(),+ messageType: MessageType.user);++ expect(chat.toString(),+ 'Chat(id: 4, taskId: 4, message: Test toString, timestamp: ${chat.timestamp}, messageType: MessageType.user)');+ });+ });+}