I tried to create the code to clean all tables respecting their relations (the child tables must be cleaned before their parent) and after this I need to add some basic data to run my tests.
I'm having some issues related to Promises chaining, because if I use Promise.all it doesn't respect the correct order, and if the create the chained blocks using then(() => {}) (as in the sample code below) it respects the order but the code becomes a mess.
How can I achieve the same result but without the mess?
before((done) => {
        modelDef.TaskListItemModel.TaskListItem.query().del()
            .then(() => {
                modelDef.TaskListModel.TaskList.query().del()
                    .then(() => {
                        modelDef.ProductAnomalyModel.ProductAnomaly.query().del()
                            .then(() => {
                                modelDef.ProductModel.Product.query().del()
                                    .then(() => {
                                        modelDef.UserModel.User.query().del()
                                            .then(() => {
                                                modelDef.UserModel.User.forge(test_User)
                                                    .save()
                                                    .then((result) => {
                                                        test_User.id = result.get('id');
                                                        test_ProductAnomaly.createdBy = test_User.id;
                                                        test_TaskList.createdBy = test_User.id;
                                                        return modelDef.ProductModel.Product.forge(test_Product)
                                                            .save();
                                                    })
                                                    .then((result) => {
                                                        test_Product.id = result.get('id');
                                                        test_ProductAnomaly.ProductId = test_Product.id;
                                                        return modelDef.ProductAnomalyModel.ProductAnomaly.forge(test_ProductAnomaly)
                                                            .save();
                                                    })
                                                    .then((result) => {
                                                        test_ProductAnomaly.id = result.get('id');
                                                        test_TaskListItem.ProductAnomalyId = test_ProductAnomaly.id;
                                                        return modelDef.TaskListModel.TaskList.forge(test_TaskList)
                                                            .save();
                                                    })
                                                    .then((result) => {
                                                        test_TaskListItem.tasklistId = result.get('id');
                                                        return modelDef.TaskListItemModel.TaskListItem.forge(test_TaskListItem)
                                                            .save();
                                                    })
                                                    .then(done);
                                            })
                                    })
                            })
                    })
            });
    });
