Aravinth Manivannan
d43f1d29ca
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
87 lines
3 KiB
TypeScript
87 lines
3 KiB
TypeScript
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
//
|
|
// 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);
|
|
|
|
test("use authentication without setting it ", async () => {
|
|
await 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 () => {
|
|
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);
|
|
});
|