mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-30 00:01:25 +00:00
Merge remote-tracking branch 'yerba/federation' into federation_changes_1
This commit is contained in:
commit
33c5c21a57
6 changed files with 86 additions and 76 deletions
1
.dockerignore
vendored
1
.dockerignore
vendored
|
@ -3,6 +3,7 @@ ui/node_modules
|
||||||
server/target
|
server/target
|
||||||
docker/dev/volumes
|
docker/dev/volumes
|
||||||
docker/federation/volumes
|
docker/federation/volumes
|
||||||
|
docker/federation-test/volumes
|
||||||
.git
|
.git
|
||||||
ansible
|
ansible
|
||||||
|
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@ ansible/passwords/
|
||||||
docker/lemmy_mine.hjson
|
docker/lemmy_mine.hjson
|
||||||
docker/dev/env_deploy.sh
|
docker/dev/env_deploy.sh
|
||||||
docker/federation/volumes
|
docker/federation/volumes
|
||||||
|
docker/federation-test/volumes
|
||||||
docker/dev/volumes
|
docker/dev/volumes
|
||||||
|
|
||||||
# local build files
|
# local build files
|
||||||
|
|
23
docker/federation-test/run-tests.sh
vendored
Executable file
23
docker/federation-test/run-tests.sh
vendored
Executable file
|
@ -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/
|
3
docker/federation/docker-compose.yml
vendored
3
docker/federation/docker-compose.yml
vendored
|
@ -7,7 +7,8 @@ services:
|
||||||
- "8540:8540"
|
- "8540:8540"
|
||||||
- "8550:8550"
|
- "8550:8550"
|
||||||
volumes:
|
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:
|
depends_on:
|
||||||
- lemmy_alpha
|
- lemmy_alpha
|
||||||
- pictshare_alpha
|
- pictshare_alpha
|
||||||
|
|
2
docker/federation/run-federation-test.bash
vendored
2
docker/federation/run-federation-test.bash
vendored
|
@ -12,6 +12,6 @@ pushd ../../server/ || exit
|
||||||
cargo build
|
cargo build
|
||||||
popd || exit
|
popd || exit
|
||||||
|
|
||||||
sudo docker build ../../ -f Dockerfile -t lemmy-federation:latest
|
sudo docker build ../../ --file Dockerfile -t lemmy-federation:latest
|
||||||
|
|
||||||
sudo docker-compose up
|
sudo docker-compose up
|
||||||
|
|
96
ui/src/api_tests/api.spec.ts
vendored
96
ui/src/api_tests/api.spec.ts
vendored
|
@ -3,26 +3,28 @@ import fetch from 'node-fetch';
|
||||||
import {
|
import {
|
||||||
LoginForm,
|
LoginForm,
|
||||||
LoginResponse,
|
LoginResponse,
|
||||||
GetPostsForm,
|
PostForm,
|
||||||
GetPostsResponse,
|
PostResponse,
|
||||||
CommentForm,
|
SearchResponse,
|
||||||
CommentResponse,
|
|
||||||
ListingType,
|
|
||||||
SortType,
|
|
||||||
} from '../interfaces';
|
} from '../interfaces';
|
||||||
|
|
||||||
let baseUrl = 'https://test.lemmy.ml';
|
let lemmyAlphaUrl = 'http://localhost:8540';
|
||||||
let apiUrl = `${baseUrl}/api/v1`;
|
let lemmyBetaUrl = 'http://localhost:8550';
|
||||||
let auth: string;
|
let lemmyAlphaApiUrl = `${lemmyAlphaUrl}/api/v1`;
|
||||||
|
let lemmyBetaApiUrl = `${lemmyBetaUrl}/api/v1`;
|
||||||
|
let lemmyAlphaAuth: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
// Workaround for tests being run before beforeAll() is finished
|
||||||
console.log('Logging in as test user.');
|
// https://github.com/facebook/jest/issues/9527#issuecomment-592406108
|
||||||
|
describe('main', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
console.log('Logging in as lemmy_alpha');
|
||||||
let form: LoginForm = {
|
let form: LoginForm = {
|
||||||
username_or_email: 'tester',
|
username_or_email: 'lemmy_alpha',
|
||||||
password: 'tester',
|
password: 'lemmy',
|
||||||
};
|
};
|
||||||
|
|
||||||
let res: LoginResponse = await fetch(`${apiUrl}/user/login`, {
|
let res: LoginResponse = await fetch(`${lemmyAlphaApiUrl}/user/login`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -30,56 +32,38 @@ beforeAll(async () => {
|
||||||
body: wrapper(form),
|
body: wrapper(form),
|
||||||
}).then(d => d.json());
|
}).then(d => d.json());
|
||||||
|
|
||||||
auth = res.jwt;
|
lemmyAlphaAuth = res.jwt;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get test user posts', async () => {
|
test('Create test post on alpha and fetch it on beta', async () => {
|
||||||
let form: GetPostsForm = {
|
let name = 'A jest test post';
|
||||||
type_: ListingType[ListingType.All],
|
let postForm: PostForm = {
|
||||||
sort: SortType[SortType.TopAll],
|
name,
|
||||||
auth,
|
auth: lemmyAlphaAuth,
|
||||||
|
community_id: 2,
|
||||||
|
creator_id: 2,
|
||||||
|
nsfw: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res: GetPostsResponse = await fetch(
|
let createResponse: PostResponse = await fetch(`${lemmyAlphaApiUrl}/post`, {
|
||||||
`${apiUrl}/post/list?type_=${form.type_}&sort=${form.sort}&auth=${auth}`
|
|
||||||
).then(d => d.json());
|
|
||||||
|
|
||||||
// console.debug(res);
|
|
||||||
|
|
||||||
expect(res.posts[0].id).toBe(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Create test comment', async () => {
|
|
||||||
let content = 'A jest test comment';
|
|
||||||
let form: CommentForm = {
|
|
||||||
post_id: 2,
|
|
||||||
content,
|
|
||||||
auth,
|
|
||||||
};
|
|
||||||
|
|
||||||
let res: CommentResponse = await fetch(`${apiUrl}/comment`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: wrapper(form),
|
body: wrapper(postForm),
|
||||||
|
}).then(d => d.json());
|
||||||
|
expect(createResponse.post.name).toBe(name);
|
||||||
|
|
||||||
|
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());
|
}).then(d => d.json());
|
||||||
|
|
||||||
expect(res.comment.content).toBe(content);
|
// TODO: check more fields
|
||||||
});
|
expect(searchResponse.posts[0].name).toBe(name);
|
||||||
|
});
|
||||||
|
|
||||||
test('adds 1 + 2 to equal 3', () => {
|
function wrapper(form: any): string {
|
||||||
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);
|
return JSON.stringify(form);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue