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