-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathuser-utils-test.mjs
More file actions
64 lines (55 loc) · 1.86 KB
/
user-utils-test.mjs
File metadata and controls
64 lines (55 loc) · 1.86 KB
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
import * as userUtils from '../../lib/common/user-utils.mjs'
import $rdf from 'rdflib'
import chai from 'chai'
const { expect } = chai
describe('user-utils', () => {
describe('getName', () => {
let ldp
const webId = 'http://test#me'
const name = 'NAME'
beforeEach(() => {
const store = $rdf.graph()
store.add($rdf.sym(webId), $rdf.sym('http://www.w3.org/2006/vcard/ns#fn'), $rdf.lit(name))
ldp = { fetchGraph: () => Promise.resolve(store) }
})
it('should return name from graph', async () => {
const returnedName = await userUtils.getName(webId, ldp.fetchGraph)
expect(returnedName).to.equal(name)
})
})
describe('getWebId', () => {
let fetchGraph
const webId = 'https://test.localhost:8443/profile/card#me'
const suffixMeta = '.meta'
beforeEach(() => {
fetchGraph = () => Promise.resolve(`<${webId}> <http://www.w3.org/ns/solid/terms#account> </>.`)
})
it('should return webId from meta file', async () => {
const returnedWebId = await userUtils.getWebId('foo', 'https://bar/', suffixMeta, fetchGraph)
expect(returnedWebId).to.equal(webId)
})
})
describe('isValidUsername', () => {
it('should accect valid usernames', () => {
const usernames = [
'foo',
'bar'
]
const validUsernames = usernames.filter(username => userUtils.isValidUsername(username))
expect(validUsernames.length).to.equal(usernames.length)
})
it('should not accect invalid usernames', () => {
const usernames = [
'-',
'-a',
'a-',
'9-',
'alice--bob',
'alice bob',
'alice.bob'
]
const validUsernames = usernames.filter(username => userUtils.isValidUsername(username))
expect(validUsernames.length).to.equal(0)
})
})
})