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