-
Notifications
You must be signed in to change notification settings - Fork 1
/
Permissions.test.ts
107 lines (88 loc) · 3.58 KB
/
Permissions.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
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
import { assert } from 'chai'
import config from '../../test/config'
import { Nevermined } from '../../src/nevermined/Nevermined'
import { NvmAccount } from '../../src/models/NvmAccount'
import { NewPermission, PermissionType } from '../../src/types/MetadataTypes'
describe('Permissions', () => {
let nevermined: Nevermined
let account1: NvmAccount
let account2: NvmAccount
let newPermission: NewPermission
let id: string
before(async () => {
nevermined = await Nevermined.getInstance(config)
;[account1, account2] = nevermined.accounts.list()
//TODO admin token which will expire within 3 years. In the future an admin account will be created in elasticsearch directly to run theses tests
config.marketplaceAuthToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIweGUyREQwOWQ3MTlEYTg5ZTVhM0QwRjI1NDljN0UyNDU2NmU5NDcyNjAiLCJzdWIiOiJ1LWU2YzI2NDhjLTIwZjktNDJlMC1iMWZlLWZjZWEwNzA4ODY3NyIsInJvbGVzIjpbImFkbWluIl0sImlhdCI6MTY1MTI0ODM1NCwiZXhwIjoxNzUxMjUxOTU0fQ.p9fr_c_HVlJzY1cJSGDod1zMdhRCRWdExOB_UxMDrKg'
const userProfile = await nevermined.services.profiles.findOneByAddress(account1.getId())
newPermission = {
userId: userProfile.userId,
type: [PermissionType.Read, PermissionType.Update, PermissionType.Delete],
issuer: account2.getId(),
holder: account1.getId(),
}
})
it('should create a permission', async () => {
const response = await nevermined.services.permissions.create(newPermission)
id = response.id // eslint-disable-line prefer-destructuring
assert.deepEqual(response, {
...newPermission,
issuanceDate: response.issuanceDate,
id,
})
})
it('should get a permission by id', async () => {
const response = await nevermined.services.permissions.findOneById(id)
assert.deepEqual(response, {
...newPermission,
issuanceDate: response.issuanceDate,
id,
})
})
it('should get permissions by userId', async () => {
const response = await nevermined.services.permissions.findManyByUserId(newPermission.userId)
/* eslint-disable @typescript-eslint/naming-convention */
assert.deepEqual(response, {
page: 1,
total_pages: response.total_pages,
total_results: response.total_results,
results: [{ ...newPermission, issuanceDate: response.results[0].issuanceDate, id }],
})
})
it('should get permissions by userId and type', async () => {
const response = await nevermined.services.permissions.findManyByUserIdAndType(
newPermission.userId,
PermissionType.Read,
)
/* eslint-disable @typescript-eslint/naming-convention */
assert.deepEqual(response, {
page: 1,
total_pages: response.total_pages,
total_results: response.total_results,
results: [{ ...newPermission, issuanceDate: response.results[0].issuanceDate, id }],
})
})
it('should update a permission by id', async () => {
const response = await nevermined.services.permissions.updateOneById(id, {
type: [PermissionType.Read],
})
assert.deepEqual(response, {
...newPermission,
id,
type: response.type,
issuanceDate: response.issuanceDate,
})
})
it('should delete a permission by id', async () => {
await nevermined.services.permissions.deleteOneById(id)
const response = await nevermined.services.permissions.findManyByUserId(newPermission.userId)
/* eslint-disable @typescript-eslint/naming-convention */
assert.deepEqual(response, {
page: response.page,
total_pages: response.total_pages,
total_results: response.total_results,
results: [],
})
})
})