Added some tests (createOne and getAll)
This commit is contained in:
parent
ef7ca0315b
commit
9f0886541c
21 changed files with 2940 additions and 67 deletions
88
test/utils/common.js
Normal file
88
test/utils/common.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
import uuid from "uuid/v4";
|
||||
import models from "../../models";
|
||||
|
||||
const _createCar = (brandId, active, year, done) => {
|
||||
models.Cars.create({
|
||||
name: uuid(),
|
||||
year,
|
||||
active,
|
||||
brandId
|
||||
})
|
||||
.then(item => {
|
||||
done(null, item);
|
||||
})
|
||||
.catch(done);
|
||||
};
|
||||
|
||||
const _createBrand = done => {
|
||||
models.Brands.create({
|
||||
name: uuid()
|
||||
})
|
||||
.then(item => {
|
||||
done(null, item);
|
||||
})
|
||||
.catch(done);
|
||||
};
|
||||
|
||||
const _createBrands = (total, done) => {
|
||||
const created = [];
|
||||
const next = () => {
|
||||
if (total === created.length) {
|
||||
done(null, created);
|
||||
}
|
||||
};
|
||||
|
||||
for (let i = 0; i < total; i += 1) {
|
||||
_createBrand((err, res) => {
|
||||
if (!err) {
|
||||
created.push(res);
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const _truncateCars = (tables, done) => {
|
||||
if (tables.indexOf("Cars") === -1) {
|
||||
done(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
models.Cars.destroy({
|
||||
where: {}
|
||||
})
|
||||
.then(() => done(null))
|
||||
.catch(err => done(err));
|
||||
return true;
|
||||
};
|
||||
|
||||
const _truncateBrands = (tables, done) => {
|
||||
if (tables.indexOf("Brands") === -1) {
|
||||
done(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
models.Brands.destroy({
|
||||
where: {}
|
||||
})
|
||||
.then(() => done(null))
|
||||
.catch(err => done(err));
|
||||
return true;
|
||||
};
|
||||
|
||||
const _truncate = (tables, done) => {
|
||||
_truncateCars(tables, errCars => {
|
||||
if (errCars) {
|
||||
done(errCars);
|
||||
} else {
|
||||
_truncateBrands(tables, errBrands => {
|
||||
done(errBrands);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const createBrand = _createBrand;
|
||||
export const createBrands = _createBrands;
|
||||
export const createCar = _createCar;
|
||||
export const truncate = _truncate;
|
Loading…
Add table
Add a link
Reference in a new issue