Page MenuHomeSealhub

image.test.ts
No OneTemporary

image.test.ts

import assert from "assert";
import { Collection } from "../../../main.js";
import { MockRestApi } from "../../../test_utils/test-utils.js";
import { App } from "../../app.js";
import Image from "./image.js";
import _locreq from "locreq";
import { module_dirname } from "../../../utils/module_filename.js";
import { withRunningApp } from "../../../test_utils/with-test-app.js";
import { FilePointer } from "@sealcode/file-manager";
const locreq = _locreq(module_dirname(import.meta.url));
describe("FieldTypes.Image", () => {
it("returns an instance of File when provided with the format 'file'", async () =>
withRunningApp(
(app) =>
class extends app {
collections = {
...App.BaseCollections,
images: new (class extends Collection {
fields = { image: new Image() };
})(),
};
},
async ({ app }) => {
await app.collections.images.create(new app.SuperContext(), {
image: app.FileManager.fromPath(
locreq.resolve("src/assets/logo.png")
),
});
const {
items: [item],
} = await app.collections.images
.list(new app.SuperContext())
.format({ image: "file" })
.fetch();
assert(item.get("image") instanceof FilePointer);
}
));
it("handles an array with a single file as input", async () =>
withRunningApp(
(app) =>
class extends app {
collections = {
...App.BaseCollections,
images: new (class extends Collection {
fields = { image: new Image() };
})(),
};
},
async ({ app }) => {
await app.collections.images.create(new app.SuperContext(), {
image: [
app.FileManager.fromPath(
locreq.resolve("src/assets/logo.png")
),
],
});
const {
items: [item],
} = await app.collections.images
.list(new app.SuperContext())
.format({ image: "file" })
.fetch();
assert(item.get("image") instanceof FilePointer);
}
));
it("should format image as a url path (no hostname)", async () =>
withRunningApp(
(app) =>
class extends app {
collections = {
...App.BaseCollections,
images: new (class extends Collection {
fields = { image: new Image() };
})(),
};
},
async ({ app, rest_api }) => {
await app.collections.images.create(new app.SuperContext(), {
image: [
app.FileManager.fromPath(
locreq.resolve("src/assets/logo.png")
),
],
});
const {
items: [item],
} = await app.collections.images
.list(new app.SuperContext())
.format({ image: "path" })
.fetch();
const response = await rest_api.get(
item.get("image") as string
);
assert(!!response);
}
));
it("should format image as full url (with hostname)", async () =>
withRunningApp(
(app) =>
class extends app {
collections = {
...App.BaseCollections,
images: new (class extends Collection {
fields = { image: new Image() };
})(),
};
},
async ({ app }) => {
await app.collections.images.create(new app.SuperContext(), {
image: [
app.FileManager.fromPath(
locreq.resolve("src/assets/logo.png")
),
],
});
const {
items: [item],
} = await app.collections.images
.list(new app.SuperContext())
.format({ image: "url" })
.fetch();
const response = await MockRestApi.getWithFullUrl(
item.get("image") as string
);
assert(response.status === 200);
}
));
});

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:48 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
635934
Default Alt Text
image.test.ts (3 KB)

Event Timeline