-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBookmarks.test.ts
95 lines (76 loc) · 2.73 KB
/
Bookmarks.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
import { assert } from 'chai'
import config from '../../test/config'
import { faker } from '@faker-js/faker'
import { Nevermined } from '../../src/nevermined/Nevermined'
import { NvmAccount } from '../../src/models/NvmAccount'
import { NewBookmark } from '../../src/types/MetadataTypes'
describe('Bookmarks', () => {
let nevermined: Nevermined
let account1: NvmAccount
let newBookmark: NewBookmark
let id: string
before(async () => {
config.marketplaceAuthToken = undefined
nevermined = await Nevermined.getInstance(config)
;[account1] = nevermined.accounts.list()
const clientAssertion = await nevermined.utils.jwt.generateClientAssertion(account1)
await nevermined.services.marketplace.login(clientAssertion)
const userProfile = await nevermined.services.profiles.findOneByAddress(account1.getId())
newBookmark = {
did: `did:${faker.datatype.uuid()}`,
userId: userProfile.userId,
description: faker.lorem.sentence(),
}
})
it('should create a bookmark', async () => {
const response = await nevermined.services.bookmarks.create(newBookmark)
id = response.id // eslint-disable-line prefer-destructuring
assert.deepEqual(response, {
...newBookmark,
createdAt: response.createdAt,
id,
})
})
it('should get a bookmark by id', async () => {
const response = await nevermined.services.bookmarks.findOneById(id)
assert.deepEqual(response, {
...newBookmark,
createdAt: response.createdAt,
id,
})
})
it('should get bookmarks by userId', async () => {
const response = await nevermined.services.bookmarks.findManyByUserId(newBookmark.userId)
/* eslint-disable @typescript-eslint/naming-convention */
assert.deepEqual(response, {
page: 1,
total_pages: response.total_pages,
total_results: response.total_results,
results: [{ ...newBookmark, createdAt: response.results[0].createdAt, id }],
})
})
it('should update a bookmark by id', async () => {
const description = faker.lorem.sentence()
const response = await nevermined.services.bookmarks.updateOneById(id, {
description,
userId: newBookmark.userId,
})
assert.deepEqual(response, {
...newBookmark,
id,
description,
createdAt: response.createdAt,
})
})
it('should delete a bookmark by id', async () => {
await nevermined.services.bookmarks.deleteOneById(id)
const response = await nevermined.services.bookmarks.findManyByUserId(newBookmark.userId)
/* eslint-disable @typescript-eslint/naming-convention */
assert.deepEqual(response, {
page: 1,
total_pages: response.total_pages,
total_results: { value: 0, relation: 'eq' },
results: [],
})
})
})