Skip to content

Commit 562a91b

Browse files
author
CI Fix
committed
add missing test-esm/resources
1 parent 277633e commit 562a91b

File tree

314 files changed

+4287
-1524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+4287
-1524
lines changed

lib/handlers/patch.mjs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ import $rdf from 'rdflib'
88
import crypto from 'crypto'
99
import { overQuota, getContentType } from '../utils.mjs'
1010
import withLock from '../lock.mjs'
11-
import sparqlUpdateParser from './patch/sparql-update-parser.js'
12-
import n3PatchParser from './patch/n3-patch-parser.js'
11+
// import sparqlUpdateParser from './patch/sparql-update-parser.js'
12+
// import n3PatchParser from './patch/n3-patch-parser.js'
13+
import { createRequire } from 'module'
14+
15+
const require = createRequire(import.meta.url)
16+
const sparqlUpdateParser = require('./patch/sparql-update-parser.js')
17+
const n3PatchParser = require('./patch/n3-patch-parser.js')
1318

1419
// Patch parsers by request body content type
1520
const PATCH_PARSERS = {
@@ -33,6 +38,15 @@ export default async function handler (req, res, next) {
3338
const contentType = getContentType(req.headers)
3439
debug(`PATCH -- ${req.originalUrl}`)
3540

41+
// DEBUG: Log the resource path that will be written (guaranteed output)
42+
try {
43+
const ldp = req.app.locals.ldp;
44+
const { path: resourcePath } = await ldp.resourceMapper.mapUrlToFile({ url: req, createIfNotExists: true, contentType: contentTypeForNew(req) });
45+
console.log(`PATCH -- [DEBUG] Will write to file: ${resourcePath}`);
46+
} catch (e) {
47+
console.log(`PATCH -- [DEBUG] Error resolving file path: ${e.message}`);
48+
}
49+
3650
// Parse the body (req.body will be set to true if empty body)
3751
if (contentType in PATCH_PARSERS) {
3852
bodyParser.text({ type: contentType, limit: '1mb' })(req, res, async () => {

test-esm/integration/header-test.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import { expect } from 'chai'
33
import supertest from 'supertest'
44
import { fileURLToPath } from 'url'
55
import { dirname, join } from 'path'
6+
import { setupSupertestServer } from '../../test-esm/utils.mjs'
67

7-
const require = createRequire(import.meta.url)
8-
const __dirname = dirname(fileURLToPath(import.meta.url))
9-
const { setupSupertestServer } = require('../../test/utils')
8+
// const require = createRequire(import.meta.url)
9+
const __dirname = import.meta.dirname // dirname(fileURLToPath(import.meta.url))
10+
// const { setupSupertestServer } = require('../../test/utils')
1011

1112
describe('Header handler', () => {
1213
let request
1314

1415
before(function () {
1516
this.timeout(20000)
1617
request = setupSupertestServer({
17-
root: join(__dirname, '../../test/resources/headers'),
18+
root: join(__dirname, '../../test-esm/resources/headers'),
1819
multiuser: false,
1920
webid: true,
2021
sslKey: join(__dirname, '../../test/keys/key.pem'),
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// ESM version of integration test for PATCH with application/sparql-update
2+
import { describe, it, after } from 'mocha';
3+
import { strict as assert } from 'assert';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
import { rm, write, read } from '../utils.mjs';
7+
// import supertest from 'supertest';
8+
// import ldnode from '../../index.js';
9+
import { createRequire } from 'module'
10+
11+
12+
const require = createRequire(import.meta.url);
13+
const ldnode = require('../../index.js');
14+
const supertest = require('supertest');
15+
const __filename = fileURLToPath(import.meta.url);
16+
const __dirname = path.dirname(__filename);
17+
const fse = require('fs-extra');
18+
19+
// Starting LDP
20+
const ldp = ldnode.createServer({
21+
root: path.join(__dirname, '../resources/sampleContainer'),
22+
mount: '/test-esm',
23+
webid: false
24+
});
25+
const server = supertest(ldp);
26+
27+
before(function () {
28+
fse.ensureDirSync(path.join(__dirname, '../resources/sampleContainer'));
29+
});
30+
31+
describe('PATCH through application/sparql-update', function () {
32+
it('should create a new file if file does not exist', function (done) {
33+
rm('sampleContainer/notExisting.ttl');
34+
const sampleContainerPath = path.join(__dirname, '../resources/sampleContainer');
35+
fse.ensureDirSync(sampleContainerPath);
36+
server.patch('/notExisting.ttl')
37+
.set('content-type', 'application/sparql-update')
38+
.send('INSERT DATA { :test :hello 456 .}')
39+
.expect(201)
40+
.end(function (err, res) {
41+
assert.equal(
42+
read('sampleContainer/notExisting.ttl'),
43+
'@prefix : </notExisting.ttl#>.\n\n:test :hello 456 .\n\n'
44+
);
45+
rm('sampleContainer/notExisting.ttl');
46+
done(err);
47+
});
48+
});
49+
50+
describe('DELETE', function () {
51+
it('should be an empty resource if last triple is deleted', function (done) {
52+
write(
53+
'<#current> <#temp> 123 .',
54+
'sampleContainer/existingTriple.ttl'
55+
);
56+
server.post('/existingTriple.ttl')
57+
.set('content-type', 'application/sparql-update')
58+
.send('DELETE { :current :temp 123 .}')
59+
.expect(200)
60+
.end(function (err, res) {
61+
assert.equal(
62+
read('sampleContainer/existingTriple.ttl'),
63+
'@prefix : </existingTriple.ttl#>.\n\n'
64+
);
65+
rm('sampleContainer/existingTriple.ttl');
66+
done(err);
67+
});
68+
});
69+
70+
it('should delete a single triple from a pad document', function (done) {
71+
const expected = `@prefix : </existingTriple.ttl#>.\n@prefix cal: <http://www.w3.org/2002/12/cal/ical#>.\n@prefix dc: <http://purl.org/dc/elements/1.1/>.\n@prefix meeting: <http://www.w3.org/ns/pim/meeting#>.\n@prefix pad: <http://www.w3.org/ns/pim/pad#>.\n@prefix sioc: <http://rdfs.org/sioc/ns#>.\n@prefix ui: <http://www.w3.org/ns/ui#>.\n@prefix wf: <http://www.w3.org/2005/01/wf/flow#>.\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.\n@prefix c: <https://www.w3.org/People/Berners-Lee/card#>.\n@prefix ind: </parent/index.ttl#>.\n\n:id1477502276660 dc:author c:i; sioc:content \"\"; pad:next :this.\n\n:id1477522707481\n cal:dtstart \"2016-10-26T22:58:27Z\"^^xsd:dateTime;\n wf:participant c:i;\n ui:backgroundColor \"#c1d0c8\".\n:this\n a pad:Notepad;\n dc:author c:i;\n dc:created \"2016-10-25T15:44:42Z\"^^xsd:dateTime;\n dc:title \"Shared Notes\";\n pad:next :id1477502276660 .\nind:this wf:participation :id1477522707481; meeting:sharedNotes :this.\n\n`;
72+
write(`\n\n @prefix dc: <http://purl.org/dc/elements/1.1/>.\n @prefix mee: <http://www.w3.org/ns/pim/meeting#>.\n @prefix c: <https://www.w3.org/People/Berners-Lee/card#>.\n @prefix XML: <http://www.w3.org/2001/XMLSchema#>.\n @prefix p: <http://www.w3.org/ns/pim/pad#>.\n @prefix ind: </parent/index.ttl#>.\n @prefix n: <http://rdfs.org/sioc/ns#>.\n @prefix flow: <http://www.w3.org/2005/01/wf/flow#>.\n @prefix ic: <http://www.w3.org/2002/12/cal/ical#>.\n @prefix ui: <http://www.w3.org/ns/ui#>.\n\n <#this>\n dc:author\n c:i;\n dc:created\n \"2016-10-25T15:44:42Z\"^^XML:dateTime;\n dc:title\n \"Shared Notes\";\n a p:Notepad;\n p:next\n <#id1477502276660>.\n ind:this flow:participation <#id1477522707481>; mee:sharedNotes <#this> .\n <#id1477502276660> dc:author c:i; n:content \"\"; p:indent 1; p:next <#this> .\n <#id1477522707481>\n ic:dtstart\n \"2016-10-26T22:58:27Z\"^^XML:dateTime;\n flow:participant\n c:i;\n ui:backgroundColor\n \"#c1d0c8\".\n`,
73+
'sampleContainer/existingTriple.ttl'
74+
);
75+
server.post('/existingTriple.ttl')
76+
.set('content-type', 'application/sparql-update')
77+
.send('DELETE { <#id1477502276660> <http://www.w3.org/ns/pim/pad#indent> 1 .}')
78+
.expect(200)
79+
.end(function (err, res) {
80+
assert.equal(
81+
read('sampleContainer/existingTriple.ttl'),
82+
expected
83+
);
84+
rm('sampleContainer/existingTriple.ttl');
85+
done(err);
86+
});
87+
});
88+
});
89+
90+
describe('DELETE and INSERT', function () {
91+
after(() => rm('sampleContainer/prefixSparql.ttl'));
92+
93+
it('should update a resource using SPARQL-query using `prefix`', function (done) {
94+
write(
95+
'@prefix schema: <http://schema.org/> .\n' +
96+
'@prefix pro: <http://ogp.me/ns/profile#> .\n' +
97+
'# <http://example.com/timbl#> a schema:Person ;\n' +
98+
'<#> a schema:Person ;\n' +
99+
' pro:first_name "Tim" .\n',
100+
'sampleContainer/prefixSparql.ttl'
101+
);
102+
server.post('/prefixSparql.ttl')
103+
.set('content-type', 'application/sparql-update')
104+
.send('@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n' +
105+
'@prefix schema: <http://schema.org/> .\n' +
106+
'@prefix pro: <http://ogp.me/ns/profile#> .\n' +
107+
'@prefix ex: <http://example.org/vocab#> .\n' +
108+
'DELETE { <#> pro:first_name "Tim" }\n' +
109+
'INSERT { <#> pro:first_name "Timothy" }')
110+
.expect(200)
111+
.end(function (err, res) {
112+
assert.equal(
113+
read('sampleContainer/prefixSparql.ttl'),
114+
'@prefix : </prefixSparql.ttl#>.\n@prefix schema: <http://schema.org/>.\n@prefix pro: <http://ogp.me/ns/profile#>.\n\n: a schema:Person; pro:first_name "Timothy".\n\n'
115+
);
116+
done(err);
117+
});
118+
});
119+
});
120+
121+
describe('INSERT', function () {
122+
it('should add a new triple', function (done) {
123+
write(
124+
'<#current> <#temp> 123 .',
125+
'sampleContainer/addingTriple.ttl'
126+
);
127+
server.post('/addingTriple.ttl')
128+
.set('content-type', 'application/sparql-update')
129+
.send('INSERT DATA { :test :hello 456 .}')
130+
.expect(200)
131+
.end(function (err, res) {
132+
assert.equal(
133+
read('sampleContainer/addingTriple.ttl'),
134+
'@prefix : </addingTriple.ttl#>.\n\n:current :temp 123 .\n\n:test :hello 456 .\n\n'
135+
);
136+
rm('sampleContainer/addingTriple.ttl');
137+
done(err);
138+
});
139+
});
140+
141+
it('should add value to existing triple', function (done) {
142+
write(
143+
'<#current> <#temp> 123 .',
144+
'sampleContainer/addingTripleValue.ttl'
145+
);
146+
server.post('/addingTripleValue.ttl')
147+
.set('content-type', 'application/sparql-update')
148+
.send('INSERT DATA { :current :temp 456 .}')
149+
.expect(200)
150+
.end(function (err, res) {
151+
assert.equal(
152+
read('sampleContainer/addingTripleValue.ttl'),
153+
'@prefix : </addingTripleValue.ttl#>.\n\n:current :temp 123, 456 .\n\n'
154+
);
155+
rm('sampleContainer/addingTripleValue.ttl');
156+
done(err);
157+
});
158+
});
159+
160+
it('should add value to same subject', function (done) {
161+
write(
162+
'<#current> <#temp> 123 .',
163+
'sampleContainer/addingTripleSubj.ttl'
164+
);
165+
server.post('/addingTripleSubj.ttl')
166+
.set('content-type', 'application/sparql-update')
167+
.send('INSERT DATA { :current :temp2 456 .}')
168+
.expect(200)
169+
.end(function (err, res) {
170+
assert.equal(
171+
read('sampleContainer/addingTripleSubj.ttl'),
172+
'@prefix : </addingTripleSubj.ttl#>.\n\n:current :temp 123; :temp2 456 .\n\n'
173+
);
174+
rm('sampleContainer/addingTripleSubj.ttl');
175+
done(err);
176+
});
177+
});
178+
});
179+
180+
it('nothing should change with empty patch', function (done) {
181+
write(
182+
'<#current> <#temp> 123 .',
183+
'sampleContainer/emptyExample.ttl'
184+
);
185+
server.post('/emptyExample.ttl')
186+
.set('content-type', 'application/sparql-update')
187+
.send('')
188+
.expect(200)
189+
.end(function (err, res) {
190+
assert.equal(
191+
read('sampleContainer/emptyExample.ttl'),
192+
'@prefix : </emptyExample.ttl#>.\n\n:current :temp 123 .\n\n'
193+
);
194+
rm('sampleContainer/emptyExample.ttl');
195+
done(err);
196+
});
197+
});
198+
});

test-esm/resources/.acl

Whitespace-only changes.

test-esm/resources/accounts/nicola.localhost/.meta renamed to test-esm/resources/.meta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Root Meta resource for the user account
22
# Used to discover the account's WebID URI, given the account URI
3-
</profile/card#me>
3+
<https://tim.localhost:7777/profile/card#me>
44
<http://www.w3.org/ns/solid/terms#account>
55
</>.

test-esm/resources/.permissions

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"roles" : [
3+
["user", "hello.html", "GET"]
4+
],
5+
"users" : [
6+
["https://martinmr.rww.io/profile/card#me", "user"]
7+
]
8+
}

test-esm/resources/accounts-acl/config/templates/server/.well-known/.acl renamed to test-esm/resources/.well-known/.acl

File renamed without changes.

0 commit comments

Comments
 (0)