/
ghost-storage-base-tests.ts
45 lines (35 loc) · 1.23 KB
/
ghost-storage-base-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { StorageBase, Image, ReadOptions } from 'ghost-storage-base';
import { Request, Response, NextFunction } from 'express';
class MyCustomAdapter extends StorageBase {
constructor() {
super();
}
async exists(fileName: string, targetDir?: string) {
return true;
}
async save(image: Image, targetDir?: string) {
return 'string';
}
serve() {
return (req: Request, res: Response, next: NextFunction) => next();
}
async delete(fileName: string, targetDir?: string) {
return true;
}
async read(options: ReadOptions) {
return Buffer.from([]);
}
}
const image: Image = {
path: 'tmp/123456.jpg',
name: 'IMAGE.jpg',
type: 'image/jpeg',
};
const storage = new MyCustomAdapter();
storage.getTargetDir('/'); // $ExpectType string
storage.getUniqueFileName(image, '/target'); // $ExpectType string
storage.getSanitizedFileName('IMAGE.jpg'); // $ExpectType string
storage.exists('tmp/123456.jpg', '/'); // $ExpectType Promise<boolean>
storage.save(image, '/'); // $ExpectType Promise<string>
storage.serve(); // $ExpectType (req: Request, res: Response, next: NextFunction) => void
storage.delete('tmp/123456.jpg', '/'); // $ExpectType Promise<boolean>