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