@gameroom/gameroom-kit
Version:
Node kit for the Gameroom API
131 lines (129 loc) • 3.4 kB
JavaScript
const chai = require('chai'),
should = chai.should(),
faker = require('faker'),
{ models } = require('../../'),
{ Unit_Tag, Unit, Tag } = models;
let object, tag_id, unit_id;
describe('Unit_Tag', () => {
describe('setup', () => {
it('should create objects for relationships', async() => {
let result, error;
// tag
try {
result = await Tag.create({ name: faker.random.word() });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
tag_id = result.id;
// unit
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');
unit_id = result.id;
});
});
describe('Unit_Tag.create()', () => {
it('should create an unit_tag', async () => {
let result, error;
try {
result = await Unit_Tag.create({ tag_id, unit_id });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
object = result;
});
});
describe('Unit_Tag.get()', () => {
it('should get array of unit_tags', async () => {
let result, error;
try {
result = await Unit_Tag.get();
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('array');
});
});
describe('Unit_Tag.find()', () => {
it('should find a unit_tag', async() => {
let result, error;
try {
result = await Unit_Tag.find(object, { view: 'full' });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
object = result;
});
});
describe('Unit_Tag keys', () => {
it('should match api and kit keys', async () => {
Object.keys(object).should.deep.equal(Object.keys(Unit_Tag.schema.attributes));
});
});
describe('Unit_Tag.update()', () => {
it('should update a unit_tag', async () => {
let result, error;
try {
result = await Unit_Tag.update(object);
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
});
});
describe('unit_tag.save()', () => {
it('should update one unit_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('Unit_Tag.delete()', () => {
it('should delete one unit_tag', async () => {
let result, error;
try {
result = await Unit_Tag.delete(object);
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
});
});
describe('teardown', () => {
it('should delete the relationship objects', async() => {
let result, error;
try {
result = await Tag.delete(tag_id);
result = await Unit.delete(unit_id);
} catch(err) {
error = err;
};
should.not.exist(error);
});
});
});