From d4492a573a62a76cc121b65be86e486c0663ae51 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 14 Sep 2020 13:11:28 -0500 Subject: [PATCH] Adding some more tests, some still broken. --- api_tests/src/community.spec.ts | 13 +++++++++++++ api_tests/src/post.spec.ts | 4 ++++ api_tests/src/shared.ts | 23 +++++++++++++++++++++++ api_tests/src/user.spec.ts | 1 + docker/federation/run-tests.sh | 1 + 5 files changed, 42 insertions(+) diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index bd498009a..0a28369d1 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -1,8 +1,10 @@ +jest.setTimeout(120000); import { alpha, beta, setupLogins, searchForBetaCommunity, + searchForCommunity, createCommunity, deleteCommunity, removeCommunity, @@ -21,6 +23,17 @@ test('Create community', async () => { let prevName = communityRes.community.name; let communityRes2 = await createCommunity(alpha, prevName); 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 () => { diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index c2cbad6d5..bf1c2ab30 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -56,6 +56,10 @@ test('Create a post', async () => { expect(betaPost.community_local).toBe(true); expect(betaPost.creator_local).toBe(false); 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 let searchDelta = await searchPost(delta, postRes.post); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index eb4c6da03..1199e8d60 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -120,8 +120,12 @@ export async function createPost( community_id: number ): Promise { let name = 'A jest test post'; + let body = 'Some body'; + let url = 'https://google.com/'; let form: PostForm = { name, + url, + body, auth: api.auth, community_id, nsfw: false, @@ -239,6 +243,19 @@ export async function searchForBetaCommunity( return api.client.search(form); } +export async function searchForCommunity( + api: API, + q: string, +): Promise { + // Use short-hand search url + let form: SearchForm = { + q, + type_: SearchType.Communities, + sort: SortType.TopAll, + }; + return api.client.search(form); +} + export async function searchForUser( api: API, apShortname: string @@ -369,9 +386,15 @@ export async function createCommunity( api: API, name_: string = randomString(5) ): Promise { + 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 = { name: name_, title: name_, + description, + icon, + banner, category_id: 1, nsfw: false, auth: api.auth, diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 909f9a11c..b685e2965 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -1,3 +1,4 @@ +jest.setTimeout(120000); import { alpha, beta, diff --git a/docker/federation/run-tests.sh b/docker/federation/run-tests.sh index 705ba161d..7ac434cf3 100755 --- a/docker/federation/run-tests.sh +++ b/docker/federation/run-tests.sh @@ -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: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 +yarn yarn api-test || true popd