Commit 30f35ec0 authored by aguestuser's avatar aguestuser

Merge branch 'hotfix-notify-members-of-deleted-channels-in-background' into 'main'

[hotfix] notify members of deleted channels in background

See merge request !393
parents 97dd8323 0419d5ad
......@@ -20,7 +20,7 @@ test_lint:
test_unit:
services:
- name: postgres:latest
- name: postgres:12
alias: db
script:
- yarn install
......@@ -31,7 +31,7 @@ test_unit:
test_integration:
services:
- name: postgres:latest
- name: postgres:12
alias: db
script:
- yarn install
......
......@@ -27,18 +27,31 @@ const destroy = async ({ phoneNumber, sender }) => {
return { status: 'ERROR', message: `No records found for ${phoneNumber}` }
if (phoneNumberRecord) {
logger.log(`deleting phone number ${phoneNumber}...`)
await phoneNumberRepository.destroy(phoneNumber, tx)
await releasePhoneNumber(phoneNumberRecord)
logger.log(`...deleted phone number ${phoneNumber}.`)
}
if (channel) {
logger.log(`deleting channel ${phoneNumber}...`)
await channelRepository.destroy(channel.phoneNumber, tx)
await eventRepository.log(eventTypes.CHANNEL_DESTROYED, phoneNumber, tx)
await notifier.notifyMembersExcept(channel, sender, notificationKeys.CHANNEL_DESTROYED)
logger.log(`...deleted channel ${phoneNumber}`)
;(async () => {
logger.log(`sending deletion notice to members of: ${phoneNumber}...`)
await notifier
.notifyMembersExcept(channel, sender, notificationKeys.CHANNEL_DESTROYED)
.catch(logger.error)
logger.log(`...sent deltion notice to members of: ${phoneNumber}`)
})()
}
logger.log(`destroying signald data for ${phoneNumber}...`)
await signal.unsubscribe(phoneNumber)
await deleteSignalKeystore(phoneNumber)
logger.log(`destroyed signald data for ${phoneNumber}...`)
await tx.commit()
return { status: 'SUCCESS', msg: 'All records of phone number have been destroyed.' }
......
......@@ -52,7 +52,7 @@ describe('phone number registrar -- destroy module', () => {
destroyChannelStub = sinon.stub(channelRepository, 'destroy')
destroyPhoneNumberStub = sinon.stub(phoneNumberRepository, 'destroy')
notifyMaintainersStub = sinon.stub(notifier, 'notifyMaintainers')
notifyMembersExceptStub = sinon.stub(notifier, 'notifyMembersExcept')
notifyMembersExceptStub = sinon.stub(notifier, 'notifyMembersExcept').returns(Promise.resolve())
twilioRemoveStub = sinon.stub()
sinon.stub(commonService, 'getTwilioClient').callsFake(() => ({
incomingPhoneNumbers: () => ({ remove: twilioRemoveStub }),
......@@ -225,19 +225,18 @@ describe('phone number registrar -- destroy module', () => {
notifyMaintainersStub.returns(Promise.resolve())
})
it('returns an error status', async () => {
it('commits the db transaction', async () => {
await destroy({ phoneNumber })
expect(commitStub.callCount).to.eql(1)
})
it('returns a success status', async () => {
const response = await destroy({ phoneNumber })
expect(response).to.eql({
message: `Failed to destroy channel for ${phoneNumber}. Error: Failed to broadcast message`,
status: 'ERROR',
status: 'SUCCESS',
msg: 'All records of phone number have been destroyed.',
})
})
it('rolls back the db transaction', async () => {
await destroy({ phoneNumber })
expect(rollbackStub.callCount).to.eql(1)
expect(commitStub.callCount).to.eql(0)
})
})
describe('when deleting the phone number from the db fails', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment