diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index 10761ea..e960ff6 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -361,12 +361,14 @@ router.put('/:sid', async(req, res) => { // create webhooks if provided const obj = Object.assign({}, req.body); - if (null !== obj.registration_hook) { - for (const prop of ['registration_hook']) { - if (prop in obj && Object.keys(obj[prop]).length) { + for (const prop of ['registration_hook', 'queue_event_hook']) { + if (prop in obj) { + if (null === obj[prop]) { + obj[`${prop}_sid`] = null; + } + else if (typeof obj[prop] === 'object') { if ('webhook_sid' in obj[prop]) { const sid = obj[prop]['webhook_sid']; - delete obj[prop]['webhook_sid']; await Webhook.update(sid, obj[prop]); } else { @@ -374,30 +376,6 @@ router.put('/:sid', async(req, res) => { obj[`${prop}_sid`] = sid; } } - else { - obj[`${prop}_sid`] = null; - } - delete obj[prop]; - } - } - - if (null !== obj.queue_event_hook) { - for (const prop of ['queue_event_hook']) { - if (prop in obj && Object.keys(obj[prop]).length) { - if ('webhook_sid' in obj[prop]) { - const sid = obj[prop]['webhook_sid']; - delete obj[prop]['webhook_sid']; - await Webhook.update(sid, obj[prop]); - } - else { - const sid = await Webhook.make(obj[prop]); - obj[`${prop}_sid`] = sid; - } - } - else { - obj[`${prop}_sid`] = null; - } - delete obj[prop]; } } @@ -409,14 +387,14 @@ router.put('/:sid', async(req, res) => { const results = await Account.retrieve(sid); if (results.length && results[0].registration_hook_sid) orphanedRegHook = results[0].registration_hook_sid; obj.registration_hook_sid = null; - delete obj.registration_hook; } if (null === obj.queue_event_hook) { const results = await Account.retrieve(sid); if (results.length && results[0].queue_event_hook_sid) orphanedQueueHook = results[0].queue_event_hook_sid; obj.queue_event_hook_sid = null; - delete obj.queue_event_hook; } + delete obj.registration_hook; + delete obj.queue_event_hook; const rowsAffected = await Account.update(sid, obj); if (rowsAffected === 0) { diff --git a/test/docker-compose-testbed.yaml b/test/docker-compose-testbed.yaml index f2a3d28..dc4248b 100644 --- a/test/docker-compose-testbed.yaml +++ b/test/docker-compose-testbed.yaml @@ -56,9 +56,9 @@ services: - ./postgres-data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "psql -h 'localhost' -U 'root' -c '\\l'"] - interval: 1s + interval: 3s timeout: 3s - retries: 30 + retries: 60 networks: jambonz-api: ipv4_address: 172.58.0.5 diff --git a/test/postgresql/init-user-db.sh b/test/postgresql/init-user-db.sh old mode 100644 new mode 100755