mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 18:15:19 +00:00
updating tests with api changes
This commit is contained in:
parent
3fa35ce686
commit
fbf31cef85
@ -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)));
|
||||
});
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
]);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user