-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const urlJoin = require('url-join'); | ||
const { parse: parseLinkHeader } = require('http-link-header'); | ||
const { fetchServer } = require('../utils'); | ||
const initialize = require('./initialize'); | ||
const CONFIG = require('../config'); | ||
|
||
jest.setTimeout(20000); | ||
let broker; | ||
|
||
beforeAll(async () => { | ||
broker = await initialize(); | ||
}); | ||
afterAll(async () => { | ||
if (broker) await broker.stop(); | ||
}); | ||
|
||
describe('Headers handling of LDP server', () => { | ||
test('Get headers', async () => { | ||
const { headers: postHeaders } = await fetchServer(urlJoin(CONFIG.HOME_URL, 'places'), { | ||
method: 'POST', | ||
body: { | ||
'@type': 'pair:Place', | ||
'pair:label': 'My place' | ||
} | ||
}); | ||
|
||
const resourceUri = postHeaders.get('Location'); | ||
const resourcePath = new URL(resourceUri).pathname; | ||
|
||
const { headers } = await fetchServer(resourceUri, { | ||
method: 'HEAD' | ||
}); | ||
|
||
const parsedLinks = parseLinkHeader(headers.get('link')); | ||
|
||
expect(parsedLinks.refs).toMatchObject([ | ||
{ | ||
uri: urlJoin(CONFIG.HOME_URL, '_acl', resourcePath), | ||
rel: 'acl' | ||
} | ||
]); | ||
}); | ||
|
||
test('Get container-specific headers', async () => { | ||
const { headers: postHeaders } = await fetchServer(urlJoin(CONFIG.HOME_URL, 'pair', 'event'), { | ||
method: 'POST', | ||
body: { | ||
'@type': 'pair:Event', | ||
'pair:label': 'My event' | ||
} | ||
}); | ||
|
||
const resourceUri = postHeaders.get('Location'); | ||
const resourcePath = new URL(resourceUri).pathname; | ||
|
||
const { headers } = await fetchServer(resourceUri, { | ||
method: 'HEAD' | ||
}); | ||
|
||
const parsedLinks = parseLinkHeader(headers.get('link')); | ||
|
||
expect(parsedLinks.refs).toMatchObject([ | ||
{ uri: urlJoin(CONFIG.HOME_URL, '_acl', resourcePath), rel: 'acl' }, | ||
{ uri: 'http://foo.bar', rel: 'http://foo.baz' } | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters