// SPDX-FileCopyrightText: 2023 Aravinth Manivannan // // SPDX-License-Identifier: AGPL-3.0-or-later import Forgejo from "./index"; import authtoken from "../tmp/user1-accesstoken.json"; const forgeoUrl = authtoken["forgejo_url"]; const token = authtoken["sha1"]; const username = authtoken["login"]; const repo = authtoken["repo"]; const api = new Forgejo(forgeoUrl, "owner_user"); api.setTokenAuth(token); test("use authentication without setting it ", () => { const api = new Forgejo(forgeoUrl, "owner_user"); expect(() => api.getTokenAuth()).toThrow(); api.setTokenAuth(token); expect(api.getTokenAuth().getToken()).toBe(token); let headers = api.getTokenAuthHeader(); expect(headers.Authorization).toBe(`token ${token}`); }); test("verify /user API ", async () => { let user = await api.getUser(); expect(user["login"]).toBe(username); }); test("notifications API ", async () => { let notifications = await api.getNotifications(); expect(notifications.length).toBe(5); expect(await api.getNumUnreadNotifications()).toBe(5); let notification = await api.getNotificationThread(notifications[0].id); expect(notification).toEqual(notifications[0]); }); test("issue API ", async () => { let notifications = await api.getNotifications(); let issue = await api.getIssue(username, repo, 1); let notification = notifications.find((n) => { if (n.subject.html_url == issue.html_url) { return n; } }); expect(notification.subject.type).toEqual("Issue"); expect(issue.title).toEqual(notification.subject.title); expect(issue.lazy_comments_data).toBeUndefined(); expect(issue.created_at instanceof Date).toBe(true); expect(issue.updated_at instanceof Date).toBe(true); if (issue.closed_at) { // TODO: add issue closing functionality in integration/forgejo.py and verify this expect(issue.closed_at instanceof Date).toBe(true); } // expect(typeof(issue.created_at)).toBe('Date'); }); test("comments API ", async () => { let notifications = await api.getNotifications(); let issue = await api.getIssue(username, repo, 1); issue = await api.getCommentsForIssue(issue); expect(issue.lazy_comments_data.length).toBe(2); issue.lazy_comments_data?.forEach((comment) => { expect(comment.created_at instanceof Date).toBe(true); expect(comment.updated_at instanceof Date).toBe(true); }); }); test("mentions in issue", async () => { expect(await api.findMentionsInIssue(username, repo, 1)).toBe(true); expect(await api.findMentionsInIssue(username, repo, 2)).toBe(true); expect(await api.findMentionsInIssue(username, repo, 3)).toBe(true); expect(await api.findMentionsInIssue(username, repo, 4)).toBe(true); expect(await api.findMentionsInIssue(username, repo, 5)).toBe(false); });