Added some new tests
This commit is contained in:
parent
0039a8b4ec
commit
918f873fea
15 changed files with 887 additions and 114 deletions
|
@ -1,5 +1,6 @@
|
|||
import uuid from "uuid/v4";
|
||||
import models from "../../models";
|
||||
import truncateDefault from "./truncate";
|
||||
|
||||
const _createCar = (brandId, active, year, done) => {
|
||||
models.Cars.create({
|
||||
|
@ -42,47 +43,7 @@ const _createBrands = (total, done) => {
|
|||
}
|
||||
};
|
||||
|
||||
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;
|
||||
export const truncate = truncateDefault;
|
||||
|
|
45
test/utils/truncate.js
Normal file
45
test/utils/truncate.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
import models from "../../models";
|
||||
|
||||
const _truncateCars = (tables, done) => {
|
||||
if (tables.indexOf("Cars") === -1) {
|
||||
done(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
models.CarsColors.destroy({
|
||||
where: {}
|
||||
})
|
||||
.then(() => {
|
||||
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;
|
||||
};
|
||||
|
||||
export default (tables, done) => {
|
||||
_truncateCars(tables, errCars => {
|
||||
if (errCars) {
|
||||
done(errCars);
|
||||
} else {
|
||||
_truncateBrands(tables, errBrands => {
|
||||
done(errBrands);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue