-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgenerateRequestUrl.test.ts
34 lines (28 loc) · 1.64 KB
/
generateRequestUrl.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
import { test, expect } from "vitest";
import { generateRequestUrl } from "../src/generateRequestUrl";
test("Should create request url with default options", () => {
const requestUrl = generateRequestUrl();
expect(requestUrl).toBe(
"https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&source-path=%2F&hl=en&soc-app=1&soc-platform=1&soc-device=1",
);
});
test("Should throw an error for invalid tld", () => {
expect(() => generateRequestUrl({ tld: "@localhost" })).toThrowError(/invalid tld/i);
expect(() => generateRequestUrl({ tld: "123" })).toThrowError(/invalid tld/i);
expect(() => generateRequestUrl({ tld: "a" })).toThrowError(/invalid tld/i);
expect(() => generateRequestUrl({ tld: "com" })).not.toThrowError(/invalid tld/i);
});
test("Should be possible to change tld", () => {
expect(generateRequestUrl()).toEqual(expect.stringContaining("translate.google.com"));
expect(generateRequestUrl({ tld: "ua" })).toEqual(expect.stringContaining("translate.google.ua"));
expect(generateRequestUrl({ tld: "it" })).toEqual(expect.stringContaining("translate.google.it"));
});
test("Should be possible to change hl", () => {
expect(generateRequestUrl()).toEqual(expect.stringContaining("hl=en"));
expect(generateRequestUrl({ hl: "it" })).toEqual(expect.stringContaining("hl=it"));
expect(generateRequestUrl({ hl: "eu" })).toEqual(expect.stringContaining("hl=eu"));
});
test("Should be possible to change rpcids", () => {
expect(generateRequestUrl()).toEqual(expect.stringContaining("rpcids=MkEWBc"));
expect(generateRequestUrl({ rpcids: "TEST_rpsid" })).toEqual(expect.stringContaining("rpcids=TEST_rpsid"));
});