Files
imagefind/mobile/test/api_contract_test.dart
T
2026-08-18 01:07:44 +08:00

44 lines
1.2 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:imagefind_mobile/src/api.dart';
import 'package:imagefind_mobile/src/models.dart';
void main() {
test('resume plan skips received chunks and keeps the short final chunk', () {
final chunks = pendingUploadChunks(
sizeBytes: 10,
chunkSize: 4,
received: {1},
);
expect(chunks.map((item) => item.index), [0, 2]);
expect(chunks.map((item) => item.offset), [0, 8]);
expect(chunks.map((item) => item.length), [4, 2]);
});
test('SSE decoder ignores keep-alives and accepts split packets', () async {
final bytes = Stream<List<int>>.fromIterable([
utf8.encode(': keep-alive\n\ndata: {"type":"upload"'),
utf8.encode(',"id":"42"}\n\n'),
]);
final events = await decodeServerEvents(bytes).toList();
expect(events, [
{'type': 'upload', 'id': '42'},
]);
});
test('video payload keeps the dedicated download endpoint', () {
final video = VideoRecord.fromJson({
'id': 'video-1',
'title': '片段',
'duration_ms': 1000,
'download_url': '/api/v1/videos/video-1/download',
});
expect(video.downloadUrl, '/api/v1/videos/video-1/download');
});
}