Skip to content

Commit

Permalink
fix: Reject the handler when the main file of the scene is not presen…
Browse files Browse the repository at this point in the history
…t in the zip
  • Loading branch information
Kevin Szuchet committed Jul 7, 2023
1 parent e747da7 commit acfab8c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/files/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('when loading an item file', () => {
parcels: ['0,0', '0,1', '1,0', '1,1'],
base: '0,0'
},
main: 'scene.json',
main: 'game.js',
requiredPermissions: ['REQUIRED_PERMISSION']
}
zipFile.file(SCENE_MANIFEST, JSON.stringify(sceneFileContent))
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('when loading an item file', () => {
})
})

describe('and the scene config file is correctly formatted', () => {
describe('and the main property of the scene config file is not present in the zipped file', () => {
let sceneFileContent: SceneConfig

beforeEach(() => {
Expand All @@ -341,12 +341,39 @@ describe('when loading an item file', () => {
parcels: ['0,0', '0,1', '1,0', '1,1'],
base: '0,0'
},
main: 'scene.json',
main: 'game.js',
requiredPermissions: ['REQUIRED_PERMISSION']
}
zipFile.file(SCENE_MANIFEST, JSON.stringify(sceneFileContent))
})

it('should throw an error signaling that the scene config file is invalid', () => {
return expect(loadFile(fileName, zipFileContent)).rejects.toThrow(
new InvalidSceneConfigFileError()
)
})
})

describe('and the scene config file is valid and contains the main property in the zipped file', () => {
let sceneFileContent: SceneConfig
let sceneMainFile: string
let sceneMainFileContent: Uint8Array

beforeEach(() => {
sceneMainFile = 'game.js'
sceneMainFileContent = new Uint8Array([0, 1, 2, 3, 4])
sceneFileContent = {
scene: {
parcels: ['0,0', '0,1', '1,0', '1,1'],
base: '0,0'
},
main: sceneMainFile,
requiredPermissions: ['REQUIRED_PERMISSION']
}
zipFile.file(SCENE_MANIFEST, JSON.stringify(sceneFileContent))
zipFile.file(sceneMainFile, sceneMainFileContent)
})

describe('and the zip file is in the Uint8Array format', () => {
beforeEach(async () => {
zipFileContent = await zipFile.generateAsync({
Expand All @@ -361,6 +388,7 @@ describe('when loading an item file', () => {
content: {
[modelFile]: modelFileContent,
[textureFile]: textureFileContent,
[sceneMainFile]: sceneMainFileContent,
[THUMBNAIL_PATH]: thumbnailContent
},
wearable: wearableFileContent,
Expand All @@ -383,6 +411,7 @@ describe('when loading an item file', () => {
content: {
[modelFile]: modelFileContent.buffer,
[textureFile]: textureFileContent.buffer,
[sceneMainFile]: sceneMainFileContent.buffer,
[THUMBNAIL_PATH]: thumbnailContent.buffer
},
wearable: wearableFileContent,
Expand All @@ -405,6 +434,7 @@ describe('when loading an item file', () => {
content: {
[modelFile]: Buffer.from(modelFileContent.buffer),
[textureFile]: Buffer.from(textureFileContent.buffer),
[sceneMainFile]: Buffer.from(sceneMainFileContent.buffer),
[THUMBNAIL_PATH]: Buffer.from(thumbnailContent.buffer)
},
wearable: wearableFileContent,
Expand Down
4 changes: 4 additions & 0 deletions src/files/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ async function handleZippedModelFiles<T extends Content>(
if (sceneZipFile) {
const sceneFileContents = await sceneZipFile.async('uint8array')
scene = await loadSceneConfig(sceneFileContents)

if (!zip.file(scene.main)) {
throw new FileNotFoundError(scene.main)
}
}
}

Expand Down

0 comments on commit acfab8c

Please sign in to comment.