Page MenuHomeSealhub

url.test.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

url.test.ts

import assert from "assert";
import { Collection, FieldTypes, SuperContext } from "../../../main.js";
import { assertThrowsAsync } from "../../../test_utils/assert-throws-async.js";
import { TestApp } from "../../../test_utils/test-app.js";
import {
type TestAppConstructor,
withRunningApp,
} from "../../../test_utils/with-test-app.js";
import type { UrlParams } from "./url.js";
const create_app_with_url = (
test_app: TestAppConstructor<TestApp>,
params: UrlParams
) => {
const website = new (class extends Collection {
fields = {
url: new FieldTypes.Url(params),
};
})();
return class extends test_app {
collections = {
...TestApp.BaseCollections,
website,
};
};
};
describe("url", () => {
it("should be able to create any url when no options provided", async () => {
return withRunningApp(
(test_app) => create_app_with_url(test_app, {}),
async ({ app }) => {
const wb = await app.collections.website.create(
new app.SuperContext(),
{
url: "https://example.com/",
}
);
assert.strictEqual("https://example.com/", wb.get("url"));
}
);
});
it("should throw exception when domain is not allowed", async () => {
return withRunningApp(
(test_app) =>
create_app_with_url(test_app, {
allowed_origins: ["https://www.youtube.com"],
}),
async ({ app }) => {
await assertThrowsAsync(async () => {
await app.collections.website.create(
new app.SuperContext(),
{
url: "https://example.com/",
}
);
});
}
);
});
it("should throw exception when protocol is not allowed", async () => {
return withRunningApp(
(test_app) =>
create_app_with_url(test_app, { allowed_protocols: ["https"] }),
async ({ app }) => {
await assertThrowsAsync(async () => {
await app.collections.website.create(
new app.SuperContext(),
{
url: "http://example.com/",
}
);
});
}
);
});
});

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 16:15 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1197091
Default Alt Text
url.test.ts (1 KB)

Event Timeline