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

Commit

Permalink
tests: unit tests for instance (#7889)
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-mitra authored Apr 12, 2023
1 parent 872a7ff commit 6ee0ba1
Showing 1 changed file with 83 additions and 0 deletions.
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)
})
})

0 comments on commit 6ee0ba1

Please sign in to comment.