-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwb-add-reference.js
89 lines (84 loc) · 3.02 KB
/
wb-add-reference.js
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
import 'should'
import { wbDry } from '#test/lib/utils'
describe('wb add-reference', () => {
it('should accept a guid, a property and a value', async () => {
const { stdout, stderr } = await wbDry("add-reference 'Q4115189$E66DBC80-CCC1-4899-90D4-510C9922A04F' P854 https://example.org/rise-and-box-of-the-holy-sand-box")
stderr.should.equal('')
const { section, action, args } = JSON.parse(stdout)
section.should.equal('reference')
action.should.equal('add')
args.should.deepEqual([
{
guid: 'Q4115189$E66DBC80-CCC1-4899-90D4-510C9922A04F',
property: 'P854',
value: 'https://example.org/rise-and-box-of-the-holy-sand-box',
},
])
})
it('should accept a hyphenated guid, a property and a value', async () => {
const { stdout, stderr } = await wbDry('add-reference Q4115189-E66DBC80-CCC1-4899-90D4-510C9922A04F P854 https://example.org/rise-and-box-of-the-holy-sand-box')
stderr.should.equal('')
const { section, action, args } = JSON.parse(stdout)
section.should.equal('reference')
action.should.equal('add')
args.should.deepEqual([
{
guid: 'Q4115189$E66DBC80-CCC1-4899-90D4-510C9922A04F',
property: 'P854',
value: 'https://example.org/rise-and-box-of-the-holy-sand-box',
},
])
})
it('should accept an inline JSON object', async () => {
const guid = 'Q4115189$c885b63e-46f9-3f51-5736-d3ed09a58acf'
const { stdout, stderr } = await wbDry(`add-reference '{"guid":"${guid}","snaks":{"P248":"Q1150348","P1157":"S001191","P813":"2021-01-28"}}'`)
stderr.should.equal('')
const { section, action, args } = JSON.parse(stdout)
section.should.equal('reference')
action.should.equal('add')
args.should.deepEqual([
{
guid,
snaks: {
P248: 'Q1150348',
P1157: 'S001191',
P813: '2021-01-28',
},
},
])
})
it('should accept a JSON path', async () => {
const { stdout, stderr } = await wbDry('add-reference ./test/assets/add_some_reference.json')
stderr.should.equal('')
const { section, action, args } = JSON.parse(stdout)
section.should.equal('reference')
action.should.equal('add')
args.should.deepEqual([
{
guid: 'Q4115189$c885b63e-46f9-3f51-5736-d3ed09a58acf',
snaks: {
P248: 'Q1150348',
P1157: 'S001191',
P813: '2021-01-28',
},
},
])
})
it('should accept a JS module path and arguments', async () => {
const { stdout, stderr } = await wbDry('add-reference ./test/assets/add_some_reference.js Q4115189-c885b63e-46f9-3f51-5736-d3ed09a58acf S001191')
stderr.should.equal('')
const { section, action, args } = JSON.parse(stdout)
section.should.equal('reference')
action.should.equal('add')
args.should.deepEqual([
{
guid: 'Q4115189$c885b63e-46f9-3f51-5736-d3ed09a58acf',
snaks: {
P248: 'Q1150348',
P1157: 'S001191',
P813: new Date().toISOString().split('T')[0],
},
},
])
})
})