Added some new tests

This commit is contained in:
Damien Broqua 2020-02-13 22:36:14 +01:00
parent 0039a8b4ec
commit 918f873fea
15 changed files with 887 additions and 114 deletions

View file

@ -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
View 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);
});
}
});
};