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.
This commit is contained in:
hunteraraujo
2023-08-31 14:39:03 -07:00
parent c4d08aefb9
commit 8950ab44be
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
class TaskRequestBody {
final String input;
final Map<String, dynamic>? additionalInput;
TaskRequestBody({required this.input, this.additionalInput});
Map<String, dynamic> toJson() {
return {'input': input, 'additional_input': additionalInput};
}
}

View File

@@ -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'}
});
});
});
}