-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMarketplaceAPIAuth.test.ts
58 lines (48 loc) · 1.81 KB
/
MarketplaceAPIAuth.test.ts
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
import { assert } from 'chai'
import config from '../../test/config'
import { Nevermined } from '../../src/nevermined/Nevermined'
import { NvmAccount } from '../../src/models/NvmAccount'
import Logger from '../../src/models/Logger'
describe('Marketplace api auth', () => {
let nevermined: Nevermined
let account1: NvmAccount
let account2: NvmAccount
let testConfig
before(async () => {
try {
localStorage.clear()
} catch (error) {
Logger.debug(error)
}
const numAccounts = config.accounts.length
testConfig = { ...config }
testConfig.accounts = [config.accounts[numAccounts - 1], config.accounts[numAccounts - 2]]
// testConfig.accounts = makeRandomAccounts(3)
testConfig.marketplaceAuthToken = undefined
nevermined = await Nevermined.getInstance(testConfig)
// Accounts
;[account1, account2] = nevermined.accounts.list()
})
it('should login in marketplace API', async () => {
const clientAssertion = await nevermined.utils.jwt.generateClientAssertion(account1)
try {
await nevermined.services.marketplace.login(clientAssertion)
assert.equal(Boolean(testConfig.marketplaceAuthToken), true)
} catch (error) {
assert.fail('should not fail')
}
})
it('should login using a message', async () => {
const clientAssertion = await nevermined.utils.jwt.generateClientAssertion(
account1,
'Nevermined',
)
const accessToken = await nevermined.services.marketplace.login(clientAssertion)
assert.isDefined(accessToken)
})
it('should add new address to the account', async () => {
const clientAssertion = await nevermined.utils.jwt.generateClientAssertion(account2)
await nevermined.services.marketplace.addNewAddress(clientAssertion)
assert.equal(Boolean(testConfig.marketplaceAuthToken), true)
})
})