-
Notifications
You must be signed in to change notification settings - Fork 50
/
KintoneRestAPIClient.test.ts
104 lines (98 loc) · 3.13 KB
/
KintoneRestAPIClient.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
102
103
104
import { KintoneRestAPIClient } from "../KintoneRestAPIClient";
import { injectPlatformDeps } from "../platform";
import * as browserDeps from "../platform/browser";
describe("KintoneRestAPIClient", () => {
describe("constructor", () => {
let originalKintone: any;
let originalLocation: any;
beforeEach(() => {
originalKintone = global.kintone;
originalLocation = global.location;
global.kintone = {
getRequestToken: () => "dummy request token",
};
global.location = {
...global.location,
host: "example.com",
protocol: "https:",
};
});
afterEach(() => {
global.kintone = originalKintone;
global.location = originalLocation;
});
describe("guestSpaceId", () => {
const baseUrl = "https://example.com";
const auth = { apiToken: "foo" };
it("should not throw an error", () => {
const validGuestSpaceIds = [
undefined,
1,
"1",
100,
"100",
1234,
"1234",
];
validGuestSpaceIds.forEach((guestSpaceId) => {
expect(
() => new KintoneRestAPIClient({ baseUrl, auth, guestSpaceId })
).not.toThrow();
});
});
it("should throw an error", () => {
const invalidGuestSpaceIds = ["", null];
invalidGuestSpaceIds.forEach((guestSpaceId) => {
expect(
() =>
// @ts-ignore
new KintoneRestAPIClient({ baseUrl, auth, guestSpaceId })
).toThrow();
});
});
});
describe("Header", () => {
const baseUrl = "https://example.com";
const USERNAME = "user";
const PASSWORD = "password";
const auth = {
username: USERNAME,
password: PASSWORD,
};
it("should use a location object in browser environment if baseUrl param is not specified", () => {
injectPlatformDeps(browserDeps);
const client = new KintoneRestAPIClient();
expect(client.getBaseUrl()).toBe("https://example.com");
});
it("should remove trailing slash from baseUrl", () => {
const baseUrlWithTrailingSlash = "https://example.com/";
const client = new KintoneRestAPIClient({
baseUrl: baseUrlWithTrailingSlash,
auth,
});
expect(client.getBaseUrl()).toBe("https://example.com");
});
it("should raise an error in Node.js environment if baseUrl param is not specified", () => {
expect(() => new KintoneRestAPIClient({ auth })).toThrow(
"in Node.js environment, baseUrl is required"
);
});
it("should raise an error if trying to use session auth in Node.js environment", () => {
expect(() => {
new KintoneRestAPIClient({
baseUrl,
});
}).toThrow(
"session authentication is not supported in Node.js environment."
);
});
});
});
describe("version", () => {
it("should provide this library version", () => {
expect(KintoneRestAPIClient.version).toBe(
require("../../package.json").version
);
});
});
});