fix: Return 201 when creating new resources

This commit is contained in:
Joachim Van Herwegen
2021-10-11 09:54:45 +02:00
parent 5613ff9e71
commit 76c87bb56a
12 changed files with 93 additions and 30 deletions

View File

@@ -105,7 +105,8 @@ describe.each(configs)('A dynamic pod server with template config %s', (template
},
body: 'this is new data!',
});
expect(res.status).toBe(205);
expect(res.status).toBe(201);
expect(res.headers.get('location')).toBe(`${podUrl}test`);
res = await fetch(`${podUrl}test`, {
headers: {

View File

@@ -84,7 +84,7 @@ describe.each(stores)('An LDP handler with auth using %s', (name, { storeConfig,
// PUT
const document = `${baseUrl}test.txt`;
await putResource(document, { contentType: 'text/plain', body: 'TESTDATA' });
await putResource(document, { contentType: 'text/plain', body: 'TESTDATA', exists: false });
// GET
const response = await getResource(document);

View File

@@ -110,7 +110,7 @@ describe.each(stores)('An LDP handler allowing all requests %s', (name, { storeC
await expect(response.text()).resolves.toBe('TESTFILE0');
// PUT
await putResource(documentUrl, { contentType: 'text/plain', body: 'TESTFILE1' });
await putResource(documentUrl, { contentType: 'text/plain', body: 'TESTFILE1', exists: true });
// GET
response = await getResource(documentUrl, {}, { contentType: 'text/plain' });
@@ -253,7 +253,8 @@ describe.each(stores)('An LDP handler allowing all requests %s', (name, { storeC
},
body: createReadStream(joinFilePath(__dirname, '../assets/testimage.png')) as any,
});
expect(response.status).toBe(205);
expect(response.status).toBe(201);
expect(response.headers.get('location')).toBe(documentUrl);
await expect(response.text()).resolves.toHaveLength(0);
// GET
@@ -291,7 +292,8 @@ describe.each(stores)('An LDP handler allowing all requests %s', (name, { storeC
headers: { 'content-length': '0', 'content-type': 'text/turtle' },
body: '',
});
expect(response.status).toBe(205);
expect(response.status).toBe(201);
expect(response.headers.get('location')).toBe(documentUrl);
// GET
await getResource(documentUrl);
@@ -312,7 +314,7 @@ describe.each(stores)('An LDP handler allowing all requests %s', (name, { storeC
'INSERT {<http://test.com/s3> <http://test.com/p3> <http://test.com/o3>}',
'WHERE {}',
].join('\n');
await patchResource(documentUrl, query);
await patchResource(documentUrl, query, true);
// PATCH using a content-type header with charset
const query2 = [ 'DELETE { <http://test.com/s2> <http://test.com/p2> <http://test.com/o2> }',
@@ -361,7 +363,7 @@ describe.each(stores)('An LDP handler allowing all requests %s', (name, { storeC
'INSERT {<http://test.com/s3> <http://test.com/p3> <http://test.com/o3>}',
'WHERE {}',
].join('\n');
await patchResource(documentUrl, query);
await patchResource(documentUrl, query, true);
// GET
response = await getResource(documentUrl);

View File

@@ -39,7 +39,7 @@ describeIf('docker', 'A server with a RedisResourceLocker as ResourceLocker', ()
},
body: fileData,
});
expect(response.status).toBe(205);
expect(response.status).toBe(201);
// Get file
response = await fetch(fileUrl);
@@ -64,7 +64,7 @@ describeIf('docker', 'A server with a RedisResourceLocker as ResourceLocker', ()
'content-type': 'text/plain',
},
});
expect(response.status).toBe(205);
expect(response.status).toBe(201);
// GET
response = await fetch(containerUrl);
@@ -88,7 +88,7 @@ describeIf('docker', 'A server with a RedisResourceLocker as ResourceLocker', ()
},
body: fileData,
});
expect(response.status).toBe(205);
expect(response.status).toBe(201);
// GET 4 times
for (let i = 0; i < 4; i++) {

View File

@@ -76,7 +76,8 @@ describe('A server with restricted IDP access', (): void => {
headers: { 'content-type': 'text/turtle' },
body: restrictedAcl,
});
expect(res.status).toBe(205);
expect(res.status).toBe(201);
expect(res.headers.get('location')).toBe(`${baseUrl}idp/register/.acl`);
// Registration is now disabled
res = await fetch(`${baseUrl}idp/register/`);

View File

@@ -77,7 +77,8 @@ describe('A Solid server', (): void => {
},
body: '<a:b> <a:b> <a:b>.',
});
expect(res.status).toBe(205);
expect(res.status).toBe(201);
expect(res.headers.get('location')).toBe(url);
});
it('can PUT to resources.', async(): Promise<void> => {
@@ -89,7 +90,8 @@ describe('A Solid server', (): void => {
},
body: '<a:b> <a:b> <a:b>.',
});
expect(res.status).toBe(205);
expect(res.status).toBe(201);
expect(res.headers.get('location')).toBe(url);
});
it('can handle PUT errors.', async(): Promise<void> => {

View File

@@ -79,7 +79,8 @@ describe.each(stores)('A subdomain server with %s', (name, { storeConfig, teardo
},
body: 'this is new data!',
});
expect(res.status).toBe(205);
expect(res.status).toBe(201);
expect(res.headers.get('location')).toBe(`${baseUrl}alice`);
res = await fetch(`${baseUrl}alice`);
expect(res.status).toBe(200);
@@ -136,7 +137,8 @@ describe.each(stores)('A subdomain server with %s', (name, { storeConfig, teardo
},
body: 'this is new data!',
});
expect(res.status).toBe(205);
expect(res.status).toBe(201);
expect(res.headers.get('location')).toBe(`${podUrl}alice`);
res = await fetch(`${baseUrl}alice`, {
headers: {