@gameroom/kit
Version:
Node kit for the Gameroom API
138 lines (133 loc) • 3.47 kB
JavaScript
const { faker } = require('@faker-js/faker'),
chai = require('chai')
const {
models: { Option_Group, Option }
} = require('../../')
const should = chai.should()
let object, option_group_id
describe('Option', () => {
describe('setup', () => {
it('should create objects for relationships', async () => {
let result, error
try {
result = await Option_Group.create({ name: faker.random.word() })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
option_group_id = result.id
})
})
describe('Option.create()', () => {
it('should create an option', async () => {
let result, error
try {
result = await Option.create({ name: faker.random.word(), option_group_id })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Option.get()', () => {
it('should get array of options', async () => {
let result, error
try {
result = await Option.get()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
})
})
describe('Option.getAll()', () => {
it('should get array of all options', async () => {
let result, error
try {
result = await Option.getAll()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
})
})
describe('Option.find()', () => {
it('should find an option', async () => {
let result, error
try {
result = await Option.find(object, { view: 'full' })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Option keys', () => {
it('should match api and kit keys', async () => {
const raw = await Option.schema.adapter.find(Option.schema, object.id)
Object.keys(new Option()).sort().should.deep.equal(Object.keys(raw).sort())
})
})
describe('Option.update()', () => {
it('should update an option', async () => {
let result, error
object.name = faker.random.word()
try {
result = await Option.update(object)
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
})
})
describe('option.save()', () => {
it('should update one option', async () => {
let result, error
try {
result = await object.save()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
})
})
describe('Option.delete()', () => {
it('should delete one option', async () => {
let result, error
try {
result = await Option.delete(object)
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
})
})
describe('teardown', () => {
it('should delete the relationship object', async () => {
let error
try {
await Option_Group.delete(option_group_id)
} catch (err) {
error = err
}
should.not.exist(error)
})
})
})