@@ -3,7 +3,6 @@ const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapte
3
3
. WinstonLoggerAdapter ;
4
4
const GridFSBucketAdapter = require ( '../lib/Adapters/Files/GridFSBucketAdapter' )
5
5
. GridFSBucketAdapter ;
6
- const GridStoreAdapter = require ( '../lib/Adapters/Files/GridStoreAdapter' ) . GridStoreAdapter ;
7
6
const Config = require ( '../lib/Config' ) ;
8
7
const FilesController = require ( '../lib/Controllers/FilesController' ) . default ;
9
8
const databaseURI = 'mongodb://localhost:27017/parse' ;
@@ -24,8 +23,8 @@ const mockAdapter = {
24
23
describe ( 'FilesController' , ( ) => {
25
24
it ( 'should properly expand objects' , done => {
26
25
const config = Config . get ( Parse . applicationId ) ;
27
- const gridStoreAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
28
- const filesController = new FilesController ( gridStoreAdapter ) ;
26
+ const gridFSAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
27
+ const filesController = new FilesController ( gridFSAdapter ) ;
29
28
const result = filesController . expandFilesInObject ( config , function ( ) { } ) ;
30
29
31
30
expect ( result ) . toBeUndefined ( ) ;
@@ -85,19 +84,19 @@ describe('FilesController', () => {
85
84
86
85
it ( 'should add a unique hash to the file name when the preserveFileName option is false' , done => {
87
86
const config = Config . get ( Parse . applicationId ) ;
88
- const gridStoreAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
89
- spyOn ( gridStoreAdapter , 'createFile' ) ;
90
- gridStoreAdapter . createFile . and . returnValue ( Promise . resolve ( ) ) ;
87
+ const gridFSAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
88
+ spyOn ( gridFSAdapter , 'createFile' ) ;
89
+ gridFSAdapter . createFile . and . returnValue ( Promise . resolve ( ) ) ;
91
90
const fileName = 'randomFileName.pdf' ;
92
91
const regexEscapedFileName = fileName . replace ( / \. / g, '\\$&' ) ;
93
- const filesController = new FilesController ( gridStoreAdapter , null , {
92
+ const filesController = new FilesController ( gridFSAdapter , null , {
94
93
preserveFileName : false ,
95
94
} ) ;
96
95
97
96
filesController . createFile ( config , fileName ) ;
98
97
99
- expect ( gridStoreAdapter . createFile ) . toHaveBeenCalledTimes ( 1 ) ;
100
- expect ( gridStoreAdapter . createFile . calls . mostRecent ( ) . args [ 0 ] ) . toMatch (
98
+ expect ( gridFSAdapter . createFile ) . toHaveBeenCalledTimes ( 1 ) ;
99
+ expect ( gridFSAdapter . createFile . calls . mostRecent ( ) . args [ 0 ] ) . toMatch (
101
100
`^.{32}_${ regexEscapedFileName } $`
102
101
) ;
103
102
@@ -106,42 +105,42 @@ describe('FilesController', () => {
106
105
107
106
it ( 'should not add a unique hash to the file name when the preserveFileName option is true' , done => {
108
107
const config = Config . get ( Parse . applicationId ) ;
109
- const gridStoreAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
110
- spyOn ( gridStoreAdapter , 'createFile' ) ;
111
- gridStoreAdapter . createFile . and . returnValue ( Promise . resolve ( ) ) ;
108
+ const gridFSAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
109
+ spyOn ( gridFSAdapter , 'createFile' ) ;
110
+ gridFSAdapter . createFile . and . returnValue ( Promise . resolve ( ) ) ;
112
111
const fileName = 'randomFileName.pdf' ;
113
- const filesController = new FilesController ( gridStoreAdapter , null , {
112
+ const filesController = new FilesController ( gridFSAdapter , null , {
114
113
preserveFileName : true ,
115
114
} ) ;
116
115
117
116
filesController . createFile ( config , fileName ) ;
118
117
119
- expect ( gridStoreAdapter . createFile ) . toHaveBeenCalledTimes ( 1 ) ;
120
- expect ( gridStoreAdapter . createFile . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( fileName ) ;
118
+ expect ( gridFSAdapter . createFile ) . toHaveBeenCalledTimes ( 1 ) ;
119
+ expect ( gridFSAdapter . createFile . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( fileName ) ;
121
120
122
121
done ( ) ;
123
122
} ) ;
124
123
125
124
it ( 'should handle adapter without getMetadata' , async ( ) => {
126
- const gridStoreAdapter = new GridFSBucketAdapter ( databaseURI ) ;
127
- gridStoreAdapter . getMetadata = null ;
128
- const filesController = new FilesController ( gridStoreAdapter ) ;
125
+ const gridFSAdapter = new GridFSBucketAdapter ( databaseURI ) ;
126
+ gridFSAdapter . getMetadata = null ;
127
+ const filesController = new FilesController ( gridFSAdapter ) ;
129
128
130
129
const result = await filesController . getMetadata ( ) ;
131
130
expect ( result ) . toEqual ( { } ) ;
132
131
} ) ;
133
132
134
133
it ( 'should reject slashes in file names' , done => {
135
- const gridStoreAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
134
+ const gridFSAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
136
135
const fileName = 'foo/randomFileName.pdf' ;
137
- expect ( gridStoreAdapter . validateFilename ( fileName ) ) . not . toBe ( null ) ;
136
+ expect ( gridFSAdapter . validateFilename ( fileName ) ) . not . toBe ( null ) ;
138
137
done ( ) ;
139
138
} ) ;
140
139
141
140
it ( 'should also reject slashes in file names' , done => {
142
- const gridStoreAdapter = new GridStoreAdapter ( 'mongodb://localhost:27017/parse' ) ;
141
+ const gridFSAdapter = new GridFSBucketAdapter ( 'mongodb://localhost:27017/parse' ) ;
143
142
const fileName = 'foo/randomFileName.pdf' ;
144
- expect ( gridStoreAdapter . validateFilename ( fileName ) ) . not . toBe ( null ) ;
143
+ expect ( gridFSAdapter . validateFilename ( fileName ) ) . not . toBe ( null ) ;
145
144
done ( ) ;
146
145
} ) ;
147
146
} ) ;
0 commit comments