2023-09-18 20:43:58 +05:30
|
|
|
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
import Forgejo from "./index";
|
2023-09-18 22:30:02 +05:30
|
|
|
import authtoken from "../tmp/user1-accesstoken.json";
|
2023-09-18 17:56:40 +05:30
|
|
|
|
2023-09-18 22:15:11 +05:30
|
|
|
const forgeoUrl = authtoken["forgejo_url"];
|
2023-09-18 19:06:17 +05:30
|
|
|
const token = authtoken["sha1"];
|
|
|
|
const username = authtoken["login"];
|
2023-09-18 20:28:09 +05:30
|
|
|
const repo = authtoken["repo"];
|
2023-09-19 03:36:40 +05:30
|
|
|
const api = new Forgejo(forgeoUrl);
|
2023-09-18 19:06:17 +05:30
|
|
|
|
2023-09-19 03:36:40 +05:30
|
|
|
test("use authentication without setting it ", async () => {
|
|
|
|
await api.setTokenAuth(token);
|
2023-09-18 19:06:17 +05:30
|
|
|
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);
|
2023-09-18 17:56:40 +05:30
|
|
|
});
|
2023-09-18 20:28:09 +05:30
|
|
|
|
|
|
|
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);
|
2023-09-19 00:01:50 +05:30
|
|
|
let notification = notifications.find((n) => {
|
|
|
|
if (n.subject.html_url == issue.html_url) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
});
|
2023-09-19 01:33:45 +05:30
|
|
|
expect(notification.subject.type).toEqual("Issue");
|
|
|
|
expect(issue.title).toEqual(notification.subject.title);
|
2023-09-18 20:28:09 +05:30
|
|
|
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 () => {
|
2023-09-19 05:45:35 +05:30
|
|
|
let issue = await api.getIssue(username, repo, 1);
|
|
|
|
issue = await api.getCommentsForIssue(issue);
|
|
|
|
expect(await api.findMentionsInIssue(issue)).toBe(true);
|
|
|
|
|
|
|
|
issue = await api.getIssue(username, repo, 2);
|
|
|
|
issue = await api.getCommentsForIssue(issue);
|
|
|
|
expect(await api.findMentionsInIssue(issue)).toBe(true);
|
|
|
|
|
|
|
|
issue = await api.getIssue(username, repo, 3);
|
|
|
|
issue = await api.getCommentsForIssue(issue);
|
|
|
|
expect(await api.findMentionsInIssue(issue)).toBe(true);
|
|
|
|
|
|
|
|
issue = await api.getIssue(username, repo, 4);
|
|
|
|
issue = await api.getCommentsForIssue(issue);
|
|
|
|
expect(await api.findMentionsInIssue(issue)).toBe(true);
|
|
|
|
|
|
|
|
issue = await api.getIssue(username, repo, 5);
|
|
|
|
issue = await api.getCommentsForIssue(issue);
|
|
|
|
expect(await api.findMentionsInIssue(issue)).toBe(false);
|
2023-09-18 20:28:09 +05:30
|
|
|
});
|