forgejo-notifications-core/src/api.test.ts

24 lines
743 B
TypeScript
Raw Normal View History

2023-09-18 17:56:40 +05:30
import Forgejo from "./api";
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 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 () => {
const api = new Forgejo("http://localhost:3000", "owner_user");
api.setTokenAuth(token);
let user = await api.getUser();
console.log(user);
expect(user["login"]).toBe(username);
2023-09-18 17:56:40 +05:30
});