-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAppBaseClientTest.js
More file actions
145 lines (143 loc) · 4.63 KB
/
AppBaseClientTest.js
File metadata and controls
145 lines (143 loc) · 4.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const appbase = require("..");
const { uuidv4 } = require("../__mocks__");
describe("#AppBase_Client", () => {
test("should create appbase client", () => {
const client = appbase({
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(client).toEqual({
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
protocol: "https",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
});
test("should throw url missing error", () => {
try {
appbase({
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual("URL not present in options.");
}
});
test("should throw app missing error", () => {
try {
appbase({
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual("App name is not present in options.");
}
});
test("should throw protocol missing error", () => {
try {
appbase({
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual(
"Protocol is not present in url. URL should be of the form https://appbase-demo-ansible-abxiydt-arc.searchbase.io"
);
}
});
test("should throw credentials missing error", () => {
try {
appbase({
url: "https://scalr.api.appbase.io",
app: "appbasejs-test-app",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual(
"Authentication information is not present. Did you add credentials?"
);
}
});
test("should set headers", () => {
const client = appbase({
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
client.setHeaders({
authorization: "test-authorize",
"x-search-key": "美女",
});
expect(client).toEqual({
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
protocol: "https",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
headers: {
authorization: "test-authorize",
"x-search-key": "美女",
},
});
});
test("should set X-Enable-Telemetry header", () => {
const client = appbase({
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
enableTelemetry: false,
});
expect(client).toEqual({
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
protocol: "https",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
enableTelemetry: false,
});
});
test("should call transformRequest before fetch", async () => {
const client = appbase({
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
client.transformRequest = (request) => {
expect(true).toBe(true);
return request;
};
const id = uuidv4();
const tweet = {
user: "olivere",
message: "Welcome to Golang and Elasticsearch.",
};
client.index({
type: "tweet_transform_error",
id,
body: tweet,
});
});
test("should create appbase client with mongodb", () => {
const client = appbase({
url: "https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/public-demo-skxjb/service/http_endpoint/incoming_webhook/reactivesearch",
app: "appbasejs-test-app",
mongodb: {
db: "test_db",
collection: "test_collection",
},
});
expect(client).toEqual({
url: "https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/public-demo-skxjb/service/http_endpoint/incoming_webhook/reactivesearch",
protocol: "https",
credentials: null,
app: "appbasejs-test-app",
mongodb: {
db: "test_db",
collection: "test_collection",
},
});
});
});