]> Untitled Git - lemmy.git/commitdiff
Implement integration test for federation
authorFelix <me@nutomic.com>
Fri, 24 Apr 2020 16:30:31 +0000 (18:30 +0200)
committerFelix <me@nutomic.com>
Fri, 24 Apr 2020 16:30:31 +0000 (18:30 +0200)
.dockerignore
.gitignore
docker/federation-test/run-tests.sh [new file with mode: 0755]
docker/federation/docker-compose.yml
docker/federation/run-federation-test.bash
ui/src/api_tests/api.spec.ts

index 4f186bcde356ed7b50b039337906614751102883..255caf67fed0ec280ea4e62e8dba272871a1d61d 100644 (file)
@@ -3,6 +3,7 @@ ui/node_modules
 server/target
 docker/dev/volumes
 docker/federation/volumes
+docker/federation-test/volumes
 .git
 ansible
 
index 5e9fd40d6d156b03ec276d5f84fdefd186399b8e..236a729eb05f97bf7ade4a0f8a904c491905039f 100644 (file)
@@ -7,6 +7,7 @@ ansible/passwords/
 docker/lemmy_mine.hjson
 docker/dev/env_deploy.sh
 docker/federation/volumes
+docker/federation-test/volumes
 docker/dev/volumes
 
 # local build files
diff --git a/docker/federation-test/run-tests.sh b/docker/federation-test/run-tests.sh
new file mode 100755 (executable)
index 0000000..43e2f90
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+set -e
+
+pushd ../../server/
+cargo build
+popd
+
+sudo docker build ../../ --file ../federation/Dockerfile --tag lemmy-federation:latest
+
+sudo docker-compose --file ../federation/docker-compose.yml --project-directory . up -d
+
+# TODO: need to wait until the instances are initialised
+
+pushd ../../ui
+yarn
+echo "Waiting for Lemmy to start..."
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8540/api/v1/site')" != "200" ]]; do sleep 5; done
+yarn api-test || true
+popd
+
+sudo docker-compose --file ../federation/docker-compose.yml --project-directory . down
+
+sudo rm -r volumes/
index 4f23cdcc276eaf88fbeeb2abecc0d055cd50810e..496e7fa60eaf9799deddce0a868fa34ac5467754 100644 (file)
@@ -7,7 +7,8 @@ services:
       - "8540:8540"
       - "8550:8550"
     volumes:
-      - ./nginx.conf:/etc/nginx/nginx.conf
+      # Hack to make this work from both docker/federation/ and docker/federation-test/
+      - ../federation/nginx.conf:/etc/nginx/nginx.conf
     depends_on:
       - lemmy_alpha
       - pictshare_alpha
index 2c8b681ce3e65e0fe8cdcd3dbc994debffb05903..8486648b38065538f487581d5efe10df2c5eadcd 100755 (executable)
@@ -12,6 +12,6 @@ pushd ../../server/ || exit
 cargo build
 popd || exit
 
-sudo docker build ../../ -f Dockerfile -t lemmy-federation:latest
+sudo docker build ../../ --file Dockerfile -t lemmy-federation:latest
 
 sudo docker-compose up
index 5db9ee64799ab84b218d696578758bf6a9c9386b..07e12ecfe60270d15b45ab37c598ea21cd444d3d 100644 (file)
@@ -3,83 +3,67 @@ import fetch from 'node-fetch';
 import {
   LoginForm,
   LoginResponse,
-  GetPostsForm,
-  GetPostsResponse,
-  CommentForm,
-  CommentResponse,
-  ListingType,
-  SortType,
+  PostForm,
+  PostResponse,
+  SearchResponse,
 } from '../interfaces';
 
