UNPKG

@gameroom/kit

Version:

Node kit for the Gameroom API

112 lines (107 loc) 2.67 kB
const { faker } = require('@faker-js/faker'), chai = require('chai') const { models: { Unit } } = require('../../') const should = chai.should() let object describe('Unit', () => { describe('Unit.create()', () => { it('should create a unit', async () => { let result, error try { result = await Unit.create({ name: faker.random.word() }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') object = result }) }) describe('Unit.get()', () => { it('should get array of units', async () => { let result, error try { result = await Unit.get() } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('array') }) }) describe('Unit.getAll()', () => { it('should get array of all units', async () => { let result, error try { result = await Unit.getAll() } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('array') }) }) describe('Unit.find()', () => { it('should find a unit', async () => { let result, error try { result = await Unit.find(object, { view: 'full' }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') object = result }) }) describe('Unit keys', () => { it('should match api and kit keys', async () => { const raw = await Unit.schema.adapter.find(Unit.schema, object.id) Object.keys(new Unit()).sort().should.deep.equal(Object.keys(raw).sort()) }) }) describe('Unit.update()', () => { it('should update a unit', async () => { let result, error try { result = await Unit.update(object) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') }) }) describe('unit.save()', () => { it('should update one unit', 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.delete()', () => { it('should delete one unit', async () => { let result, error try { result = await Unit.delete(object) } catch (err) { error = err } should.not.exist(error) should.exist(result) }) }) })