Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function fetchTimeline(path, viewerContext = null) {
const headers = {};
if (viewerContext) {
headers['X-Authentication-Token'] = viewerContext.authToken;
}
const response = await fetch(
await apiUrl(`/v2/timelines/${path}`),
{ agent, headers }
);
const feed = await response.json();
// console.log(feed);
if (response.status !== 200) {
expect.fail('HTTP error (code {0}): {1}', response.status, feed.err);
}
expect(feed, 'to exhaustively satisfy', schema.timelineResponse);
return feed;
}
async function fetchEverything(viewerContext = null) {
const headers = {};
if (viewerContext) {
headers['X-Authentication-Token'] = viewerContext.authToken;
}
const response = await performRequest(`/v2/everything`, { headers });
const feed = await response.json();
// console.log(feed);
if (response.status !== 200) {
expect.fail('HTTP error (code {0}): {1}', response.status, feed.err);
}
expect(feed, 'to exhaustively satisfy', schema.everythingResponse);
return feed;
}
const updatePost = async (postObj, userContext, parameters) => {
const res = await funcTestHelper.updatePostAsync({ ...userContext, post: postObj }, parameters);
const body = await res.json();
if (res.status != 200) {
expect.fail(`Error updating post (${res.status}): ${body.err}`);
}
return body;
};
async function fetchMetatags(username) {
const response = await performRequest(`/v2/timelines-metatags/${username}`);
if (response.status !== 200) {
const { err } = await response.json();
expect.fail('HTTP error (code {0}): {1}', response.status, err);
}
return await response.text();
}
const postOpenGraphFetcher = (app) => async (postId) => {
const res = await fetch(`${app.context.config.host}/v2/posts-opengraph/${postId}`);
if (res.status !== 200) {
expect.fail('HTTP error (code {0})', res.status);
}
return await res.text();
};
if (viewerContext) {
headers['X-Authentication-Token'] = viewerContext.authToken;
}
const response = await fetch(
await apiUrl(`/${params.apiVersion}/posts/${postId}?maxComments=${params.allComments ? 'all' : ''}&maxLikes=${params.allLikes ? 'all' : ''}`),
{ agent, headers }
);
const post = await response.json();
if (response.status !== 200) {
if (params.returnError) {
return response;
}
expect.fail('HTTP error (code {0}): {1}', response.status, post.err);
}
if (params.apiVersion === 'v2') {
expect(post, 'to exhaustively satisfy', schema.postResponse);
}
return post;
}