addReadyFile method

String addReadyFile({
  1. required String uploaderId,
  2. required String channelId,
  3. required String name,
  4. required String mimeType,
  5. required List<int> bytes,
  6. String scanStatus = 'clean',
  7. String uploadState = 'complete',
})

A file of uploaderId in channelId that is uploaded and checked already, for tests that start with attachments: scanStatus and uploadState set its state (12 2); returns its ID. Attach it with createMessage and attachment_file_ids.

Implementation

String addReadyFile({
  required String uploaderId,
  required String channelId,
  required String name,
  required String mimeType,
  required List<int> bytes,
  String scanStatus = 'clean',
  String uploadState = 'complete',
}) {
  final id = nextId();
  final data = Uint8List.fromList(bytes);
  final f = FakeFile({
    'id': id,
    'sha256': sha256.convert(data).toString(),
    'size_bytes': data.length,
    'mime_type': mimeType,
    'original_name': name,
    'uploaded_by': uploaderId,
    'purpose': 'attachment',
    'scope_channel_id': channelId,
    'upload_state': 'pending',
    'scan_status': 'pending',
    'transcript_status': 'none',
    'thumbnails': <Object?>[],
    'created_at': stamp(),
  });
  f
    ..bytes = data
    ..sessionState = 'completed'
    ..declaredSha256 = f.json['sha256']! as String;
  files[id] = f;
  if (uploadState == 'complete') {
    // A seeded file is not news: only its later changes are events.
    _scanned(f, scanStatus);
  } else {
    f.json['upload_state'] = uploadState;
  }
  return id;
}