swarm/test/file_upload_integration_test.dart
randogoth 3cafc4456c move xfay app secret to .env
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-08 12:38:31 +03:00

52 lines
1.3 KiB
Dart

@Tags(['integration'])
library;
import 'dart:typed_data';
import 'package:swarm/swarm.dart';
import 'package:test/test.dart';
import 'test_env.dart';
// Well-known test key — obviously not a real user key.
const _privKey =
'0000000000000000000000000000000000000000000000000000000000000001';
const _kAppName = 'xfay';
// 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() {
final env = loadEnv();
final appSecret = env['XFAY_APP_SECRET'] ?? '';
late FileUploadActor actor;
setUp(() {
actor = FileUploadActor(
privateKey: _privKey,
appName: _kAppName,
appSecret: appSecret,
);
});
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/'));
});
}