@gameroom/kit
Version:
Node kit for the Gameroom API
137 lines (132 loc) • 3.37 kB
JavaScript
const { faker } = require('@faker-js/faker'),
chai = require('chai')
const {
models: { Price, Product }
} = require('../../')
const should = chai.should()
let object, product_id
describe('Price', () => {
describe('setup', () => {
it('should create objects for relationships', async () => {
let result, error
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
})
})
describe('Price.create()', () => {
it('should create an price', async () => {
let result, error
try {
result = await Price.create({ name: faker.random.word(), product_id })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Price.get()', () => {
it('should get array of prices', async () => {
let result, error
try {
result = await Price.get()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
})
})
describe('Price.getAll()', () => {
it('should get array of all prices', async () => {
let result, error
try {
result = await Price.getAll()
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('array')
})
})
describe('Price.find()', () => {
it('should find a price', async () => {
let result, error
try {
result = await Price.find(object, { view: 'full' })
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
object = result
})
})
describe('Price keys', () => {
it('should match api and kit keys', async () => {
const raw = await Price.schema.adapter.find(Price.schema, object.id)
Object.keys(new Price()).sort().should.deep.equal(Object.keys(raw).sort())
})
})
describe('Price.update()', () => {
it('should update a price', async () => {
let result, error
try {
result = await Price.update(object)
} catch (err) {
error = err
}
should.not.exist(error)
should.exist(result)
result.should.be.a('object')
})
})
describe('price.save()', () => {
it('should update one price', 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('Price.delete()', () => {
it('should delete one price', async () => {
let result, error
try {
result = await Price.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 Product.delete(product_id)
} catch (err) {
error = err
}
should.not.exist(error)
})
})
})