@gameroom/gameroom-kit
Version:
Node kit for the Gameroom API
119 lines (117 loc) • 3.04 kB
JavaScript
let chai = require('chai'),
should = chai.should(),
faker = require('faker'),
{ models } = require('../../'),
{ Price, Product } = models,
object, product_id;
describe('Price', () => {
describe('setup', () => {
it('should create objects for relationships', async() => {
let result, error;
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;
});
});
describe('Price.create()', () => {
it('should create an price', async () => {
let result, error;
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');
object = result;
});
});
describe('Price.get()', () => {
it('should get array of prices', async () => {
let result, error;
try {
result = await Price.get();
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('array');
});
});
describe('Price.find()', () => {
it('should find a price', async() => {
let result, error;
try {
result = await Price.find(object, { view: 'full' });
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
object = result;
});
});
describe('Price keys', () => {
it('should match api and kit keys', async () => {
Object.keys(object).should.deep.equal(Object.keys(Price.schema.attributes));
});
});
describe('Price.update()', () => {
it('should update a price', async () => {
let result, error;
try {
result = await Price.update(object);
} catch(err) {
error = err;
};
should.not.exist(error);
should.exist(result);
result.should.be.a('object');
});
});
describe('price.save()', () => {
it('should update one price', 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.delete()', () => {
it('should delete one price', async () => {
let result, error;
try {
result = await Price.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 Product.delete(product_id);
} catch(err) {
error = err;
};
should.not.exist(error);
});
});
});