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