@gameroom/kit
Version:
Node kit for the Gameroom API
171 lines (166 loc) • 4.55 kB
JavaScript
const { faker } = require('@faker-js/faker'),
chai = require('chai')
const {
models: { Option_Group, Option, Product, Unit, Unit_Option }
} = require('../../')
const should = chai.should()
let object, option_group_id, option_id, product_id, unit_id
describe('Unit_Option', () => {
describe('setup', () => {
it('should create objects for relationships', async () => {
let result, error
// option_group
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
// option
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')
option_id = result.id
// product
try {
result = await Product.create({ name: faker.random.word() })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
product_id = result.id
// unit
try {
result = await Unit.create({ name: faker.random.word(), product_id })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
unit_id = result.id
})
})
describe('Unit_Option.create()', () => {
it('should create a unit_option', async () => {
let result, error
try {
result = await Unit_Option.create({ unit_id, option_id })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Unit_Option.get()', () => {
it('should get array of unit_options', async () => {
let result, error
try {
result = await Unit_Option.get()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
})
})
describe('Unit_Option.getAll()', () => {
it('should get array of all unit_options', async () => {
let result, error
try {
result = await Unit_Option.getAll()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
})
})
describe('Unit_Option.find()', () => {
it('should find a unit_option', async () => {
let result, error
try {
result = await Unit_Option.find(object, { view: 'full' })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Unit_Option keys', () => {
it('should match api and kit keys', async () => {
const raw = await Unit_Option.schema.adapter.find(Unit_Option.schema, object.id)
Object.keys(new Unit_Option()).sort().should.deep.equal(Object.keys(raw).sort())
})
})
describe('Unit_Option.update()', () => {
it('should update a unit_option', async () => {
let result, error
try {
result = await Unit_Option.update(object)
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
})
})
describe('unit_option.save()', () => {
it('should update one unit_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('Unit_Option.delete()', () => {
it('should delete one unit_option', async () => {
let result, error
try {
result = await Unit_Option.delete(object)
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
})
})
describe('teardown', () => {
it('should delete the relationship objects', async () => {
let error
try {
await Unit.delete(unit_id)
await Product.delete(product_id)
await Option.delete(option_id)
await Option_Group.delete(option_group_id)
} catch (err) {
error = err
}
should.not.exist(error)
})
})
})