@gameroom/kit
Version:
Node kit for the Gameroom API
63 lines (58 loc) • 1.74 kB
JavaScript
const { faker } = require('@faker-js/faker'),
chai = require('chai')
const {
models: { Catalog, Location }
} = require('../../')
const should = chai.should()
let catalog, object
describe('Location', () => {
describe('setup', () => {
it('should create objects for relationships', async () => {
let result, error
try {
object = new Location({ accuracy: 5, altitude: 5, altitude_accuracy: 0.5, latitude: 37.4219983, longitude: -122.084 })
result = await Catalog.create({ name: faker.random.word(), location: object })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
catalog = result
})
})
describe('Location.get()', () => {
it('should get array of locations', async () => {
let result, error
try {
result = await Location.get({ filter: { key: 'locatable_id', value: catalog.id } })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
object = result[0]
})
})
describe('Location.find()', () => {
it('should find a location', async () => {
let result, error
try {
result = await Location.find(object)
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Location keys', () => {
it('should match api and kit keys', async () => {
const raw = await Location.schema.adapter.find(Location.schema, object.id)
Object.keys(new Location()).sort().should.deep.equal(Object.keys(raw).sort())
})
})
})