Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/api/docs/src/models/record.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ record:
thumbnailUrls:
type: object
properties:
width256Status:
type: string
enum:
- ok
- processing
- failed
200:
type: string
256:
Expand Down Expand Up @@ -93,6 +99,12 @@ record:
type: array
items:
$ref: "./archive_file.yaml#/archiveFile"
accessCopyStatus:
type: string
enum:
- ok
- processing
- failed
folderLinkId:
type: string
folderLinkType:
Expand Down
117 changes: 116 additions & 1 deletion packages/api/src/record/controller/get_records_page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
import request from "supertest";
import { app } from "../../app.js";
import { db } from "../../database.js";
import type { ArchiveRecord, GetRecordsResponse } from "../models.js";
import {
AccessCopyStatus,
Thumbnail256Status,
type ArchiveRecord,
type GetRecordsResponse,
} from "../models.js";
import { runFixtures } from "../../../test/run_fixtures.js";
import {
mockExtractShareTokenFromHeaders,
Expand Down Expand Up @@ -48,6 +53,21 @@ const setupDatabase = async (): Promise<void> => {
]);
};

const setupStatusFieldDatabase = async (): Promise<void> => {
await runFixtures(db, [
"record.fixtures.create_test_accounts",
"record.fixtures.create_test_archives",
"record.fixtures.create_test_account_archives",
"record.fixtures.create_test_status_field_archives",
"record.fixtures.create_test_status_field_account_archives",
"record.fixtures.create_test_status_field_folders",
"record.fixtures.create_test_status_field_records",
"record.fixtures.create_test_status_field_files",
"record.fixtures.create_test_status_field_record_files",
"record.fixtures.create_test_status_field_folder_links",
]);
};

