UNPKG

@gameroom/kit

Version:

Node kit for the Gameroom API

148 lines (142 loc) 3.75 kB
const { faker } = require('@faker-js/faker'), chai = require('chai') const { models: { Address, Customer } } = require('../../') const should = chai.should() const addressable_type = 'Customer' let addressable_id, object describe('Address', () => { 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') addressable_id = result.id }) }) describe('Address.create()', () => { it('should create an address', async () => { let result, error try { result = await Address.create({ city: faker.address.city(), country: faker.address.country(), name: faker.random.word(), state: faker.address.state(), street1: faker.address.streetAddress(), zip: faker.address.zipCode(), addressable_id, addressable_type }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') object = result }) }) describe('Address.get()', () => { it('should get array of addresses', async () => { let result, error try { result = await Address.get() } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('array') }) }) describe('Address.getAll()', () => { it('should get array of all addresses', async () => { let result, error try { result = await Address.getAll() } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('array') }) }) describe('Address.find()', () => { it('should find an address', async () => { let result, error try { result = await Address.find(object, { view: 'full' }) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') object = result }) }) describe('Address keys', () => { it('should match api and kit keys', async () => { const raw = await Address.schema.adapter.find(Address.schema, object.id) Object.keys(new Address()).sort().should.deep.equal(Object.keys(raw).sort()) }) }) describe('Address.update()', () => { it('should update a address', async () => { let result, error try { result = await Address.update(object) } catch (err) { error = err } should.not.exist(error) should.exist(result) result.should.be.a('object') }) }) describe('address.save()', () => { it('should update one addresses', 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('Address.delete()', () => { it('should delete one address', async () => { let result, error try { result = await Address.delete(object) } catch (err) { error = err } should.not.exist(error) should.exist(result) }) }) describe('teardown', () => { it('should delete the relationship object', async () => { let error try { await Customer.delete(addressable_id) } catch (err) { error = err } should.not.exist(error) }) }) })