-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
41 lines (34 loc) · 1.33 KB
/
index.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
import * as dotenv from "dotenv";
import { getShortLink } from "./index";
dotenv.config();
test("Should get a unique shorturl without any errors", async () => {
const response = await getShortLink({
username: process.env["YOURLS_USERNAME"]!,
password: process.env["YOURLS_PASSWORD"]!,
serverUrl: process.env["YOURLS_SERVER_URL"]!,
// A uniquely generated url
url: `https://example-${Date.now()}.com`,
});
expect(response).toBeDefined();
expect(response.root.errorCode[0]).toBeFalsy();
expect(response.root.shorturl[0]).toBeDefined();
});
test("Should try for two requests with same url and should contain error for the second while still having the shortened url in response", async () => {
const url = `https://example-${Date.now()}.com`;
const response1 = await getShortLink({
username: process.env["YOURLS_USERNAME"]!,
password: process.env["YOURLS_PASSWORD"]!,
serverUrl: process.env["YOURLS_SERVER_URL"]!,
url,
});
const response2 = await getShortLink({
username: process.env["YOURLS_USERNAME"]!,
password: process.env["YOURLS_PASSWORD"]!,
serverUrl: process.env["YOURLS_SERVER_URL"]!,
url,
});
expect(response1).toBeDefined();
expect(response2).toBeDefined();
expect(response2.root.errorCode[0]).toBeTruthy();
expect(response2.root.shorturl[0]).toBeDefined();
});