UNPKG

@gameroom/kit

Version:

Node kit for the Gameroom API

138 lines (132 loc) 3.38 kB
const chai = require('chai') const { models: { Charge, Customer } } = require('../../') const should = chai.should() const chargeable_type = 'Customer' let chargeable, object describe('Charge', () => { describe('setup', () => { it('should create objects for relationships', async () => { let result, error try { result = await Customer.create({ password: 'password' }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') chargeable = result }) }) describe('Charge.create()', () => { it('should create a charge', async () => { let result, error try { result = await Charge.create({ chargeable, chargeable_type }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') object = result }) }) describe('Charge.get()', () => { it('should get array of charges', async () => { let result, error try { result = await Charge.get() } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('array') }) }) describe('Charge.getAll()', () => { it('should get array of all charges', async () => { let result, error try { result = await Charge.getAll() } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('array') }) }) describe('Charge.find()', () => { it('should find a charge', async () => { let result, error try { result = await Charge.find(object, { view: 'full' }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') object = result }) }) describe('Charge keys', () => { it('should match api and kit keys', async () => { const raw = await Charge.schema.adapter.find(Charge.schema, object.id) Object.keys(new Charge()).sort().should.deep.equal(Object.keys(raw).sort()) }) }) describe('Charge.update()', () => { it('should update a charge', async () => { let result, error try { result = await Charge.update(object) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') }) }) describe('charge.save()', () => { it('should update one charges', 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('Charge.delete()', () => { it('should delete one charge', async () => { let result, error try { result = await Charge.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 Customer.delete(chargeable) } catch (err) { error = err } should.not.exist(error) }) }) })