Files
rustfs-console/tests/lib/object-versions-source.test.js

64 lines
3.2 KiB
JavaScript

import test from "node:test"
import assert from "node:assert/strict"
import fs from "node:fs"
import { capabilityCheckGroups } from "../../lib/permission-capabilities.ts"
test("object versions restore copies a source version back to the current object key", () => {
const hookSource = fs.readFileSync("hooks/use-object.ts", "utf8")
const componentSource = fs.readFileSync("components/object/versions.tsx", "utf8")
const permissionSource = fs.readFileSync("lib/permission-capabilities.ts", "utf8")
assert.match(hookSource, /const restoreObjectVersion = useCallback/)
assert.match(hookSource, /CopySource: encodeObjectCopySource\(bucket, key, versionId\)/)
assert.match(hookSource, /MetadataDirective: "COPY"/)
assert.match(hookSource, /TaggingDirective: "COPY"/)
assert.match(componentSource, /restoreObjectVersion\(objectKey, versionId\)/)
assert.match(componentSource, /canCapability\("objects\.version\.restore", objectContext\)/)
assert.match(componentSource, /!row\.original\.IsLatest/)
assert.match(permissionSource, /"objects\.version\.restore": \[\{ actions: \["s3:GetObjectVersion", "s3:PutObject"\]/)
const checks = capabilityCheckGroups("objects.version.restore", {
bucket: "bucket",
objectKey: "file.txt",
versionId: "old-version",
}).flatMap((group) => group.checks)
assert.equal(checks[0].action, "s3:GetObjectVersion")
assert.equal(checks[0].context.versionId, "old-version")
assert.deepEqual(checks[1].context.copySource, { bucket: "bucket", objectKey: "file.txt", versionId: "old-version" })
})
test("object versions dialog is wide, sortable by date and size, and shows summary statistics", () => {
const source = fs.readFileSync("components/object/versions.tsx", "utf8")
assert.match(source, /sm:max-w-5xl/)
assert.match(source, /count: versions\.length/)
assert.match(source, /totalSize: versions\.reduce/)
assert.match(source, /accessorFn: \(row\) => \(row\.LastModified \? new Date\(row\.LastModified\)\.getTime\(\) : 0\)/)
assert.match(source, /accessorFn: \(row\) => row\.Size \?\? 0/)
})
test("object versions dialog does not hide versions behind unreachable default pagination", () => {
const source = fs.readFileSync("components/object/versions.tsx", "utf8")
assert.match(source, /disablePagination: true/)
})
test("object versions delete button reflects the active delete request", () => {
const source = fs.readFileSync("components/object/versions.tsx", "utf8")
assert.match(source, /const \[deletingVersionId, setDeletingVersionId\] = React\.useState<string \| null>\(null\)/)
assert.match(source, /disabled=\{deletingVersionId === row\.original\.VersionId\}/)
assert.doesNotMatch(source, /variant="destructive"\s+size="sm"\s+className="text-white"/)
})
test("object version listing follows S3 version pagination markers", () => {
const source = fs.readFileSync("hooks/use-object.ts", "utf8")
assert.match(source, /let keyMarker: string \| undefined/)
assert.match(source, /let versionIdMarker: string \| undefined/)
assert.match(source, /KeyMarker: keyMarker/)
assert.match(source, /VersionIdMarker: versionIdMarker/)
assert.match(source, /keyMarker = res\.NextKeyMarker/)
assert.match(source, /versionIdMarker = res\.NextVersionIdMarker/)
assert.match(source, /while \(isTruncated\)/)
})