mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
tests: add chat model tests(cv: 100)
This commit is contained in:
45
test/dashbot/models/chat_action_model_test.dart
Normal file
45
test/dashbot/models/chat_action_model_test.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:apidash/dashbot/core/constants/constants.dart';
|
||||
import 'package:apidash/dashbot/features/chat/models/chat_action.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('ChatAction serialization & defaults', () {
|
||||
test('fromJson (full) -> correct enum mapping', () {
|
||||
final json = {
|
||||
'action': 'apply_openapi',
|
||||
'target': 'documentation',
|
||||
'field': 'spec',
|
||||
'path': '/components/schemas',
|
||||
'value': {'k': 'v'},
|
||||
};
|
||||
final action = ChatAction.fromJson(json);
|
||||
expect(action.actionType, ChatActionType.applyOpenApi);
|
||||
expect(action.targetType, ChatActionTarget.documentation);
|
||||
expect(action.field, 'spec');
|
||||
expect(action.path, '/components/schemas');
|
||||
expect(action.value, {'k': 'v'});
|
||||
});
|
||||
|
||||
test('fromJson (missing fields) -> uses safe defaults', () {
|
||||
final action = ChatAction.fromJson({});
|
||||
expect(action.actionType, ChatActionType.other);
|
||||
expect(action.targetType, ChatActionTarget.httpRequestModel);
|
||||
expect(action.field, '');
|
||||
expect(action.path, isNull);
|
||||
});
|
||||
|
||||
test('toJson produces expected keys & enum strings', () {
|
||||
const action = ChatAction(
|
||||
action: 'download_doc',
|
||||
target: 'documentation',
|
||||
actionType: ChatActionType.downloadDoc,
|
||||
targetType: ChatActionTarget.documentation,
|
||||
);
|
||||
final json = action.toJson();
|
||||
expect(json, containsPair('action', 'download_doc'));
|
||||
expect(json, containsPair('target', 'documentation'));
|
||||
expect(json, containsPair('action_type', 'download_doc'));
|
||||
expect(json, containsPair('target_type', 'documentation'));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user