From a0bf073b27bed39682acb3ae50441b843422e945 Mon Sep 17 00:00:00 2001 From: rwngallego Date: Fri, 27 Aug 2021 02:43:05 +0200 Subject: [PATCH] Change URL root and unregister user response --- src/lib/push_api/api_client.js | 14 +++++++------- src/lib/push_api/api_client.test.js | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib/push_api/api_client.js b/src/lib/push_api/api_client.js index 685b73b..fcafda6 100644 --- a/src/lib/push_api/api_client.js +++ b/src/lib/push_api/api_client.js @@ -8,7 +8,7 @@ const ApiClient = (() => { firstTime = false } - const path = `${Options.serverUrl}/v1/public/users` + const path = `${Options.serverUrl}/v1/push/users` const bodyContent = JSON.stringify({ user: pushSubscription, user_id: userId, @@ -35,7 +35,7 @@ const ApiClient = (() => { const getUser = async (userId) => { Logger.info('Getting the registration status from the server') - const path = `${Options.serverUrl}/v1/public/users/${userId}` + const path = `${Options.serverUrl}/v1/push/users/${userId}` const body = await fetch(path, { method: 'get', @@ -62,21 +62,21 @@ const ApiClient = (() => { Logger.info('Unregistering user in the server') Logger.debug(`User: ${userId}`) - const path = `${Options.serverUrl}/v1/public/users/${userId}/unregister` + const path = `${Options.serverUrl}/v1/push/users/${userId}/unregister` - let response + let success = false try { const body = await fetch(path, { method: 'post', headers: getHeaders() }) - response = await body.json() - Logger.debug('response', response) + success = body.ok } catch (e) { Logger.error('Could not execute the fetch operation', e) + return false } - if (response && typeof response.result !== 'undefined') { + if (success) { Logger.info('The user was unregistered') return true } else { diff --git a/src/lib/push_api/api_client.test.js b/src/lib/push_api/api_client.test.js index 39dd399..c897a96 100644 --- a/src/lib/push_api/api_client.test.js +++ b/src/lib/push_api/api_client.test.js @@ -74,10 +74,9 @@ describe('when getting a user', () => { describe('when unregistering the user', () => { it('returns true on success', async () => { - const response = { result: true } fetch.mockImplementationOnce(() => { return Promise.resolve({ - json: () => Promise.resolve(response) + ok: () => true }) }) const result = await ApiClient.unregister('user-uuid-1')