@gameroom/gameroom-kit
Version:
Node kit for the Gameroom API
153 lines (151 loc) • 4.2 kB
JavaScript
let chai = require('chai'),
should = chai.should(),
faker = require('faker'),
{ models } = require('../../'),
{ Option_Group, Option, Product, Unit_Option, Unit } = models,
option_group_id, option_id, product_id, unit_id, object;
describe('Unit_Option', () => {
describe('setup', () => {
it('should create objects for relationships', async() => {
let result, error;
// option_group
try {
result = await Option_Group.create({ name: faker.random.word() });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
option_group_id = result.id;
// option
try {
result = await Option.create({ name: faker.random.word(), option_group_id });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
option_id = result.id;
// product
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');
product_id = result.id;
// unit
try {
result = await Unit.create({ name: faker.random.word(), product_id });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
unit_id = result.id;
});
});
describe('Unit_Option.create()', () => {
it('should create a unit_option', async () => {
let result, error;
try {
result = await Unit_Option.create({ unit_id, option_id });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
object = result;
});
});
describe('Unit_Option.get()', () => {
it('should get array of unit_options', async () => {
let result, error;
try {
result = await Unit_Option.get();
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('array');
});
});
describe('Unit_Option.find()', () => {
it('should find a unit_option', async() => {
let result, error;
try {
result = await Unit_Option.find(object, { view: 'full' });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
object = result;
});
});
describe('Unit_Option keys', () => {
it('should match api and kit keys', async () => {
Object.keys(object).should.deep.equal(Object.keys(Unit_Option.schema.attributes));
});
});
describe('Unit_Option.update()', () => {
it('should update a unit_option', async () => {
let result, error;
try {
result = await Unit_Option.update(object);
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
});
});
describe('unit_option.save()', () => {
it('should update one unit_option', 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_Option.delete()', () => {
it('should delete one unit_option', async () => {
let result, error;
try {
result = await Unit_Option.delete(object);
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
});
});
describe('teardown', () => {
it('should delete the relationship objects', async() => {
let error;
try {
await Unit.delete(unit_id);
await Product.delete(product_id);
await Option.delete(option_id);
await Option_Group.delete(option_group_id);
} catch(err) {
error = err;
};
should.not.exist(error);
});
});
});