factory-girl
factory-girl copied to clipboard
delete objects after test suite
I'm using Dynamoose with factory-girl. In one of my test cases, I'm using the following
factory.createMany('xxxxxxx', 10).then((xxxxx) => {});
which is creating 10 records in my test db, however, what I'm trying to do is, I would like to delete those 10 records after the test suite is done from my local dynamoDB.
I did look at this link https://github.com/aexmachina/factory-girl#objectadapter
, but there is no support for DynamoDB. Any suggestions on this?
Have you tried this? Factory#cleanUp ex.
factory.createMany('xxxxxxx', 10).then((xxxxx) => {})
factory.cleanUp()
I have tried that and it doesn't work?
I read that: (https://github.com/aexmachina/factory-girl#factorycleanup) cleanUp() calls destroy() method of an adapter:
cleanUp() {
const createdArray = [];
for (const c of this.created) {
createdArray.push(c);
}
const promise = createdArray.reduce(
(prev, [adapter, model]) =>
prev.then(() => adapter.destroy(model, model.constructor)),
Promise.resolve()
);
this.created.clear();
this.resetSeq();
return promise;
}
Briefly looking at Dynamoose's docs I can't see them having destroy()
method at all: https://dynamoosejs.com/api/model/
Maybe that's the case.