Test AttachmentBuilder
This commit is contained in:
parent
7aeef08fb9
commit
15aa62cbe2
|
@ -19,12 +19,8 @@ class AttachmentBuilder {
|
|||
String get attachUrl => "attachment://$_name";
|
||||
|
||||
/// Open file at [path] then read it's contents and prepare to send. Name will be automatically extracted from path if no name provided.
|
||||
factory AttachmentBuilder.path(String path, {String? name, bool? spoiler}) {
|
||||
final bytes = File(path).readAsBytesSync();
|
||||
final fileName = name ?? path_utils.basename(path);
|
||||
|
||||
return AttachmentBuilder._new(bytes, fileName, spoiler);
|
||||
}
|
||||
factory AttachmentBuilder.path(String path, {String? name, bool? spoiler}) =>
|
||||
AttachmentBuilder.file(File(path), name: name, spoiler: spoiler);
|
||||
|
||||
/// Create attachment from specified file instance. Name will be automatically extracted from path if no name provided.
|
||||
factory AttachmentBuilder.file(File file, {String? name, bool? spoiler}) {
|
||||
|
|
|
@ -323,4 +323,29 @@ void main() {
|
|||
expect(role.permissions.raw, PermissionsConstants.sendMessages | PermissionsConstants.readMessageHistory);
|
||||
});
|
||||
});
|
||||
|
||||
group("AttachmentBuilder tests", () {
|
||||
test(".bytes constructor", () {
|
||||
final attachment = AttachmentBuilder.bytes([], "test.txt", spoiler: true);
|
||||
|
||||
expect(attachment.attachUrl, "attachment://SPOILER_test.txt");
|
||||
});
|
||||
|
||||
test(".file constructor", () async {
|
||||
final file = File("/tmp/test.txt");
|
||||
await file.create();
|
||||
final attachment = AttachmentBuilder.file(file, name: "name_for_file.png", spoiler: true);
|
||||
|
||||
expect(attachment.attachUrl, "attachment://SPOILER_name_for_file.png");
|
||||
});
|
||||
|
||||
test(".file constructor", () async {
|
||||
const path = "/tmp/test.txt";
|
||||
final file = File(path);
|
||||
await file.create();
|
||||
final attachment = AttachmentBuilder.path(path);
|
||||
|
||||
expect(attachment.attachUrl, "attachment://test.txt");
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue