swarm/test/file_upload_integration_test.dart

52 lines
1.3 KiB
Dart
Raw Normal View History

2026-06-08 11:08:00 +03:00
@Tags(['integration'])
library;
import 'dart:typed_data';
import 'package:swarm/swarm.dart';
import 'package:test/test.dart';
// Well-known test key — obviously not a real user key.
const _privKey =
'0000000000000000000000000000000000000000000000000000000000000001';
// Per-app credentials for the xfay app.
// ignore: avoid_hardcoded_credentials (test-only, not a user secret)
const _kAppName = 'xfay';
const _kAppSecret =
'REDACTED';
// Minimal valid JPEG (SOI marker only — enough for R2 to store).
final _kTestBytes = Uint8List.fromList([0xFF, 0xD8, 0xFF, 0xD9]);
const _kContentType = 'image/jpeg';
void main() {
late FileUploadActor actor;
setUp(() {
actor = FileUploadActor(
privateKey: _privKey,
appName: _kAppName,
appSecret: _kAppSecret,
);
});
tearDown(() => actor.close());
test('register publishes kind 5392 to relay without error', () async {
expect(
await actor.handle(const RegisterForUpload()),
isA<UploaderRegistered>(),
);
});
test('upload returns a CDN url under the xfay app path', () async {
final result = await actor.handle(
UploadFile(bytes: _kTestBytes, contentType: _kContentType),
);
expect(result, isA<FileUploaded>());
final url = (result as FileUploaded).cdnUrl;
expect(url, startsWith('https://cdn.otherwhere.app/xfay/'));
});
}