File tree Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ import { Test } from '@nestjs/testing';
33import { AppModule } from '../src/app.module' ;
44import { 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 ( ) ;
Original file line number Diff line number Diff line change 11import { DynamicModule , Module } from '@nestjs/common' ;
22
3- import { StorageModule } from '../../lib' ;
3+ import { DriverType , StorageModule } from '../../lib' ;
44import { StorageService } from '../../lib/storage.service' ;
55
66@Module ( { } )
77export 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}
You can’t perform that action at this time.
0 commit comments