UNPKG

@gameroom/kit

Version:

Node kit for the Gameroom API

160 lines (155 loc) 4.41 kB
const { faker } = require('@faker-js/faker'), chai = require('chai') const { models: { Option_Group, Price_Option_Group, Price, Product } } = require('../../') const should = chai.should() let object, option_group_id, price_id, 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.getAll()', () => { it('should get array of all price_option_groups', async () => { let result, error try { result = await Price_Option_Group.getAll() } 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 () => { const raw = await Price_Option_Group.schema.adapter.find(Price_Option_Group.schema, object.id) Object.keys(new Price_Option_Group()).sort().should.deep.equal(Object.keys(raw).sort()) }) }) 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 error try { await Price.delete(price_id) await Product.delete(product_id) await Option_Group.delete(option_group_id) } catch (err) { error = err } should.not.exist(error) }) }) })