Skip to content

Commit

Permalink
Change URL root and unregister user response
Browse files Browse the repository at this point in the history
  • Loading branch information
rwngallego committed Aug 27, 2021
1 parent 96b5973 commit a0bf073
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/lib/push_api/api_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/push_api/api_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a0bf073

Please sign in to comment.