From c4d08aefb9d913fd88598c9f545682b63649b20e Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Thu, 31 Aug 2023 14:36:35 -0700 Subject: [PATCH] Implement and Test StepRequestBody Model This commit introduces the StepRequestBody class, designed to encapsulate the request body for sending a chat message in the form of a step. The class includes a toJson method for easy serialization to JSON format. Additionally, unit tests have been added to ensure that the StepRequestBody object is created with the correct values and that it serializes to the expected JSON format. - Added StepRequestBody 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 robust way to manage the request body for step-based chat messages. --- lib/models/step_request_body.dart | 10 ++++++++++ test/step_request_body_test.dart | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 lib/models/step_request_body.dart create mode 100644 test/step_request_body_test.dart diff --git a/lib/models/step_request_body.dart b/lib/models/step_request_body.dart new file mode 100644 index 00000000..6f8fb7cb --- /dev/null +++ b/lib/models/step_request_body.dart @@ -0,0 +1,10 @@ +class StepRequestBody { + final String input; + final Map? additionalInput; + + StepRequestBody({required this.input, this.additionalInput}); + + Map toJson() { + return {'input': input, 'additional_input': additionalInput}; + } +} diff --git a/test/step_request_body_test.dart b/test/step_request_body_test.dart new file mode 100644 index 00000000..d15a95f6 --- /dev/null +++ b/test/step_request_body_test.dart @@ -0,0 +1,26 @@ +import 'package:auto_gpt_flutter_client/models/step_request_body.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('StepRequestBody', () { + test('should create StepRequestBody with correct values', () { + final stepRequestBody = StepRequestBody( + input: 'Execute something', additionalInput: {'key': 'value'}); + + expect(stepRequestBody.input, 'Execute something'); + expect(stepRequestBody.additionalInput, {'key': 'value'}); + }); + + test('should convert StepRequestBody to correct JSON', () { + final stepRequestBody = StepRequestBody( + input: 'Execute something', additionalInput: {'key': 'value'}); + + final json = stepRequestBody.toJson(); + + expect(json, { + 'input': 'Execute something', + 'additional_input': {'key': 'value'} + }); + }); + }); +}