tests in typescript
This commit is contained in:
73
back/test/test-utils/test-attrsUtils.ts
Normal file
73
back/test/test-utils/test-attrsUtils.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { AttrsWithEnvelope, User } from "../../interfaces/mail/attrs.interface";
|
||||
import names from "./names";
|
||||
|
||||
interface Options {
|
||||
subject?: string;
|
||||
from?: User[];
|
||||
sender?: User[];
|
||||
replyTo?: User[];
|
||||
to?: User[];
|
||||
cc?: User[];
|
||||
bcc?: User[];
|
||||
inReplyTo?: string;
|
||||
messageId?: string;
|
||||
date?: string;
|
||||
flags?: string[];
|
||||
uid?: number;
|
||||
modseq?: number;
|
||||
}
|
||||
|
||||
export function generateAttrs(options: Options): AttrsWithEnvelope {
|
||||
const attrs = {
|
||||
"size": 42,
|
||||
"envelope": {
|
||||
date: "2023-03-21T15:25:42.000Z",
|
||||
subject: options.subject ?? "subject" + randomString(10),
|
||||
from: options.from ?? undefined,
|
||||
sender: options.sender ?? undefined,
|
||||
replyTo: options.replyTo ?? undefined,
|
||||
to: options.to ?? undefined,
|
||||
cc: options.cc ?? undefined,
|
||||
bcc: options.bcc ?? undefined,
|
||||
inReplyTo: options.inReplyTo ?? undefined,
|
||||
messageId: options.messageId ?? randomString(10),
|
||||
},
|
||||
"date": options.date ?? new Date().toDateString(),
|
||||
"flags": options.flags ?? [],
|
||||
"uid": options.uid ?? randomInt(3),
|
||||
"modseq": options.modseq ?? randomInt(7),
|
||||
"x-gm-labels": ["\\Inbox"],
|
||||
"x-gm-msgid": "1760991478422670209",
|
||||
"x-gm-thrid": "1760991478422670209",
|
||||
};
|
||||
return attrs;
|
||||
}
|
||||
|
||||
export function generateUsers(nb: number) {
|
||||
const users: {user: User, id: number}[] = [];
|
||||
for (let i = 0; i < nb; i++) {
|
||||
users.push({
|
||||
user: {
|
||||
name: "",
|
||||
mailbox: names[i],
|
||||
host: "provider.com",
|
||||
},
|
||||
id: i,
|
||||
});
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
function randomString(length: number): string {
|
||||
let result = "";
|
||||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const charactersLength = characters.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function randomInt(length: number): number {
|
||||
return parseInt((Math.random() * Math.pow(10, length)).toFixed());
|
||||
}
|
||||
Reference in New Issue
Block a user