-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.js
54 lines (47 loc) · 1.88 KB
/
basic.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
const assert = require('assert')
const UnityAuthenticationClient = require('unity-package-authentication').UnityAuthenticationClient
const UnitySearchClient = require('../').UnitySearchClient
const testCreds = require('unity-package-authentication/test/constants')
describe('UnityDownloadClient', () => {
it('should construct', () => {
new UnitySearchClient('')
new UnitySearchClient(new UnityAuthenticationClient())
new UnitySearchClient('', '')
new UnitySearchClient('', '', '')
})
it('should reformat apiRoot if needed', () => {
const client = new UnitySearchClient('', '', 'pie/')
assert.equal(client.apiRoot, 'pie')
})
it('should search anonymously', (done) => {
new UnitySearchClient()
.search('32351')
.then((results) => {
assert.ok(results.length > 0)
done()
}, done)
}).timeout(5000)
it('should search authenticated', (done) => {
new UnityAuthenticationClient()
// see https://github.com/bengreenier/unity-package-authentication/blob/master/test/basic.js#L22
.authenticate(testCreds.testUsername, testCreds.testPassword)
.then((sessionId) => {
return new UnitySearchClient(sessionId)
}).then((client) => {
// this only works so long as this package exists
// see https://www.assetstore.unity3d.com/en/#!/content/32351
return client.search('32351')
}).then((results) => {
assert.ok(results.length > 0)
done()
}, done)
}).timeout(5000)
it('should do lookups', (done) => {
new UnitySearchClient()
.lookup(32351)
.then((data) => {
assert.ok(data.id != null)
done()
}, done)
}).timeout(5000)
})