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 17:56:40 +05:30
|
|
|
import authtoken from "../secrets/user1-accesstoken.json";
|
|
|
|
|
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"];
|
|
|
|
const api = new Forgejo("http://localhost:3000", "owner_user");
|
|
|
|
api.setTokenAuth(token);
|
2023-09-18 19:06:17 +05:30
|
|
|
|
2023-09-18 17:56:40 +05:30
|
|
|
test("use authentication without setting it ", () => {
|
|
|
|
const api = new Forgejo("http://localhost:3000", "owner_user");
|
|
|
|
|
|
|
|
expect(() => api.getTokenAuth()).toThrow();
|
2023-09-18 19:06:17 +05:30
|
|
|
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);
|
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);
|
|
|
|
expect(notifications[0].subject.type).toEqual("Issue");
|
|
|
|
expect(issue.title).toEqual(notifications[0].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);
|
|
|
|
});
|