|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:taskwarrior/app/utils/taskc/response.dart'; |
| 3 | +import 'package:taskwarrior/app/utils/taskc/payload.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group('Response', () { |
| 7 | + test('should create Response instance with header and payload', () { |
| 8 | + final payload = Payload(tasks: ['task1', 'task2'], userKey: 'userKey123'); |
| 9 | + final header = {'type': 'response', 'version': '1.0'}; |
| 10 | + final response = Response(header: header, payload: payload); |
| 11 | + |
| 12 | + expect(response.header, header); |
| 13 | + expect(response.payload, payload); |
| 14 | + }); |
| 15 | + |
| 16 | + test('should create Response instance from string', () { |
| 17 | + const responseString = |
| 18 | + 'type: response\nversion: 1.0\n\n' 'task1\ntask2\nuserKey123'; |
| 19 | + final response = Response.fromString(responseString); |
| 20 | + |
| 21 | + expect(response.header, { |
| 22 | + 'type': 'response', |
| 23 | + 'version': '1.0', |
| 24 | + }); |
| 25 | + expect(response.payload.tasks, ['task1', 'task2']); |
| 26 | + expect(response.payload.userKey, 'userKey123'); |
| 27 | + }); |
| 28 | + |
| 29 | + test('should handle Response.fromString with missing payload', () { |
| 30 | + const responseString = 'type: response\nversion: 1.0\n\n'; |
| 31 | + final response = Response.fromString(responseString); |
| 32 | + |
| 33 | + expect(response.header, { |
| 34 | + 'type': 'response', |
| 35 | + 'version': '1.0', |
| 36 | + }); |
| 37 | + expect(response.payload.tasks, []); |
| 38 | + expect(response.payload.userKey, ''); |
| 39 | + }); |
| 40 | + |
| 41 | + test('should handle Response.fromString with complex header', () { |
| 42 | + const responseString = 'type: response\nversion: 1.0\nextra: info\n\n' |
| 43 | + 'task1\ntask2\nuserKey123'; |
| 44 | + final response = Response.fromString(responseString); |
| 45 | + |
| 46 | + expect(response.header, { |
| 47 | + 'type': 'response', |
| 48 | + 'version': '1.0', |
| 49 | + 'extra': 'info', |
| 50 | + }); |
| 51 | + expect(response.payload.tasks, ['task1', 'task2']); |
| 52 | + expect(response.payload.userKey, 'userKey123'); |
| 53 | + }); |
| 54 | + |
| 55 | + test('should handle Response.fromString with empty header', () { |
| 56 | + const responseString = '\n\n' 'task1\ntask2\nuserKey123'; |
| 57 | + final response = Response.fromString(responseString); |
| 58 | + |
| 59 | + expect(response.header, {'': ''}); |
| 60 | + expect(response.payload.tasks, ['task1', 'task2']); |
| 61 | + expect(response.payload.userKey, 'userKey123'); |
| 62 | + }); |
| 63 | + }); |
| 64 | +} |
0 commit comments