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';
|
|
|
|
|
|
2026-06-08 12:38:31 +03:00
|
|
|
import 'test_env.dart';
|
|
|
|
|
|
2026-06-08 11:08:00 +03:00
|
|
|
// 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() {
|
2026-06-08 12:38:31 +03:00
|
|
|
final env = loadEnv();
|
|
|
|
|
final appSecret = env['XFAY_APP_SECRET'] ?? '';
|
|
|
|
|
|
2026-06-08 11:08:00 +03:00
|
|
|
late FileUploadActor actor;
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
|
actor = FileUploadActor(
|
|
|
|
|
privateKey: _privKey,
|
|
|
|
|
appName: _kAppName,
|
2026-06-08 12:38:31 +03:00
|
|
|
appSecret: appSecret,
|
2026-06-08 11:08:00 +03:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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/'));
|
|
|
|
|
});
|
|
|
|
|
}
|