Skip to content

Commit

Permalink
feat(v0.4.0): add tests for readFormData
Browse files Browse the repository at this point in the history
  • Loading branch information
iyifr committed Dec 12, 2024
1 parent 8482a33 commit 26fe57c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/h4_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,41 @@ void main() {
await uploadDir.delete(recursive: true);
}
});

test('Reads normal formdata objects', () async {
router.post('/formdata', (event) async {
var formData = await readFormData(event);
return {
'name': formData.get('name'),
'age': formData.get('age'),
'hobbies': formData.getAll('hobbies'),
'address': {
'street': formData.get('address.street'),
'city': formData.get('address.city')
}
};
});

final formData = dio_form_data.FormData.fromMap({
'name': 'John Doe',
'age': '30',
'hobbies': ['reading', 'gaming', 'coding'],
'address.street': '123 Main St',
'address.city': 'New York'
});

final response = await dio.post('/formdata',
data: formData,
options: Options(
headers: {'content-type': 'multipart/form-data'},
));

var data = json.decode(response.data);

expect(data['name'], equals('John Doe'));
expect(data['age'], equals('30'));
expect(data['hobbies'], containsAll(['reading', 'gaming', 'coding']));
expect(data['address']['street'], equals('123 Main St'));
expect(data['address']['city'], equals('New York'));
});
}

0 comments on commit 26fe57c

Please sign in to comment.