@gameroom/gameroom-kit
Version:
Node kit for the Gameroom API
94 lines (92 loc) • 2.35 kB
JavaScript
let chai = require('chai'),
should = chai.should(),
faker = require('faker'),
{ models } = require('../../'),
{ Product, Unit } = models,
product, object;
describe('Unit', () => {
describe('Unit.create()', () => {
it('should create a unit', async () => {
let result, error;
try {
result = await Unit.create({ name: faker.random.word(), product });
} 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.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 () => {
Object.keys(object).should.deep.equal(Object.keys(Unit.schema.attributes));
});
});
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);
});
});
});