diff --git a/app/sdk/__tests__/identity.tests.ts b/app/sdk/__tests__/identity.tests.ts index 92f6bfa2..5f474420 100644 --- a/app/sdk/__tests__/identity.tests.ts +++ b/app/sdk/__tests__/identity.tests.ts @@ -39,11 +39,11 @@ test('allocates session correctly', async () => { const identity = new IdentityModule(log, store, 'test_guid', 'test_token', 'test_url', false); identity.setRevision(5); identity.addProfileListener((ev: Profile) => { profile = ev }); - await waitFor(() => (profile?.handle == 'test' && profile?.name != 'test_name' && profile?.image != 'test_image')); + await waitFor(() => (profile?.handle == 'test' && profile?.name != 'test_name' && !profile?.imageSet)); identity.setProfileData("test_name", "test_location", "test_description"); identity.setRevision(6); - await waitFor(() => (profile?.name == 'test_name' && profile?.image != 'test_image')); + await waitFor(() => (profile?.name == 'test_name' && !profile?.imageSet)); identity.setProfileImage("test_image"); identity.setRevision(7); - await waitFor(() => (profile?.image == 'test_image')); + await waitFor(() => (Boolean(profile?.imageSet))); }); diff --git a/app/sdk/__tests__/settings.tests.ts b/app/sdk/__tests__/settings.tests.ts index a290805c..b6239990 100644 --- a/app/sdk/__tests__/settings.tests.ts +++ b/app/sdk/__tests__/settings.tests.ts @@ -17,10 +17,10 @@ jest.mock('redaxios', () => { }), put: jest.fn().mockImplementation((url, body) => { if (url == 'http://test_url/account/notification?agent=test_token') { - testConfig.pushEnabled = body; + testConfig.pushEnabled = JSON.parse(body); } if (url == 'http://test_url/account/searchable?agent=test_token') { - testConfig.searchable = body; + testConfig.searchable = JSON.parse(body); } if (url == 'http://test_url/account/seal?agent=test_token') { testConfig.seal = body; diff --git a/app/sdk/src/net/fetchUtil.ts b/app/sdk/src/net/fetchUtil.ts index 3b2335c4..c576b34d 100644 --- a/app/sdk/src/net/fetchUtil.ts +++ b/app/sdk/src/net/fetchUtil.ts @@ -2,22 +2,16 @@ const TIMEOUT = 15000; //await new Promise(r => setTimeout(r, 2000)); -export function checkResponse(response) { - if(response.status >= 400 && response.status < 600) { - throw new Error(response.status); +export function checkResponse(code: number) { + if(code >= 400 && code < 600) { + throw new Error(code.toString()); } } -export async function fetchWithTimeout(url, options) { - return Promise.race([ +export async function fetchWithTimeout(url: string, options: RequestInit): Promise { + return Promise.race([ fetch(url, options).catch(err => { throw new Error(url + ' failed'); }), new Promise((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), TIMEOUT)) ]); } -export async function fetchWithCustomTimeout(url, options, timeout) { - return Promise.race([ - fetch(url, options).catch(err => { throw new Error(url + ' failed'); }), - new Promise((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), timeout)) - ]); -} diff --git a/app/sdk/src/net/setAccountLogin.ts b/app/sdk/src/net/setAccountLogin.ts index b299fad1..a25bdb3d 100644 --- a/app/sdk/src/net/setAccountLogin.ts +++ b/app/sdk/src/net/setAccountLogin.ts @@ -6,5 +6,6 @@ export async function setAccountLogin(node: string, secure: boolean, token: stri const auth = encode(`${username}:${password}`); const headers = new Headers() headers.append('Credentials', `Basic ${auth}`); - checkResponse(await fetchWithTimeout(endpoint, { method: 'PUT', headers })); + const { status } = await fetchWithTimeout(endpoint, { method: 'PUT', headers }); + checkResponse(status); }