Self-hosted, federated location sharing app and server that prioritizes user privacy and security
end-to-end-encryption
location-sharing
privacy
self-hosted
federated
1import { SERVER_DIR, startOrRestartServer, stopServer } from "./srv.ts";
2import { rm } from "node:fs/promises";
3import { describe, test, expect, beforeAll, afterAll, beforeEach } from "bun:test";
4import { generateUser, post, URL } from "./utils.ts";
5
6console.log(`SERVER_DIR: ${SERVER_DIR}`);
7let signup_key: string | undefined = undefined;
8
9beforeEach(async () => {
10 signup_key = await startOrRestartServer();
11 await Bun.sleep(100);
12});
13
14afterAll(async () => {
15 stopServer();
16});
17
18describe("API tests", () => {
19 test("Main usage test", async () => {
20 const admin = await generateUser(signup_key, true);
21
22 const res1 = await post("generate-signup-key", admin, undefined);
23 expect(res1).toEqual(expect.any(String));
24
25 const user = await generateUser(res1);
26
27 await post("create-friend-request", admin, user.user_id);
28
29 await post("accept-friend-request", user, admin.user_id);
30
31 const res2 = await post("is-friend-request-accepted", admin, user.user_id);
32 expect(JSON.parse(res2)).toBe(true);
33
34 await post("send-pings", admin, [
35 {
36 receiver_id: user.user_id,
37 encrypted_ping: "this is definitely encrypted trust #1",
38 },
39 ]);
40
41 await post("send-pings", admin, [
42 {
43 receiver_id: user.user_id,
44 encrypted_ping: "this is definitely encrypted trust #2",
45 },
46 ]);
47
48 const res3 = await post("get-pings", user, admin.user_id);
49
50 expect(JSON.parse(res3)).toEqual(["this is definitely encrypted trust #2", "this is definitely encrypted trust #1"]);
51 });
52});