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

tests: unit tests for instance #7889

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions packages/server-core/src/networking/instance/instance.test.ts
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)
})
})