updating tests with api changes

This commit is contained in:
balzack 2024-09-09 22:26:48 -07:00
parent 3fa35ce686
commit fbf31cef85
4 changed files with 12 additions and 17 deletions

View File

@ -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)));
});

View File

@ -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;

View File

@ -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<Response> {
return Promise.race<Response>([
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))
]);
}

View File

@ -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);
}