Adding some more tests, some still broken.

This commit is contained in:
Dessalines 2020-09-14 13:11:28 -05:00
parent 554d6beafa
commit d4492a573a
5 changed files with 42 additions and 0 deletions

View file

@ -1,8 +1,10 @@
jest.setTimeout(120000);
import { import {
alpha, alpha,
beta, beta,
setupLogins, setupLogins,
searchForBetaCommunity, searchForBetaCommunity,
searchForCommunity,
createCommunity, createCommunity,
deleteCommunity, deleteCommunity,
removeCommunity, removeCommunity,
@ -21,6 +23,17 @@ test('Create community', async () => {
let prevName = communityRes.community.name; let prevName = communityRes.community.name;
let communityRes2 = await createCommunity(alpha, prevName); let communityRes2 = await createCommunity(alpha, prevName);
expect(communityRes2['error']).toBe('community_already_exists'); expect(communityRes2['error']).toBe('community_already_exists');
await delay();
// Cache the community on beta, make sure it has the other fields
let searchShort = `!${prevName}@lemmy-alpha:8540`;
let search = await searchForCommunity(beta, searchShort);
let communityOnBeta = search.communities[0];
expect(communityOnBeta.name).toBe(communityRes.community.name);
expect(communityOnBeta.title).toBe(communityRes.community.title);
expect(communityOnBeta.description).toBe(communityRes.community.description);
expect(communityOnBeta.icon).toBe(communityRes.community.icon);
expect(communityOnBeta.banner).toBe(communityRes.community.banner);
}); });
test('Delete community', async () => { test('Delete community', async () => {

View file

@ -56,6 +56,10 @@ test('Create a post', async () => {
expect(betaPost.community_local).toBe(true); expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false); expect(betaPost.creator_local).toBe(false);
expect(betaPost.score).toBe(1); expect(betaPost.score).toBe(1);
expect(betaPost.name).toBe(postRes.post.name);
expect(betaPost.body).toBe(postRes.post.body);
expect(betaPost.url).toBe(postRes.post.url);
expect(betaPost.nsfw).toBe(postRes.post.nsfw);
// Delta only follows beta, so it should not see an alpha ap_id // Delta only follows beta, so it should not see an alpha ap_id
let searchDelta = await searchPost(delta, postRes.post); let searchDelta = await searchPost(delta, postRes.post);

View file

@ -120,8 +120,12 @@ export async function createPost(
community_id: number community_id: number
): Promise<PostResponse> { ): Promise<PostResponse> {
let name = 'A jest test post'; let name = 'A jest test post';
let body = 'Some body';
let url = 'https://google.com/';
let form: PostForm = { let form: PostForm = {
name, name,
url,
body,
auth: api.auth, auth: api.auth,
community_id, community_id,
nsfw: false, nsfw: false,
@ -239,6 +243,19 @@ export async function searchForBetaCommunity(
return api.client.search(form); return api.client.search(form);
} }
export async function searchForCommunity(
api: API,
q: string,
): Promise<SearchResponse> {
// Use short-hand search url
let form: SearchForm = {
q,
type_: SearchType.Communities,
sort: SortType.TopAll,
};
return api.client.search(form);
}
export async function searchForUser( export async function searchForUser(
api: API, api: API,
apShortname: string apShortname: string
@ -369,9 +386,15 @@ export async function createCommunity(
api: API, api: API,
name_: string = randomString(5) name_: string = randomString(5)
): Promise<CommunityResponse> { ): Promise<CommunityResponse> {
let description = 'a sample description';
let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
let form: CommunityForm = { let form: CommunityForm = {
name: name_, name: name_,
title: name_, title: name_,
description,
icon,
banner,
category_id: 1, category_id: 1,
nsfw: false, nsfw: false,
auth: api.auth, auth: api.auth,

View file

@ -1,3 +1,4 @@
jest.setTimeout(120000);
import { import {
alpha, alpha,
beta, beta,

View file

@ -22,6 +22,7 @@ while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8550/api/v1/site')
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8560/api/v1/site')" != "200" ]]; do sleep 1; done while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8560/api/v1/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8570/api/v1/site')" != "200" ]]; do sleep 1; done while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8570/api/v1/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')" != "200" ]]; do sleep 1; done while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')" != "200" ]]; do sleep 1; done
yarn
yarn api-test || true yarn api-test || true
popd popd