-let baseUrl = 'https://test.lemmy.ml';
-let apiUrl = `${baseUrl}/api/v1`;
-let auth: string;
+let lemmyAlphaUrl = 'http://localhost:8540';
+let lemmyBetaUrl = 'http://localhost:8550';
+let lemmyAlphaApiUrl = `${lemmyAlphaUrl}/api/v1`;
+let lemmyBetaApiUrl = `${lemmyBetaUrl}/api/v1`;
+let lemmyAlphaAuth: string;
 
-beforeAll(async () => {
-  console.log('Logging in as test user.');
-  let form: LoginForm = {
-    username_or_email: 'tester',
-    password: 'tester',
-  };
+// Workaround for tests being run before beforeAll() is finished
+// https://github.com/facebook/jest/issues/9527#issuecomment-592406108
+describe('main', () => {
+  beforeAll(async () => {
+    console.log('Logging in as lemmy_alpha');
+    let form: LoginForm = {
+      username_or_email: 'lemmy_alpha',
+      password: 'lemmy',
+    };
 
-  let res: LoginResponse = await fetch(`${apiUrl}/user/login`, {
-    method: 'POST',
-    headers: {
-      'Content-Type': 'application/json',
-    },
-    body: wrapper(form),
-  }).then(d => d.json());
+    let res: LoginResponse = await fetch(`${lemmyAlphaApiUrl}/user/login`, {
+      method: 'POST',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      body: wrapper(form),
+    }).then(d => d.json());
 
-  auth = res.jwt;
-});
-
-test('Get test user posts', async () => {
-  let form: GetPostsForm = {
-    type_: ListingType[ListingType.All],
-    sort: SortType[SortType.TopAll],
-    auth,
-  };
+    lemmyAlphaAuth = res.jwt;
+  });
 
-  let res: GetPostsResponse = await fetch(
-    `${apiUrl}/post/list?type_=${form.type_}&sort=${form.sort}&auth=${auth}`
-  ).then(d => d.json());
+  test('Create test post on alpha and fetch it on beta', async () => {
+    let name = 'A jest test post';
+    let postForm: PostForm = {
+      name,
+      auth: lemmyAlphaAuth,
+      community_id: 2,
+      creator_id: 2,
+      nsfw: false,
+    };
 
-  // console.debug(res);
+    let createResponse: PostResponse = await fetch(`${lemmyAlphaApiUrl}/post`, {
+      method: 'POST',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      body: wrapper(postForm),
+    }).then(d => d.json());
+    expect(createResponse.post.name).toBe(name);
 
-  expect(res.posts[0].id).toBe(2);
-});
+    let searchUrl = `${lemmyBetaApiUrl}/search?q=${createResponse.post.ap_id}&type_=All&sort=TopAll`;
+    let searchResponse: SearchResponse = await fetch(searchUrl, {
+      method: 'GET',
+    }).then(d => d.json());
 
-test('Create test comment', async () => {
-  let content = 'A jest test comment';
-  let form: CommentForm = {
-    post_id: 2,
-    content,
-    auth,
-  };
+    // TODO: check more fields
+    expect(searchResponse.posts[0].name).toBe(name);
+  });
 
-  let res: CommentResponse = await fetch(`${apiUrl}/comment`, {
-    method: 'POST',
-    headers: {
-      'Content-Type': 'application/json',
-    },
-    body: wrapper(form),
-  }).then(d => d.json());
-
-  expect(res.comment.content).toBe(content);
+  function wrapper(form: any): string {
+    return JSON.stringify(form);
+  }
 });
-
-test('adds 1 + 2 to equal 3', () => {
-  let sum = (a: number, b: number) => a + b;
-  expect(sum(1, 2)).toBe(3);
-});
-
-test(`Get ${baseUrl} nodeinfo href`, async () => {
-  let url = `${baseUrl}/.well-known/nodeinfo`;
-  let href = `${baseUrl}/nodeinfo/2.0.json`;
-  let res = await fetch(url).then(d => d.json());
-  expect(res.links.href).toBe(href);
-});
-
-function wrapper(form: any): string {
-  return JSON.stringify(form);
-}