file upload actor
This commit is contained in:
parent
fca846eb43
commit
f55083ea1b
6 changed files with 682 additions and 0 deletions
51
test/file_upload_integration_test.dart
Normal file
51
test/file_upload_integration_test.dart
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
@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/'));
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue