This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: unit tests for instance (#7889)
- Loading branch information
1 parent
872a7ff
commit 6ee0ba1
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
packages/server-core/src/networking/instance/instance.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Paginated } from '@feathersjs/feathers' | ||
import assert from 'assert' | ||
import { v1 } from 'uuid' | ||
|
||
import { Instance } from '@etherealengine/common/src/interfaces/Instance' | ||
import { Location } from '@etherealengine/common/src/interfaces/Location' | ||
import { destroyEngine } from '@etherealengine/engine/src/ecs/classes/Engine' | ||
|
||
import { Application } from '../../../declarations' | ||
import { createFeathersExpressApp } from '../../createApp' | ||
|
||
const params = { isInternal: true } as any | ||
|
||
describe('instance.test', () => { | ||
let app: Application | ||
|
||
before(async () => { | ||
app = createFeathersExpressApp() | ||
await app.setup() | ||
}) | ||
|
||
after(() => { | ||
return destroyEngine() | ||
}) | ||
|
||
let testLocation: Location | ||
let testInstance: Instance | ||
|
||
before(async () => { | ||
const name = `Test Location ${v1()}` | ||
const sceneId = `test-scene-${v1()}` | ||
|
||
const location_settings = await app.service('location-settings').create({}) | ||
|
||
testLocation = await app.service('location').create( | ||
{ | ||
name, | ||
sceneId, | ||
location_settings | ||
}, | ||
params | ||
) | ||
}) | ||
|
||
it('should create an instance', async () => { | ||
const instance = (await app.service('instance').create({ locationId: testLocation.id })) as Instance | ||
|
||
assert.ok(instance) | ||
assert.equal(instance.locationId, testLocation.id) | ||
assert.equal(instance.currentUsers, 0) | ||
assert.equal(instance.ended, false) | ||
|
||
testInstance = instance | ||
}) | ||
|
||
it('should get that instance', async () => { | ||
const instance = await app.service('instance').get(testInstance.id) | ||
|
||
assert.ok(instance) | ||
assert.ok(instance.roomCode) | ||
assert.equal(instance.id, testInstance.id) | ||
}) | ||
|
||
it('should find instances for admin', async () => { | ||
const instances = (await app.service('instance').find({ | ||
action: 'admin' | ||
} as any)) as Paginated<Instance> | ||
|
||
assert.equal(instances.total, 1) | ||
assert.equal(instances.data[0].id, testInstance.id) | ||
}) | ||
|
||
it('should find active instances', async () => { | ||
const activeInstances = await app | ||
.service('instances-active') | ||
.find({ query: { sceneId: testLocation.sceneId }, ...params }) | ||
|
||
assert.equal(activeInstances.length, 1) | ||
assert.equal(activeInstances[0].id, testInstance.id) | ||
assert.equal(activeInstances[0].currentUsers, 0) | ||
assert.equal(activeInstances[0].location, testLocation.id) | ||
}) | ||
}) |