Took a while to get these to pass and fail for the correct reasons. Really need to make sure the functions are all called from the correct address using the from
attribute. Added an additional test for the positive delete case.
it('should REVERT when deleting a person if the sender is NOT the contract owner', async function () {
let instance = await People.deployed();
await instance.createPerson('Sally', 45, 130, { value: web3.utils.toWei('1', 'ether'), from: accounts[1] });
let p = await instance.getPerson({from: accounts[1]});
assert(p.name === 'Sally', 'precondition: person not created');
await truffleAssert.fails(
instance.deletePerson(accounts[1], {from: accounts[1]}),
truffleAssert.ErrorType.REVERT
);
let person = await instance.getPerson({from: accounts[1]});
assert(person.name === 'Sally', 'person should not have been deleted');
});
it('should remove the person from the mapping when it is deleted', async function() {
let instance = await People.deployed();
await instance.createPerson('Joe', 40, 180, { value: web3.utils.toWei('1', 'ether'), from: accounts[2] });
let person = await instance.getPerson({from: accounts[2]});
assert(person.name === 'Joe', 'precondition: person not created');
await instance.deletePerson(accounts[2]);
let result = await instance.getPerson({from: accounts[2]});
assert(result.name === '', 'person NOT deleted from mapping');
});