@gameroom/gameroom-kit
Version:
Node kit for the Gameroom API
120 lines (118 loc) • 3.1 kB
JavaScript
let chai = require('chai'),
should = chai.should(),
faker = require('faker'),
{ models } = require('../../'),
{ Charge, Customer } = models,
chargeable, object, chargeable_type='Customer';
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');
objects = result;
});
});
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 () => {
Object.keys(object).should.deep.equal(Object.keys(Charge.schema.attributes));
});
});
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 result, error;
try {
result = await Customer.delete(chargeable);
} catch(err) {
error = err;
};
should.not.exist(error);
});
});
});