factory-girl icon indicating copy to clipboard operation
factory-girl copied to clipboard

delete objects after test suite

Open kedarnag138 opened this issue 6 years ago • 3 comments

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?

kedarnag138 avatar Jan 10 '19 08:01 kedarnag138

Have you tried this? Factory#cleanUp ex.

factory.createMany('xxxxxxx', 10).then((xxxxx) => {})
factory.cleanUp()

tomaszgiba avatar May 10 '19 12:05 tomaszgiba

I have tried that and it doesn't work?

lhendre avatar Aug 01 '19 19:08 lhendre

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.

tomaszgiba avatar Aug 02 '19 08:08 tomaszgiba