Skip to content

Commit f814d58

Browse files
committed
test: add local storage test get text file
1 parent f8c8907 commit f814d58

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

tests/e2e/local-driver.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Test } from '@nestjs/testing';
33
import { AppModule } from '../src/app.module';
44
import { StorageService } from '../../lib';
55

6-
describe('local driver', async () => {
7-
let app: INestApplication;
8-
let storageService;
6+
describe('local driver', () => {
7+
let app: INestApplication, storageService: StorageService;
8+
9+
const fileName = 'local_test.txt',
10+
fileContent = 'hi local storage test';
911

1012
beforeEach(async () => {
1113
const moduleRef = await Test.createTestingModule({
@@ -20,7 +22,14 @@ describe('local driver', async () => {
2022
storageService = app.get<StorageService>(StorageService);
2123
});
2224

23-
it(`put `);
25+
it(`put text`, async () => {
26+
await storageService.getDisk().put(`tests/data/${fileName}`, fileContent);
27+
});
28+
29+
it(`get text file`, async () => {
30+
const res = await storageService.getDisk().get(`tests/data/${fileName}`);
31+
expect(res.raw).toEqual(fileContent);
32+
});
2433

2534
afterEach(async () => {
2635
await app.close();

tests/src/app.module.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import { DynamicModule, Module } from '@nestjs/common';
22

3-
import { StorageModule } from '../../lib';
3+
import { DriverType, StorageModule } from '../../lib';
44
import { StorageService } from '../../lib/storage.service';
55

66
@Module({})
77
export class AppModule {
8-
constructor(private readonly storageService: StorageService) {
9-
console.log('AppModule constructor', storageService);
10-
}
8+
constructor(private readonly storageService: StorageService) {}
119

1210
static withLocalStorage(): DynamicModule {
13-
console.log('withLocalStorage');
1411
return {
1512
module: AppModule,
1613
imports: [
1714
StorageModule.forRoot({
1815
default: 'local',
1916
disks: {
2017
local: {
21-
driver: 'local',
18+
driver: DriverType.LOCAL,
2219
config: {
2320
root: process.cwd(),
2421
},
@@ -28,4 +25,21 @@ export class AppModule {
2825
],
2926
};
3027
}
28+
29+
static withS3Storage(): DynamicModule {
30+
return {
31+
module: AppModule,
32+
imports: [
33+
StorageModule.forRoot({
34+
default: 's3',
35+
disks: {
36+
s3: {
37+
driver: DriverType.S3,
38+
config: {},
39+
},
40+
},
41+
}),
42+
],
43+
};
44+
}
3145
}

0 commit comments

Comments
 (0)