-
Notifications
You must be signed in to change notification settings - Fork 4
/
batch_get.spec.js
49 lines (39 loc) · 1.73 KB
/
batch_get.spec.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
/* eslint-env jest */
import RingCentral from '../src/ringcentral'
import { maxBy, reduce } from 'ramda'
import multipartMixedParser from 'multipart-mixed-parser'
jest.setTimeout(64000)
const rc = new RingCentral(process.env.RINGCENTRAL_CLIENT_ID, process.env.RINGCENTRAL_CLIENT_SECRET, process.env.RINGCENTRAL_SERVER_URL)
describe('ringcentral', () => {
test('batch get', async () => {
await rc.authorize({
username: process.env.RINGCENTRAL_USERNAME,
extension: process.env.RINGCENTRAL_EXTENSION,
password: process.env.RINGCENTRAL_PASSWORD
})
let r = await rc.get('/restapi/v1.0/glip/groups')
const group = reduce(maxBy(g => g.members.length), { members: [] }, r.data.records)
// console.log(group)
r = await rc.get(`/restapi/v1.0/glip/persons/${group.members.join(',')}`)
const data = multipartMixedParser.parse(r.data)
const persons = data.splice(1) // first element in data is response status
expect(persons.length > 0).toBe(true)
// console.log(JSON.stringify(persons, null, 2))
await rc.revoke()
})
test('simple version', async () => {
await rc.authorize({
username: process.env.RINGCENTRAL_USERNAME,
extension: process.env.RINGCENTRAL_EXTENSION,
password: process.env.RINGCENTRAL_PASSWORD
})
const r = await rc.get('/restapi/v1.0/glip/groups')
// find the group with the most members
const group = reduce(maxBy(g => g.members.length), { members: [] }, r.data.records)
expect(group.members.length).toBeGreaterThan(1)
const persons = await rc.batchGet('/restapi/v1.0/glip/persons', group.members, 2)
expect(persons.length).toBe(group.members.length)
expect(persons.map(p => p.id)).toEqual(group.members)
await rc.revoke()
})
})