const clearDatabase = async (): Promise<void> => {
await db.query(
`TRUNCATE
Expand Down Expand Up @@ -380,3 +400,98 @@ describe("GET /records", () => {
expect(logger.error).toHaveBeenCalledWith(testError);
});
});

describe("GET /records accessCopyStatus and thumbnailUrls.width256Status", () => {
beforeEach(async () => {
mockExtractUserEmailFromAuthToken("test@permanent.org");
mockExtractShareTokenFromHeaders();
await clearDatabase();
await setupStatusFieldDatabase();
});

afterEach(async () => {
vi.restoreAllMocks();
vi.clearAllMocks();
});

afterAll(async () => {
await clearDatabase();
});

const agent = request(app);

test("expect accessCopyStatus to be ok when an archivematica access copy file exists", async () => {
const response = await agent
.get("/api/v2/records?recordIds[]=20001&pageSize=100")
.expect(200);
const { body } = response as { body: GetRecordsResponse };
expect(body.items).toHaveLength(1);
expect(body.items[0]?.accessCopyStatus).toEqual(AccessCopyStatus.Ok);
expect(body.items[0]?.thumbnailUrls.width256Status).toBeNull();
});

test("expect accessCopyStatus and thumbnailUrls.width256Status to be processing for a recent record with only an original image file", async () => {
const response = await agent
.get("/api/v2/records?recordIds[]=20002&pageSize=100")
.expect(200);
const { body } = response as { body: GetRecordsResponse };
expect(body.items).toHaveLength(1);
expect(body.items[0]?.accessCopyStatus).toEqual(
AccessCopyStatus.Processing,
);
expect(body.items[0]?.thumbnailUrls.width256Status).toEqual(
Thumbnail256Status.Processing,
);
});

test("expect thumbnailUrls.width256Status and accessCopyStatus to be failed for an old record with only an original image file and no 256px thumbnail", async () => {
const response = await agent
.get("/api/v2/records?recordIds[]=20003&pageSize=100")
.expect(200);
const { body } = response as { body: GetRecordsResponse };
expect(body.items).toHaveLength(1);
expect(body.items[0]?.thumbnailUrls.width256Status).toEqual(
Thumbnail256Status.Failed,
);
expect(body.items[0]?.accessCopyStatus).toBe(AccessCopyStatus.Failed);
});

test("expect thumbnailUrls.width256Status to be ok and the URL fields to pass through record thumbnail columns when a 256px thumbnail already exists", async () => {
const response = await agent
.get("/api/v2/records?recordIds[]=20004&pageSize=100")
.expect(200);
const { body } = response as { body: GetRecordsResponse };
expect(body.items).toHaveLength(1);
expect(body.items[0]?.accessCopyStatus).toBeNull();
expect(body.items[0]?.thumbnailUrls).toEqual({
width256Status: Thumbnail256Status.Ok,
"200": "https://localcdn.permanent.org/20004/thumb200.jpg",
"500": "https://localcdn.permanent.org/20004/thumb500.jpg",
"1000": "https://localcdn.permanent.org/20004/thumb1000.jpg",
"2000": "https://localcdn.permanent.org/20004/thumb2000.jpg",
"256": "https://localcdn.permanent.org/20004/thumb256.jpg",
});
});

test("expect accessCopyStatus and thumbnailUrls.width256Status to both be null for a record whose only file is an unsupported type", async () => {
const response = await agent
.get("/api/v2/records?recordIds[]=20005&pageSize=100")
.expect(200);
const { body } = response as { body: GetRecordsResponse };
expect(body.items).toHaveLength(1);
expect(body.items[0]?.accessCopyStatus).toBeNull();
expect(body.items[0]?.thumbnailUrls.width256Status).toBeNull();
});

test("expect accessCopyStatus to be processing for video files while thumbnailUrls.width256Status stays null, since 256px thumbnails aren't generated for video", async () => {
const response = await agent
.get("/api/v2/records?recordIds[]=20006&pageSize=100")
.expect(200);
const { body } = response as { body: GetRecordsResponse };
expect(body.items).toHaveLength(1);
expect(body.items[0]?.accessCopyStatus).toEqual(
AccessCopyStatus.Processing,
);
expect(body.items[0]?.thumbnailUrls.width256Status).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
INSERT INTO
account_archive (
account_archiveid,
accountid,
archiveid,
accessrole,
position,
type,
status,
createddt,
updateddt
)
VALUES
(
100,
2,
100,
'access.role.owner',
0,
'type.account.standard',
'status.generic.ok',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INSERT INTO
archive (archiveid, archivenbr, payeraccountid, public, type, status)
VALUES
(
100,
'0100-0100',
2,
false,
'type.archive.person',
'status.generic.ok'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
INSERT INTO file (
fileid,
archiveid,
size,
format,
type,
status,
fileurl,
downloadurl,
createddt,
updateddt
)
VALUES
(
20001,
100,
1024,
'file.format.archivematica.access',
'type.file.image.jpeg',
'status.generic.ok',
'https://localcdn.permanent.org/20001/file',
'https://localcdn.permanent.org/20001/download',
'2023-06-21T00:00:00.000Z',
'2023-06-21T00:00:00.000Z'
),
(
20002,
100,
1024,
'file.format.original',
'type.file.image.jpeg',
'status.generic.ok',
'https://localcdn.permanent.org/20002/file',
'https://localcdn.permanent.org/20002/download',
'2023-06-21T00:00:00.000Z',
'2023-06-21T00:00:00.000Z'
),
(
20003,
100,
1024,
'file.format.original',
'type.file.image.jpeg',
'status.generic.ok',
'https://localcdn.permanent.org/20003/file',
'https://localcdn.permanent.org/20003/download',
'2023-06-21T00:00:00.000Z',
'2023-06-21T00:00:00.000Z'
),
(
20004,
100,
1024,
'file.format.converted',
'type.file.image.jpg',
'status.generic.ok',
'https://localcdn.permanent.org/20004/file',
'https://localcdn.permanent.org/20004/download',
'2023-06-21T00:00:00.000Z',
'2023-06-21T00:00:00.000Z'
),
(
20005,
100,
1024,
'file.format.original',
'type.file.archive.zip',
'status.generic.ok',
'https://localcdn.permanent.org/20005/file',
'https://localcdn.permanent.org/20005/download',
'2023-06-21T00:00:00.000Z',
'2023-06-21T00:00:00.000Z'
),
(
20006,
100,
1024,
'file.format.original',
'type.file.video.mp4',
'status.generic.ok',
'https://localcdn.permanent.org/20006/file',
'https://localcdn.permanent.org/20006/download',
'2023-06-21T00:00:00.000Z',
'2023-06-21T00:00:00.000Z'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
INSERT INTO folder_link (
folder_linkid,
recordid,
folderid,
parentfolderid,
parentfolder_linkid,
archiveid,
position,
accessrole,
status,
type
)
VALUES
(
20001,
20001,
NULL,
100,
NULL,
100,
1,
'access.role.owner',
'status.generic.ok',
'type.folder_link.private'
),
(
20002,
20002,
NULL,
100,
NULL,
100,
1,
'access.role.owner',
'status.generic.ok',
'type.folder_link.private'
),
(
20003,
20003,
NULL,
100,
NULL,
100,
1,
'access.role.owner',
'status.generic.ok',
'type.folder_link.private'
),
(
20004,
20004,
NULL,
100,
NULL,
100,
1,
'access.role.owner',
'status.generic.ok',
'type.folder_link.private'
),
(
20005,
20005,
NULL,
100,
NULL,
100,
1,
'access.role.owner',
'status.generic.ok',
'type.folder_link.private'
),
(
20006,
20006,
NULL,
100,
NULL,
100,
1,
'access.role.owner',
'status.generic.ok',
'type.folder_link.private'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
INSERT INTO
folder (
folderid,
archiveid,
publicdt,
displayname,
downloadname,
status,
createddt,
type
)
VALUES
(
100,
100,
NULL,
'Status Field Test Root',
'Status Field Test Root',
'status.generic.ok',
CURRENT_TIMESTAMP,
'type.folder.root.private'
);
Loading
Loading