forgejo-frontend-integration/tests/maildev.ts
Aravinth Manivannan b09d5ce6c4
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
feat: get activation link from maildev
2024-01-10 20:43:37 +05:30

27 lines
694 B
TypeScript

import * as config from "./config";
export const getEmails = async (toAddr: string) => {
const url = new URL(config.MAILDEV_URL);
url.pathname = "/email";
let res = await fetch(url);
let data = await res.json();
let mails = [];
Array.from(data).forEach((mail: any) => {
if (mail.to[0].address == toAddr) {
mails.push(mail);
}
});
return mails;
};
export const getActivationLink = async (
toAddr: string
): Promise<string | void> => {
let emails = await getEmails(toAddr);
for (let i = 0; i < emails.length; i++) {
let mail = emails[i];
if (mail.subject.includes("Please activate your account")) {
return mail.text.split('\n')[4]
}
}
};