-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repository): implement undo soft delete feature (#185)
GH-182 ## Description Add 2 functionalities to undo the soft delete of a record 1. undoSoftDeleteById() -> This will just undo soft delete entity by specified id 2. undoSoftDeleteAll() -> This will undo soft delete entities depending on where clause or all. Fixes # (issue) ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested ? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [x] Test A - [x] Test B ## Checklist: - [x] Performed a self-review of my own code - [x] npm test passes on your machine
- Loading branch information
1 parent
bc202f4
commit 8622d8e
Showing
2 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ describe('SoftCrudRepository', () => { | |
const customers = await repo.find(); | ||
expect(customers).to.have.length(3); | ||
}); | ||
|
||
it('should find non soft deleted entries with and operator', async () => { | ||
const customers = await repo.find({ | ||
where: { | ||
|
@@ -793,6 +794,80 @@ describe('SoftCrudRepository', () => { | |
}); | ||
}); | ||
|
||
describe('undoSoftDelete', () => { | ||
beforeEach(setupTestData); | ||
afterEach(clearTestData); | ||
|
||
it('should undo soft deleted entry by id', async () => { | ||
await repo.undoSoftDeleteById(3); | ||
const customer = await repo.findById(3); | ||
const customers = await repo.find(); | ||
expect(customer.deleted).to.false(); | ||
expect(customers).to.have.length(4); | ||
}); | ||
|
||
it('should check deletedOn flag is undefined after undo', async () => { | ||
const softDeletedCustomer = await repo.findByIdIncludeSoftDelete(3); | ||
expect(softDeletedCustomer.deletedOn).to.Date(); | ||
await repo.undoSoftDeleteById(3); | ||
const customer = await repo.findById(3); | ||
expect(customer.deletedOn).to.undefined(); | ||
}); | ||
|
||
it('should undo all soft deleted entries', async () => { | ||
await repo.deleteAll(); | ||
await repo.undoSoftDeleteAll(); | ||
const customers = await repo.find(); | ||
expect(customers).to.have.length(4); | ||
}); | ||
|
||
it('should undo soft deleted entries with and operator', async () => { | ||
await repo.undoSoftDeleteAll({ | ||
and: [{email: '[email protected]'}, {id: 3}], | ||
}); | ||
const customers = await repo.find({ | ||
where: { | ||
and: [ | ||
{ | ||
email: '[email protected]', | ||
}, | ||
{ | ||
id: 3, | ||
}, | ||
], | ||
}, | ||
}); | ||
expect(customers).to.have.length(1); | ||
}); | ||
|
||
it('should undo soft deleted entries with or operator', async () => { | ||
await repo.deleteAll({email: '[email protected]'}); | ||
await repo.undoSoftDeleteAll({ | ||
or: [ | ||
{ | ||
email: '[email protected]', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
}, | ||
], | ||
}); | ||
const customers = await repo.find({ | ||
where: { | ||
or: [ | ||
{ | ||
email: '[email protected]', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
}, | ||
], | ||
}, | ||
}); | ||
expect(customers).to.have.length(2); | ||
}); | ||
}); | ||
|
||
describe('deleteAll', () => { | ||
beforeEach(setupTestData); | ||
afterEach(clearTestData); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters