-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbasehub.test.ts
More file actions
50 lines (45 loc) · 1.63 KB
/
basehub.test.ts
File metadata and controls
50 lines (45 loc) · 1.63 KB
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
import { assertEquals } from "jsr:@std/assert";
import { transform } from "./basehub.ts";
const img =
"https://assets.basehub.com/fa068a12/qZeFxPJWNB7UQdwUzjX3e/features-streamlined-team-communication-real-time-messaging-(light-mode)3x.jpg";
Deno.test("basehub", async (t) => {
await t.step("should format a URL", () => {
const result = transform({
url: img,
width: 200,
height: 100,
});
assertEquals(
result?.toString(),
"https://assets.basehub.com/fa068a12/qZeFxPJWNB7UQdwUzjX3e/features-streamlined-team-communication-real-time-messaging-(light-mode)3x.jpg?w=200&h=100",
);
});
await t.step("should not set height if not provided", () => {
const result = transform({ url: img, width: 200 });
assertEquals(
result?.toString(),
"https://assets.basehub.com/fa068a12/qZeFxPJWNB7UQdwUzjX3e/features-streamlined-team-communication-real-time-messaging-(light-mode)3x.jpg?w=200",
);
});
await t.step("should delete height if not set", () => {
const url = new URL(img);
url.searchParams.set("h", "100");
const result = transform({ url, width: 200 });
assertEquals(
result?.toString(),
"https://assets.basehub.com/fa068a12/qZeFxPJWNB7UQdwUzjX3e/features-streamlined-team-communication-real-time-messaging-(light-mode)3x.jpg?w=200",
);
});
await t.step("should round non-integer params", () => {
const result = transform({
url: img,
width: 200.6,
height: 100.2,
format: "webp",
});
assertEquals(
result?.toString(),
"https://assets.basehub.com/fa068a12/qZeFxPJWNB7UQdwUzjX3e/features-streamlined-team-communication-real-time-messaging-(light-mode)3x.jpg?w=201&h=100&format=webp",
);
});
});