-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinsertAndDeleteWithGet.test.js
114 lines (108 loc) · 4.18 KB
/
insertAndDeleteWithGet.test.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
describe('test Get', function() {
const data =
'<http://exampleSub> <http://examplePred> <http://exampleObj>. ' +
'GRAPH <urn:sparql:tests:insert:data> {' +
'<http://exampleSub> <http://exampleSub> 102} ';
var params =
'action=exec&' +
'queryLn=SPARQL&' +
'query=' +
encodeURIComponent(
'PREFIX foaf: <https://agentlab.ru/rdf4j-workbench/repositories> ' + 'SELECT ?Subject ' + 'WHERE{ ' + data + '}',
) +
'&' +
'limit_query=100&' +
'infer=true&';
it('insert data to rdf repository with context', async () => {
var urlprefix = 'https://agentlab.ru/rdf4j-workbench/repositories/rtrtrtr/query' + '?' + params;
//проверка до добавления
var dataSel = await fetch(urlprefix, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
}).then((r) => r.json());
expect(dataSel.results.bindings.length).toEqual(0);
//добавление
var paramsGet = 'query=' + encodeURIComponent('INSERT DATA' + '{' + data + '}');
urlprefix = 'https://agentlab.ru/rdf4j-workbench/repositories/rtrtrtr' + '?' + paramsGet;
var result = await fetch(urlprefix, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
}).then((r) => {
console.log(r);
expect(r).toBeInstanceOf(Response);
expect(r['status']).toEqual(200);
return r;
});
});
it('check data after insert to rdf repository with context', async () => {
//проверка после
var urlprefix = 'https://agentlab.ru/rdf4j-workbench/repositories/rtrtrtr/query' + '?' + params;
var dataSel = await fetch(urlprefix, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
}).then((r) => r.json());
//console.log('===================== ' + Object.keys(dataSel.results.bindings));
expect(dataSel.results.bindings.length).toEqual(0);
});
it('delete data to rdf repository with context', async () => {
//добавление
urlprefix = 'https://agentlab.ru/rdf4j-workbench/repositories/rtrtrtr/update';
var result = await fetch(urlprefix, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
body: 'update=' + encodeURIComponent('INSERT DATA' + '{' + data + '}'),
}).then((r) => {
console.log(r);
expect(r).toBeInstanceOf(Response);
expect(r['status']).toEqual(200);
return r;
});
var urlprefix = 'https://agentlab.ru/rdf4j-workbench/repositories/rtrtrtr/query' + '?' + params;
//проверка до
var dataSel = await fetch(urlprefix, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
}).then((r) => r.json());
expect(dataSel.results.bindings.length).toBeGreaterThan(0);
//удаление
var paramsGet = 'query=' + encodeURIComponent('DELETE DATA' + '{' + data + '}');
urlprefix = 'https://agentlab.ru/rdf4j-workbench/repositories/rtrtrtr' + '?' + paramsGet;
var result = await fetch(urlprefix, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
}).then((r) => {
console.log(r);
expect(r).toBeInstanceOf(Response);
expect(r['status']).toEqual(200);
return r;
});
//проверка после
dataSel = await fetch(urlprefix, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/sparql-results+json',
},
}).then((r) => r.json());
//console.log('===================== ' + Object.keys(dataSel.results.bindings));
expect(dataSel.results.bindings.length).toBeGreaterThan(0);
});
});