This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
generated from NuroDev/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.test.ts
101 lines (88 loc) · 2.58 KB
/
analytics.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { describe, it, expect, beforeAll } from "vitest";
import "dotenv/config";
import {
activityByCountry,
activityByDate,
activityByReadingEnvironment,
activityByUserAgent,
} from ".";
const { MAILERSEND_API_KEY } = process.env as Record<string, string>;
const getCurrentUTC = (): number => Math.floor(new Date().getTime() / 1000);
describe("Analytics", () => {
beforeAll(() => {
if (!MAILERSEND_API_KEY)
throw "No MailerSend API key found in environment variables";
});
it.concurrent("Activity By Country", async () => {
try {
const activityByCountryResponse = await activityByCountry(
MAILERSEND_API_KEY,
{
date_from: getCurrentUTC() - 200,
date_to: getCurrentUTC(),
}
);
expect(activityByCountryResponse).not.toBeNull();
expect(activityByCountryResponse.data).toBeDefined();
} catch (error) {
console.error(error);
throw error;
}
});
it.concurrent("Activity By Date", async () => {
try {
const activityByDateResponse = await activityByDate(MAILERSEND_API_KEY, {
date_from: getCurrentUTC() - 200,
date_to: getCurrentUTC(),
event: [
"clicked",
"delivered",
"hard_bounced",
"junk",
"opened",
"processed",
"queued",
"sent",
"soft_bounced",
"spam_complaints",
"unsubscribed",
],
});
expect(activityByDateResponse).not.toBeNull();
expect(activityByDateResponse.data).toBeDefined();
} catch (error) {
console.error(error);
throw error;
}
});
it.concurrent("Activity By Reading Environment", async () => {
try {
const activityByReadingEnvironmentResponse =
await activityByReadingEnvironment(MAILERSEND_API_KEY, {
date_from: getCurrentUTC() - 200,
date_to: getCurrentUTC(),
});
expect(activityByReadingEnvironmentResponse).not.toBeNull();
expect(activityByReadingEnvironmentResponse.data).toBeDefined();
} catch (error) {
console.error(error);
throw error;
}
});
it.concurrent("Activity By User-Agent", async () => {
try {
const activityUserAgentResponse = await activityByUserAgent(
MAILERSEND_API_KEY,
{
date_from: getCurrentUTC() - 200,
date_to: getCurrentUTC(),
}
);
expect(activityUserAgentResponse).not.toBeNull();
expect(activityUserAgentResponse.data).toBeDefined();
} catch (error) {
console.error(error);
throw error;
}
});
});