UNPKG

@gameroom/gameroom-kit

Version:

Node kit for the Gameroom API

142 lines (140 loc) 4.04 kB
let chai = require('chai'), should = chai.should(), faker = require('faker'), { models } = require('../../'), { Option_Group, Price_Option_Group, Price, Product } = models, object, option_group_id, price, product_id; describe('Price_Option_Group', () => { 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; // 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; // price try { result = await Price.create({ name: faker.random.word(), product_id }); } catch(err) { error = err; }; should.not.exist(error); should.exist(result); result.should.be.a('object'); price_id = result.id; }); }); describe('Price_Option_Group.create()', () => { it('should create an price_option_group', async () => { let result, error; try { result = await Price_Option_Group.create({ option_group_id, price_id }); } catch(err) { error = err; }; should.not.exist(error); should.exist(result); result.should.be.a('object'); object = result; }); }); describe('Price_Option_Group.get()', () => { it('should get array of price_option_groups', async () => { let result, error; try { result = await Price_Option_Group.get(); } catch(err) { error = err; }; should.not.exist(error); should.exist(result); result.should.be.a('array'); }); }); describe('Price_Option_Group.find()', () => { it('should find a price_option_group', async() => { let result, error; try { result = await Price_Option_Group.find(object, { view: 'full' }); } catch(err) { error = err; }; should.not.exist(error); should.exist(result); result.should.be.a('object'); object = result; }); }); describe('Price_Option_Group keys', () => { it('should match api and kit keys', async () => { Object.keys(object).should.deep.equal(Object.keys(Price_Option_Group.schema.attributes)); }); }); describe('Price_Option_Group.update()', () => { it('should update a price_option_group', async () => { let result, error; try { result = await Price_Option_Group.update(object); } catch(err) { error = err; }; should.not.exist(error); should.exist(result); result.should.be.a('object'); }); }); describe('price_option_group.save()', () => { it('should update one price_option_group', 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('Price_Option_Group.delete()', () => { it('should delete one price_option_group', async () => { let result, error; try { result = await Price_Option_Group.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 Price.delete(price_id); result = await Product.delete(product_id); result = await Option_Group.delete(option_group_id); } catch(err) { error = err; }; should.not.exist(error); }); }); });