Skip to content

Commit 790c6fd

Browse files
committed
input file test
1 parent bb0826c commit 790c6fd

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/SDK/Language/Dart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ public function getFiles(): array
446446
'destination' => '/test/src/exception_test.dart',
447447
'template' => 'dart/test/src/exception_test.dart.twig',
448448
],
449+
[
450+
'scope' => 'default',
451+
'destination' => '/test/src/input_file_test.dart',
452+
'template' => 'dart/test/src/input_file_test.dart.twig',
453+
],
449454
[
450455
'scope' => 'default',
451456
'destination' => '/test/src/response_test.dart',

src/SDK/Language/Flutter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ public function getFiles(): array
305305
'destination' => '/test/src/upload_progress_test.dart',
306306
'template' => 'dart/test/src/upload_progress_test.dart.twig',
307307
],
308+
[
309+
'scope' => 'default',
310+
'destination' => '/test/src/input_file_test.dart',
311+
'template' => 'dart/test/src/input_file_test.dart.twig',
312+
],
308313
[
309314
'scope' => 'default',
310315
'destination' => '/test/src/exception_test.dart',
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{% if 'dart' in language.params.packageName %}
2+
import 'package:test/test.dart';
3+
{% else %}
4+
import 'package:flutter_test/flutter_test.dart';
5+
{% endif %}
6+
import 'package:{{language.params.packageName}}/src/exception.dart';
7+
import 'package:{{language.params.packageName}}/src/input_file.dart';
8+
9+
void main() {
10+
group('InputFile', () {
11+
test('throws exception when neither path nor bytes are provided', () {
12+
expect(
13+
() => InputFile(),
14+
throwsA(isA<{{spec.title | caseUcfirst}}Exception>().having(
15+
(e) => e.message,
16+
'message',
17+
'One of `path` or `bytes` is required',
18+
)),
19+
);
20+
});
21+
22+
test('throws exception when path and bytes are both null', () {
23+
expect(
24+
() => InputFile(path: null, bytes: null),
25+
throwsA(isA<{{spec.title | caseUcfirst}}Exception>().having(
26+
(e) => e.message,
27+
'message',
28+
'One of `path` or `bytes` is required',
29+
)),
30+
);
31+
});
32+
33+
test('creates InputFile from path', () {
34+
final inputFile = InputFile.fromPath(path: '/path/to/file');
35+
36+
expect(inputFile.path, '/path/to/file');
37+
expect(inputFile.filename, isNull);
38+
expect(inputFile.contentType, isNull);
39+
expect(inputFile.bytes, isNull);
40+
});
41+
42+
test('creates InputFile from bytes', () {
43+
final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt');
44+
45+
expect(inputFile.path, isNull);
46+
expect(inputFile.filename, 'file.txt');
47+
expect(inputFile.contentType, isNull);
48+
expect(inputFile.bytes, [1, 2, 3]);
49+
});
50+
});
51+
}

0 commit comments

Comments
 (0)