mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add GET /attachments endpoint for listing attachment metadata
Summary: Combines the code and behaviour of the existing endpoints `GET /records` (for the general shape of the result and the parameters for sort/filter/limit etc) and retrieving a specific attachment with `GET /attachments/:id` for handling fields specific to attachments. Test Plan: Added a DocApi test. Also updated one test to use the new endpoint instead of raw `GET /tables/_grist_Attachments/records`. Reviewers: cyprien Reviewed By: cyprien Subscribers: cyprien Differential Revision: https://phab.getgrist.com/D3443
This commit is contained in:
@@ -1460,6 +1460,23 @@ function testDocApi() {
|
||||
assert.deepEqual(resp.data, [3]);
|
||||
});
|
||||
|
||||
it("GET /docs/{did}/attachments lists attachment metadata", async function() {
|
||||
// Test that the usual /records query parameters like sort and filter also work
|
||||
const url = `${serverUrl}/api/docs/${docIds.TestDoc}/attachments?sort=-fileName&limit=2`;
|
||||
const resp = await axios.get(url, chimpy);
|
||||
assert.equal(resp.status, 200);
|
||||
const {records} = resp.data;
|
||||
for (const record of records) {
|
||||
assert.match(record.fields.timeUploaded, /^\d{4}-\d{2}-\d{2}T/);
|
||||
delete record.fields.timeUploaded;
|
||||
}
|
||||
assert.deepEqual(records, [
|
||||
{id: 2, fields: {fileName: "world.jpg", fileSize: 6}},
|
||||
{id: 3, fields: {fileName: "hello.png", fileSize: 6}},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("GET /docs/{did}/attachments/{id} returns attachment metadata", async function() {
|
||||
const resp = await axios.get(`${serverUrl}/api/docs/${docIds.TestDoc}/attachments/2`, chimpy);
|
||||
assert.equal(resp.status, 200);
|
||||
@@ -1700,10 +1717,7 @@ function testDocApi() {
|
||||
assert.deepEqual(resp.data, [1, 2, 3]);
|
||||
|
||||
async function checkAttachmentIds(ids: number[]) {
|
||||
resp = await axios.get(
|
||||
`${docUrl}/tables/_grist_Attachments/records`,
|
||||
chimpy,
|
||||
);
|
||||
resp = await axios.get(`${docUrl}/attachments`, chimpy);
|
||||
assert.equal(resp.status, 200);
|
||||
assert.deepEqual(resp.data.records.map((r: any) => r.id), ids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user