]> Untitled Git - lemmy.git/blobdiff - api_tests/src/user.spec.ts
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / api_tests / src / user.spec.ts
index cd1325181b478f5f51e0405ba528e2d69fe5563e..b2083c66c20e0a86386b7c968b6e9037fef8b199 100644 (file)
@@ -1,6 +1,5 @@
 jest.setTimeout(120000);
-import { None } from "@sniptt/monads";
-import { PersonViewSafe } from "lemmy-js-client";
+import { PersonView } from "lemmy-js-client";
 
 import {
   alpha,
@@ -26,43 +25,33 @@ beforeAll(async () => {
 
 let apShortname: string;
 
-function assertUserFederation(
-  userOne: PersonViewSafe,
-  userTwo: PersonViewSafe
-) {
-  expect(userOne.person.name).toBe(userTwo.person.name);
-  expect(userOne.person.display_name.unwrapOr("none")).toBe(
-    userTwo.person.display_name.unwrapOr("none")
-  );
-  expect(userOne.person.bio.unwrapOr("none")).toBe(
-    userTwo.person.bio.unwrapOr("none")
-  );
-  expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
-  expect(userOne.person.avatar.unwrapOr("none")).toBe(
-    userTwo.person.avatar.unwrapOr("none")
-  );
-  expect(userOne.person.banner.unwrapOr("none")).toBe(
-    userTwo.person.banner.unwrapOr("none")
-  );
-  expect(userOne.person.published).toBe(userTwo.person.published);
+function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
+  expect(userOne?.person.name).toBe(userTwo?.person.name);
+  expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
+  expect(userOne?.person.bio).toBe(userTwo?.person.bio);
+  expect(userOne?.person.actor_id).toBe(userTwo?.person.actor_id);
+  expect(userOne?.person.avatar).toBe(userTwo?.person.avatar);
+  expect(userOne?.person.banner).toBe(userTwo?.person.banner);
+  expect(userOne?.person.published).toBe(userTwo?.person.published);
 }
 
 test("Create user", async () => {
   let userRes = await registerUser(alpha);
   expect(userRes.jwt).toBeDefined();
-  alpha.auth = userRes.jwt;
+  alpha.auth = userRes.jwt ?? "";
 
   let site = await getSite(alpha);
   expect(site.my_user).toBeDefined();
-  apShortname = `@${
-    site.my_user.unwrap().local_user_view.person.name
-  }@lemmy-alpha:8541`;
+  if (!site.my_user) {
+    throw "Missing site user";
+  }
+  apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
 });
 
 test("Set some user settings, check that they are federated", async () => {
   await saveUserSettingsFederated(alpha);
-  let alphaPerson = (await resolvePerson(alpha, apShortname)).person.unwrap();
-  let betaPerson = (await resolvePerson(beta, apShortname)).person.unwrap();
+  let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
+  let betaPerson = (await resolvePerson(beta, apShortname)).person;
   assertUserFederation(alphaPerson, betaPerson);
 });
 
@@ -71,37 +60,38 @@ test("Delete user", async () => {
   expect(userRes.jwt).toBeDefined();
   let user: API = {
     client: alpha.client,
-    auth: userRes.jwt,
+    auth: userRes.jwt ?? "",
   };
 
   // make a local post and comment
-  let alphaCommunity = (
-    await resolveCommunity(user, "!main@lemmy-alpha:8541")
-  ).community.unwrap();
+  let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541"))
+    .community;
+  if (!alphaCommunity) {
+    throw "Missing alpha community";
+  }
   let localPost = (await createPost(user, alphaCommunity.community.id))
     .post_view.post;
   expect(localPost).toBeDefined();
-  let localComment = (await createComment(user, localPost.id, None))
-    .comment_view.comment;
+  let localComment = (await createComment(user, localPost.id)).comment_view
+    .comment;
   expect(localComment).toBeDefined();
 
   // make a remote post and comment
-  let betaCommunity = (await resolveBetaCommunity(user)).community.unwrap();
+  let betaCommunity = (await resolveBetaCommunity(user)).community;
+  if (!betaCommunity) {
+    throw "Missing beta community";
+  }
   let remotePost = (await createPost(user, betaCommunity.community.id))
     .post_view.post;
   expect(remotePost).toBeDefined();
-  let remoteComment = (await createComment(user, remotePost.id, None))
-    .comment_view.comment;
+  let remoteComment = (await createComment(user, remotePost.id)).comment_view
+    .comment;
   expect(remoteComment).toBeDefined();
 
   await deleteUser(user);
 
-  expect((await resolvePost(alpha, localPost)).post.isNone()).toBe(true);
-  expect((await resolveComment(alpha, localComment)).comment.isNone()).toBe(
-    true
-  );
-  expect((await resolvePost(alpha, remotePost)).post.isNone()).toBe(true);
-  expect((await resolveComment(alpha, remoteComment)).comment.isNone()).toBe(
-    true
-  );
+  expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
+  expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
+  expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
+  expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
 });