Skip to content

Commit

Permalink
update new slug tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgeoa committed Dec 31, 2023
1 parent a5d6011 commit b4e062b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/integration/acl-oidc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 403)
assert.include(response.statusMessage, 'Can\'t write file/folder: User Unauthorized')
assert.include(response.statusMessage, 'User Unauthorized')
done()
})
})
Expand All @@ -683,7 +683,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 401)
assert.include(response.statusMessage, 'Can\'t write file/folder: Unauthenticated')
assert.include(response.statusMessage, 'Unauthenticated')
done()
})
})
Expand Down
43 changes: 34 additions & 9 deletions test/integration/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ describe('HTTP APIs', function () {
})

describe('POST API', function () {
let postLocation
before(function () {
// Ensure all these are finished before running tests
return Promise.all([
Expand All @@ -738,6 +739,12 @@ describe('HTTP APIs', function () {
'../resources/sampleContainer/post2.ttl'), {
encoding: 'utf8'
})
// Capture the resource name generated by server by parsing Location: header
let postedResourceName
const getResourceName = function (res) {
postedResourceName = res.header.location
}

it('should create new document resource', function (done) {
server.post('/post-tests/')
.send(postRequest1Body)
Expand All @@ -763,7 +770,24 @@ describe('HTTP APIs', function () {
.set('slug', 'put-resource')
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
.send(postRequest2Body)
.expect(201, done)
.expect(201)
.end((err, res) => {
if (err) return done(err)
try {
postLocation = res.headers.location
console.log('location ' + postLocation)
const createdDir = fs.statSync(path.join(__dirname, '../resources', postLocation.slice(0, -1)))
assert(createdDir.isDirectory(), 'Container should have been created')
} catch (err) {
return done(err)
}
done()
})
})
it('should get newly created container with new slug', function (done) {
console.log('location' + postLocation)
server.get(postLocation)
.expect(200, done)
})
it('should error with 403 if auxiliary resource file.acl', function (done) {
server.post('/post-tests/')
Expand Down Expand Up @@ -821,11 +845,6 @@ describe('HTTP APIs', function () {
server.delete('/post-tests/post-resource-1.ttl')
.expect(200, done)
})
// Capture the resource name generated by server by parsing Location: header
let postedResourceName
const getResourceName = function (res) {
postedResourceName = res.header.location
}
it('should create new resource without slug header', function (done) {
server.post('/post-tests/')
.send(postRequest1Body)
Expand Down Expand Up @@ -864,9 +883,15 @@ describe('HTTP APIs', function () {
server.post('/post-tests/')
.send(postRequest1Body)
.set('content-type', 'text/turtle')
.set('slug', 'loans')
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
.expect(201, done)
.set('slug', 'loans.ttl')
.expect(201)
.expect(getResourceName)
.end(done)
})
it('should get newly created document resource with new slug', function (done) {
console.log(postedResourceName)
server.get(postedResourceName)
.expect(200, done)
})
it('should create a container with a name hex decoded from the slug', (done) => {
const containerName = 'Film%4011'
Expand Down

0 comments on commit b4e062b

Please sign in to comment.