From 8950ab44beacd971734f0b9d21dea77aff2922c4 Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Thu, 31 Aug 2023 14:39:03 -0700 Subject: [PATCH] Implement and Test TaskRequestBody Model This commit adds the TaskRequestBody class, which is designed to encapsulate the request body when creating a new task. The class includes a toJson method for easy serialization to JSON format. Additionally, unit tests have been written to ensure that the TaskRequestBody object is created with the correct values and that it serializes to the expected JSON structure. - Added TaskRequestBody class with input and optional additionalInput fields. - Implemented toJson method for converting an instance of the class to JSON. - Added unit tests to verify both object creation and JSON serialization. These changes provide a standardized way to manage the request body when creating new tasks, improving the overall code quality and maintainability. --- lib/models/task_request_body.dart | 10 ++++++++++ test/task_request_body_test.dart | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 lib/models/task_request_body.dart create mode 100644 test/task_request_body_test.dart diff --git a/lib/models/task_request_body.dart b/lib/models/task_request_body.dart new file mode 100644 index 00000000..294ca8d0 --- /dev/null +++ b/lib/models/task_request_body.dart @@ -0,0 +1,10 @@ +class TaskRequestBody { + final String input; + final Map? additionalInput; + + TaskRequestBody({required this.input, this.additionalInput}); + + Map toJson() { + return {'input': input, 'additional_input': additionalInput}; + } +} diff --git a/test/task_request_body_test.dart b/test/task_request_body_test.dart new file mode 100644 index 00000000..7ac1d61b --- /dev/null +++ b/test/task_request_body_test.dart @@ -0,0 +1,26 @@ +import 'package:auto_gpt_flutter_client/models/task_request_body.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('TaskRequestBody', () { + test('should create TaskRequestBody with correct values', () { + final taskRequestBody = TaskRequestBody( + input: 'Do something', additionalInput: {'key': 'value'}); + + expect(taskRequestBody.input, 'Do something'); + expect(taskRequestBody.additionalInput, {'key': 'value'}); + }); + + test('should convert TaskRequestBody to correct JSON', () { + final taskRequestBody = TaskRequestBody( + input: 'Do something', additionalInput: {'key': 'value'}); + + final json = taskRequestBody.toJson(); + + expect(json, { + 'input': 'Do something', + 'additional_input': {'key': 'value'} + }); + }); + }); +}