Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
api = require('./apitest')
2
{setup, teardown} = api
3
misc = require('smc-util/misc')
4
expect = require('expect')
5
6
describe 'tests creating an auth token via the api -- ', ->
7
before(setup)
8
after(teardown)
9
10
account_id2 = undefined
11
12
it "uses api call to create a second account", (done) ->
13
api.call
14
event : 'create_account'
15
body :
16
first_name : "Sage2"
17
last_name : "CoCalc2"
18
email_address : "[email protected]"
19
password : "1234qwerty"
20
agreed_to_terms : true
21
cb : (err, resp) ->
22
expect(resp?.event).toBe('account_created')
23
expect(misc.is_valid_uuid_string(resp?.account_id)).toBe(true)
24
account_id2 = resp?.account_id
25
done(err)
26
27
auth_token = undefined
28
it "obtains an auth token for the second account", (done) ->
29
api.call
30
event : 'user_auth'
31
body :
32
account_id : account_id2
33
password : "1234qwerty"
34
cb : (err, resp) ->
35
if err
36
done(err); return
37
expect(resp.event).toBe('user_auth_token')
38
expect(resp.auth_token.length).toBe(24)
39
auth_token = resp.auth_token
40
done()
41
42
it "check in the database that the token would work", (done) ->
43
api.db.get_auth_token_account_id
44
auth_token : auth_token
45
cb : (err, account_id) ->
46
if err
47
done(err)
48
else
49
expect(account_id).toBe(account_id2)
50
done()
51
52
53