@@ -25,19 +25,10 @@ Ethereal Engine. All Rights Reserved.
25
25
26
26
import appRootPath from 'app-root-path'
27
27
import assert from 'assert'
28
- import fs from 'fs'
29
28
import path from 'path'
30
29
31
- import { destroyEngine } from '@etherealengine/engine/src/ecs/classes/Engine'
32
-
33
- import { StaticResourceType , staticResourcePath } from '@etherealengine/engine/src/schemas/media/static-resource.schema'
34
- import { Paginated } from '@feathersjs/feathers'
35
- import { Application } from '../../../declarations'
36
30
import { mockFetch , restoreFetch } from '../../../tests/util/mockFetch'
37
- import { createFeathersKoaApp } from '../../createApp'
38
- import { getCachedURL } from '../storageprovider/getCachedURL'
39
- import { getStorageProvider } from '../storageprovider/storageprovider'
40
- import { addAssetFromProject , downloadResourceAndMetadata } from './static-resource-helper'
31
+ import { downloadResourceAndMetadata } from './static-resource-helper'
41
32
42
33
describe ( 'static-resource-helper' , ( ) => {
43
34
before ( ( ) => {
@@ -91,201 +82,3 @@ describe('static-resource-helper', () => {
91
82
} )
92
83
} )
93
84
} )
94
-
95
- const testProject = 'test-project'
96
-
97
- describe ( 'audio-upload' , ( ) => {
98
- let app : Application
99
-
100
- before ( async ( ) => {
101
- app = createFeathersKoaApp ( )
102
- await app . setup ( )
103
- const url = 'https://test.com/projects/default-project/assets/test.mp3'
104
- const url2 = getCachedURL ( '/projects/default-project/assets/test.mp3' , getStorageProvider ( ) . cacheDomain )
105
- mockFetch ( {
106
- [ url ] : {
107
- contentType : 'audio/mpeg' ,
108
- response : fs . readFileSync (
109
- path . join ( appRootPath . path , '/packages/projects/default-project/assets/SampleAudio.mp3' )
110
- )
111
- } ,
112
- [ url2 ] : {
113
- contentType : 'audio/mpeg' ,
114
- response : fs . readFileSync (
115
- path . join ( appRootPath . path , '/packages/projects/default-project/assets/SampleAudio.mp3' )
116
- )
117
- }
118
- } )
119
- } )
120
-
121
- afterEach ( async ( ) => {
122
- const storageProvider = getStorageProvider ( )
123
- if ( await storageProvider . doesExist ( 'test.mp3' , 'static-resources/test-project/' ) )
124
- await storageProvider . deleteResources ( [ 'static-resources/test-project/test.mp3' ] )
125
-
126
- const existingResource = ( await app . service ( staticResourcePath ) . find ( {
127
- query : {
128
- mimeType : 'audio/mpeg'
129
- } ,
130
- paginate : false
131
- } ) ) as StaticResourceType [ ]
132
- await Promise . all ( existingResource . map ( ( resource ) => app . service ( staticResourcePath ) . remove ( resource . id ) ) )
133
- } )
134
-
135
- after ( ( ) => {
136
- restoreFetch ( )
137
- return destroyEngine ( )
138
- } )
139
-
140
- describe ( 'addAssetFromProject' , ( ) => {
141
- it ( 'should download audio asset as a new static resource from external url when forced to download' , async ( ) => {
142
- const storageProvider = getStorageProvider ( )
143
- const url = 'https://test.com/projects/default-project/assets/test.mp3'
144
-
145
- const staticResource = await addAssetFromProject ( app , url , testProject , true )
146
-
147
- assert ( staticResource . id )
148
- assert . equal ( staticResource . url , getCachedURL ( staticResource . key ! , storageProvider . cacheDomain ) )
149
- assert . equal ( staticResource . key , 'static-resources/test-project/test.mp3' )
150
- assert . equal ( staticResource . mimeType , 'audio/mpeg' )
151
- assert . equal ( staticResource . project , testProject )
152
-
153
- assert ( await storageProvider . doesExist ( 'test.mp3' , 'static-resources/test-project/' ) )
154
-
155
- const file = await storageProvider . getObject ( staticResource . key ! )
156
- assert . equal ( file . ContentType , 'audio/mpeg' )
157
- } )
158
-
159
- it ( 'should link audio asset as a new static resource from external url when not forced to download' , async ( ) => {
160
- const storageProvider = getStorageProvider ( )
161
- const url = 'https://test.com/projects/default-project/assets/test.mp3'
162
-
163
- const staticResource = await addAssetFromProject ( app , url , testProject , false )
164
-
165
- assert ( staticResource . id )
166
- assert . equal ( staticResource . url , 'https://test.com/projects/default-project/assets/test.mp3' )
167
- assert . equal ( staticResource . key , 'https://test.com/projects/default-project/assets/test.mp3' )
168
- assert . equal ( staticResource . mimeType , 'audio/mpeg' )
169
- assert . equal ( staticResource . project , testProject )
170
-
171
- const fileExists = await storageProvider . doesExist ( 'test.mp3' , 'static-resources/test-project/' )
172
- assert ( ! fileExists )
173
- } )
174
-
175
- it ( 'should download audio asset as a new static resource from another project' , async ( ) => {
176
- const storageProvider = getStorageProvider ( )
177
- const url = getCachedURL ( '/projects/default-project/assets/test.mp3' , storageProvider . cacheDomain )
178
-
179
- const staticResource = await addAssetFromProject ( app , url , testProject , true )
180
-
181
- assert . equal ( staticResource . key , 'static-resources/test-project/test.mp3' )
182
- assert . equal ( staticResource . url , getCachedURL ( staticResource . key ! , storageProvider . cacheDomain ) )
183
- assert . equal ( staticResource . mimeType , 'audio/mpeg' )
184
- assert . equal ( staticResource . project , testProject )
185
-
186
- assert ( await storageProvider . doesExist ( 'test.mp3' , 'static-resources/test-project/' ) )
187
-
188
- const file = await storageProvider . getObject ( staticResource . key ! )
189
- assert . equal ( file . ContentType , 'audio/mpeg' )
190
- } )
191
-
192
- it ( 'should link audio asset as a new static resource from another project' , async ( ) => {
193
- const storageProvider = getStorageProvider ( )
194
- const url = getCachedURL ( '/projects/default-project/assets/test.mp3' , storageProvider . cacheDomain )
195
-
196
- const staticResource = await addAssetFromProject ( app , url , testProject , false )
197
-
198
- assert . equal ( staticResource . key , url )
199
- assert . equal ( staticResource . url , url )
200
- assert . equal ( staticResource . mimeType , 'audio/mpeg' )
201
- assert . equal ( staticResource . project , testProject )
202
-
203
- // should not exist under static resources
204
- const fileExists = await storageProvider . doesExist ( 'test.mp3' , 'static-resources/test-project/' )
205
- assert ( ! fileExists )
206
- } )
207
-
208
- it ( 'should link audio asset as a new static resource from url if from the same project' , async ( ) => {
209
- const storageProvider = getStorageProvider ( )
210
- const url = getCachedURL ( '/projects/default-project/assets/test.mp3' , storageProvider . cacheDomain )
211
-
212
- const staticResource = await addAssetFromProject ( app , url , 'default-project' , false )
213
-
214
- assert . equal ( staticResource . key , 'projects/default-project/assets/test.mp3' )
215
- assert . equal ( staticResource . url , url )
216
- assert . equal ( staticResource . mimeType , 'audio/mpeg' )
217
- assert . equal ( staticResource . project , 'default-project' )
218
-
219
- // should not exist under static resources
220
- const fileExists = await storageProvider . doesExist ( 'test.mp3' , 'static-resources/test-project/' )
221
- assert ( ! fileExists )
222
- } )
223
-
224
- it ( 'should return existing static resource with the same hash and project' , async ( ) => {
225
- const storageProvider = getStorageProvider ( )
226
- const url = getCachedURL ( '/projects/default-project/assets/test.mp3' , storageProvider . cacheDomain )
227
-
228
- const response = await addAssetFromProject ( app , url , 'default-project' , false )
229
- const response2 = await addAssetFromProject ( app , url , 'default-project' , false )
230
-
231
- const staticResources = ( await app . service ( staticResourcePath ) . find ( {
232
- query : {
233
- url
234
- }
235
- } ) ) as Paginated < StaticResourceType >
236
-
237
- assert . equal ( staticResources . data . length , 1 )
238
- assert . equal ( response . id , response2 . id )
239
- assert . equal ( response . url , response2 . url )
240
- assert . equal ( response . key , response2 . key )
241
- } )
242
-
243
- it ( 'should return new static resource with the same hash exists in another project when forcing download' , async ( ) => {
244
- const storageProvider = getStorageProvider ( )
245
- const url = getCachedURL ( '/projects/default-project/assets/test.mp3' , storageProvider . cacheDomain )
246
-
247
- const response = await addAssetFromProject ( app , url , 'default-project' , true )
248
- const response2 = await addAssetFromProject ( app , url , 'test-project' , true )
249
-
250
- const staticResources = ( await app . service ( staticResourcePath ) . find ( {
251
- query : {
252
- url : response . url
253
- }
254
- } ) ) as Paginated < StaticResourceType >
255
- assert . equal ( staticResources . data . length , 1 )
256
-
257
- const staticResources2 = ( await app . service ( staticResourcePath ) . find ( {
258
- query : {
259
- url : response2 . url
260
- }
261
- } ) ) as Paginated < StaticResourceType >
262
- assert . equal ( staticResources2 . data . length , 1 )
263
-
264
- assert . notEqual ( response . id , response2 . id )
265
- assert . notEqual ( response . url , response2 . url )
266
- assert . notEqual ( response . key , response2 . key )
267
- assert . equal ( response . hash , response2 . hash )
268
- } )
269
-
270
- it ( 'should different static resource with the same url and hash if it exists in another project when not forcing download' , async ( ) => {
271
- const storageProvider = getStorageProvider ( )
272
- const url = getCachedURL ( '/projects/default-project/assets/test.mp3' , storageProvider . cacheDomain )
273
-
274
- const response = await addAssetFromProject ( app , url , 'default-project' , false )
275
- const response2 = await addAssetFromProject ( app , url , 'test-project' , false )
276
-
277
- const staticResources = ( await app . service ( staticResourcePath ) . find ( {
278
- query : {
279
- url : response . url
280
- }
281
- } ) ) as Paginated < StaticResourceType >
282
- assert . equal ( staticResources . data . length , 2 )
283
-
284
- assert ( response . id !== response2 . id )
285
- assert . equal ( response . url , response2 . url )
286
- // key is different as it is a different project
287
- assert . notEqual ( response . key , response2 . key )
288
- assert . equal ( response . hash , response2 . hash )
289
- } )
290
- } )
291
- } )
0 commit comments