forked from jsforce/jsforce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection-meta.test.js
299 lines (273 loc) · 9.08 KB
/
connection-meta.test.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*global describe, it, before, after */
var TestEnv = require('./helper/testenv'),
assert = TestEnv.assert;
var async = require('async'),
_ = require('lodash/core'),
sf = require('../lib/jsforce'),
config = require('./config/salesforce');
var testEnv = new TestEnv(config);
/**
*
*/
describe("connection-meta", function() {
this.timeout(40000); // set timeout to 40 sec.
var conn = testEnv.createConnection();
/**
*
*/
before(function(done) {
this.timeout(600000); // set timeout to 10 min.
testEnv.establishConnection(conn, done);
});
/**
*
*/
describe("describe Account", function() {
it("should return metadata information", function(done) {
conn.sobject('Account').describe(function(err, meta) {
if (err) { throw err; }
assert.ok(meta.name === "Account");
assert.ok(_.isArray(meta.fields));
}.check(done));
});
describe("then describe cached Account", function() {
it("should return metadata information", function(done) {
conn.sobject('Account').describe$(function(err, meta) {
if (err) { throw err; }
assert.ok(meta.name === "Account");
assert.ok(_.isArray(meta.fields));
}.check(done));
});
});
});
/**
*
*/
describe("describe global sobjects", function() {
it("should return whole global sobject list", function(done) {
conn.describeGlobal(function(err, res) {
if (err) { throw err; }
assert.ok(_.isArray(res.sobjects));
assert.ok(_.isString(res.sobjects[0].name));
assert.ok(_.isString(res.sobjects[0].label));
assert.ok(_.isUndefined(res.sobjects[0].fields));
}.check(done));
});
describe("then describe cached global sobjects", function() {
it("should return whole global sobject list", function(done) {
conn.describeGlobal$(function(err, res) {
if (err) { throw err; }
assert.ok(_.isArray(res.sobjects));
assert.ok(_.isString(res.sobjects[0].name));
assert.ok(_.isString(res.sobjects[0].label));
assert.ok(_.isUndefined(res.sobjects[0].fields));
}.check(done));
});
});
});
/**
*
*/
describe("get recently accessed records", function() {
before(function(done) {
conn.query("SELECT Id, Name FROM Account ORDER BY CreatedDate DESC LIMIT 2 FOR VIEW", function(err) {
if (err) { throw err; }
}.check(done));
});
it("should return recently viewed records in all object", function(done) {
conn.recent(2, function(err, records) {
if (err) { throw err; }
assert(_.isArray(records));
records.forEach(function(record) {
assert(_.isString(record.Id));
assert(_.isString(record.Name));
assert(_.isString(record.attributes.type));
assert(record.attributes.type === 'Account');
});
}.check(done));
});
it("should return recently viewed accounts in Account object", function(done) {
conn.sobject('Account').recent(function(err, records) {
if (err) { throw err; }
assert(_.isArray(records));
records.forEach(function(record) {
assert(_.isString(record.Id));
assert(_.isString(record.Name));
assert(_.isString(record.attributes.type));
assert(record.attributes.type === 'Account');
});
}.check(done));
});
});
/**
*
*/
describe("get updated / deleted account", function () {
before(function(done) {
var accs = [{ Name: 'Hello' }, { Name: 'World' }];
conn.sobject('Account').create(accs, function(err, rets) {
if (err) { throw err; }
var id1 = rets[0].id, id2 = rets[1].id;
async.parallel([
function(cb) {
conn.sobject('Account').record(id1).update({ Name: "Hello2" }, cb);
},
function(cb) {
conn.sobject('Account').record(id2).destroy(cb);
}
], function (err, ret) {
if (err) { throw err; }
}.check(done));
});
});
/**
*
*/
describe("get updated accounts", function () {
it("should return updated account object", function (done) {
var end = new Date();
var start = new Date(end.getTime() - 1 * 24 * 60 * 60 * 1000); // 1 day before
conn.sobject('Account').updated(start, end, function (err, result) {
if (err) { throw err; }
assert.ok(_.isArray(result.ids));
}.check(done));
});
});
/**
*
*/
describe("get updated account with string input", function () {
it("should return updated account object", function (done) {
var end = new Date();
var start = new Date(end.getTime() - 1 * 24 * 60 * 60 * 1000); // 1 day before
conn.sobject('Account').updated(start.toString(), end.toString(), function (err, result) {
if (err) { throw err; }
assert.ok(_.isArray(result.ids));
}.check(done));
});
});
/**
*
*/
describe("get deleted account", function () {
it("should return deleted account object", function (done) {
var end = new Date();
var start = new Date(end.getTime() - 1 * 24 * 60 * 60 * 1000); // 1 day before
conn.sobject('Account').deleted(start, end, function (err, result) {
if (err) { throw err; }
assert.ok(_.isArray(result.deletedRecords));
}.check(done));
});
});
/**
*
*/
describe("get deleted account with string input", function () {
it("should return deleted account object", function (done) {
var end = new Date();
var start = new Date(end.getTime() - 1 * 24 * 60 * 60 * 1000); // 1 day before
conn.sobject('Account').deleted(start.toString(), end.toString(), function (err, result) {
if (err) { throw err; }
assert.ok(_.isArray(result.deletedRecords));
}.check(done));
});
});
});
/**
*
*/
describe("get user identity information", function() {
it("should return user identity information", function (done) {
conn.identity(function(err, res) {
if (err) { throw err; }
assert.ok(_.isString(res.id));
assert.ok(res.id.indexOf('https://') === 0);
assert.ok(_.isString(res.user_id));
assert.ok(_.isString(res.organization_id));
assert.ok(_.isString(res.email));
assert.ok(_.isObject(res.photos));
assert.ok(_.isObject(res.urls));
}.check(done));
});
});
/**
*
*/
describe("get api limit information", function() {
it("should get api usage and its limit in the org", function() {
var limitInfo = conn.limitInfo;
assert.ok(_.isObject(limitInfo.apiUsage));
assert.ok(_.isNumber(limitInfo.apiUsage.used));
assert.ok(_.isNumber(limitInfo.apiUsage.limit));
assert.ok(limitInfo.apiUsage.used > 0);
assert.ok(limitInfo.apiUsage.limit >= limitInfo.apiUsage.used);
});
});
/**
*
*/
describe("get tabs list information", function() {
it("should get tabs info in the org", function(done) {
conn.tabs(function(err, tabs) {
assert.ok(_.isArray(tabs));
tabs.forEach(function(tab) {
assert.ok(_.isString(tab.label));
assert.ok(_.isString(tab.name));
assert.ok(_.isString(tab.url));
});
}.check(done));
});
});
/**
*
*/
describe("get system limits information", function() {
it("should get limit info in the org", function(done) {
conn.limits(function(err, limits) {
assert.ok(_.isObject(limits));
assert.ok(_.isObject(limits.DataStorageMB));
assert.ok(limits.DataStorageMB.Remaining >= 0);
assert.ok(limits.DataStorageMB.Max > 0);
assert.ok(_.isObject(limits.FileStorageMB));
assert.ok(limits.FileStorageMB.Remaining >= 0);
assert.ok(limits.FileStorageMB.Max > 0);
assert.ok(_.isObject(limits.DailyApiRequests));
assert.ok(limits.DailyApiRequests.Remaining >= 0);
assert.ok(limits.DailyApiRequests.Max > 0);
}.check(done));
});
});
/**
*
*/
describe("get theme information", function() {
it("should get theme info in the org", function(done) {
conn.theme(function(err, theme) {
assert.ok(_.isObject(theme));
assert.ok(_.isArray(theme.themeItems));
theme.themeItems.forEach(function(t) {
assert.ok(_.isString(t.name));
assert.ok(_.isArray(t.colors) || t.colors === null);
(t.colors || []).forEach(function(c) {
assert.ok(_.isString(c.color));
assert.ok(_.isString(c.context));
assert.ok(_.isString(c.theme));
});
assert.ok(_.isArray(t.icons) || t.icons === null);
(t.icons || []).forEach(function(ic) {
assert.ok(_.isString(ic.url));
assert.ok(_.isNumber(ic.width));
assert.ok(_.isNumber(ic.height));
assert.ok(_.isString(ic.contentType));
});
});
}.check(done));
});
});
/**
*
*/
after(function(done) {
testEnv.closeConnection(conn, done);
});
});