Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 40e5c58

Browse files
authored
added tests for scene-upload (#9449)
* added tests for scene-upload * added license comment * cleanup after test * remove the project after test
1 parent 804e6f0 commit 40e5c58

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
CPAL-1.0 License
3+
4+
The contents of this file are subject to the Common Public Attribution License
5+
Version 1.0. (the "License"); you may not use this file except in compliance
6+
with the License. You may obtain a copy of the License at
7+
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
8+
The License is based on the Mozilla Public License Version 1.1, but Sections 14
9+
and 15 have been added to cover use of software over a computer network and
10+
provide for limited attribution for the Original Developer. In addition,
11+
Exhibit A has been modified to be consistent with Exhibit B.
12+
13+
Software distributed under the License is distributed on an "AS IS" basis,
14+
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
15+
specific language governing rights and limitations under the License.
16+
17+
The Original Code is Ethereal Engine.
18+
19+
The Original Developer is the Initial Developer. The Initial Developer of the
20+
Original Code is the Ethereal Engine team.
21+
22+
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
23+
Ethereal Engine. All Rights Reserved.
24+
*/
25+
26+
import { parseStorageProviderURLs } from '@etherealengine/engine/src/common/functions/parseSceneJSON'
27+
import { destroyEngine } from '@etherealengine/engine/src/ecs/classes/Engine'
28+
import { ProjectType, projectPath } from '@etherealengine/engine/src/schemas/projects/project.schema'
29+
import { sceneUploadPath } from '@etherealengine/engine/src/schemas/projects/scene-upload.schema'
30+
import { SceneJsonType, scenePath } from '@etherealengine/engine/src/schemas/projects/scene.schema'
31+
import { ScopeType } from '@etherealengine/engine/src/schemas/scope/scope.schema'
32+
import { avatarPath } from '@etherealengine/engine/src/schemas/user/avatar.schema'
33+
import { UserApiKeyType, userApiKeyPath } from '@etherealengine/engine/src/schemas/user/user-api-key.schema'
34+
import { UserName, userPath } from '@etherealengine/engine/src/schemas/user/user.schema'
35+
import defaultSceneSeed from '@etherealengine/projects/default-project/default.scene.json'
36+
import assert from 'assert'
37+
import { v1 } from 'uuid'
38+
import { Application } from '../../../declarations'
39+
import { createFeathersKoaApp } from '../../createApp'
40+
41+
describe('scene-upload.test', () => {
42+
let app: Application
43+
let projectName: string
44+
let testUserApiKey: UserApiKeyType
45+
46+
before(async () => {
47+
app = createFeathersKoaApp()
48+
await app.setup()
49+
})
50+
51+
before(async () => {
52+
projectName = `test-scene-project-${v1()}`
53+
await app.service(projectPath).create({ name: projectName })
54+
55+
const name = ('test-scene-upload-user-name-' + v1()) as UserName
56+
const avatarName = 'test-scene-upload-avatar-name-' + v1()
57+
58+
const avatar = await app.service(avatarPath).create({
59+
name: avatarName
60+
})
61+
62+
const testUser = await app.service(userPath).create({
63+
name,
64+
avatarId: avatar.id,
65+
isGuest: false,
66+
scopes: [{ type: 'editor:write' as ScopeType }]
67+
})
68+
69+
testUserApiKey = await app.service(userApiKeyPath).create({ userId: testUser.id })
70+
})
71+
72+
after(async () => {
73+
const foundProjects = (await app
74+
.service(projectPath)
75+
.find({ query: { name: projectName }, paginate: false })) as ProjectType[]
76+
await app.service(projectPath).remove(foundProjects[0].id, { isInternal: true })
77+
await destroyEngine()
78+
})
79+
80+
it('should upload a new scene', async () => {
81+
const sceneName = `test-scene-name-${v1()}`
82+
const sceneData = structuredClone(defaultSceneSeed) as unknown as SceneJsonType
83+
const parsedSceneData = parseStorageProviderURLs(structuredClone(defaultSceneSeed))
84+
85+
await app.service(sceneUploadPath).create(
86+
{ project: projectName, name: sceneName, sceneData },
87+
{
88+
files: [],
89+
provider: 'rest',
90+
headers: {
91+
authorization: `Bearer ${testUserApiKey.token}`
92+
}
93+
}
94+
)
95+
96+
const uploadedSceneData = await app
97+
.service(scenePath)
98+
.get(null, { query: { project: projectName, name: sceneName, metadataOnly: false } })
99+
100+
assert.equal(uploadedSceneData.name, sceneName)
101+
assert.equal(uploadedSceneData.project, projectName)
102+
assert.deepStrictEqual(uploadedSceneData.scene, parsedSceneData)
103+
})
104+
})

0 commit comments

Comments
 (0)