Page MenuHomeSealhub

app.test.ts
No OneTemporary

app.test.ts

import assert from "assert";
import { default as Koa } from "koa";
import { withRunningApp } from "../../test_utils/with-test-app.js";
import { assertThrowsAsync } from "../../test_utils/assert-throws-async.js";
import { App } from "../app.js";
import Collection from "../../chip-types/collection.js";
import { FieldTypes } from "../../main.js";
import prettier from "prettier";
describe("app", () => {
describe("metadata", () => {
it("is cleared when running .removeAllData()", async () => {
return withRunningApp(
(app) => app,
async ({ app }) => {
await app.Metadata.set("some", "value");
assert.strictEqual(await app.Metadata.get("some"), "value");
await app.removeAllData();
assert.strictEqual(
await app.Metadata.get("some"),
undefined
);
}
);
});
});
describe(".start()", () => {
it("should throw an error if called twice", async () => {
return withRunningApp(
(app) => app,
async ({ app }) => {
await assertThrowsAsync(
() => app.start(),
(error) => {
assert.strictEqual(
error.message,
"app should be on 'stopped' status (current status - 'running')"
);
}
);
}
);
});
});
describe("atom feed", () => {
it("generates a valid XML feed for a list of blog items", async () =>
withRunningApp(
(t) =>
class extends t {
collections = {
...App.BaseCollections,
posts: new (class extends Collection {
fields = {
title: new FieldTypes.Text(),
content: new FieldTypes.Text(),
};
})(),
};
},
async ({ app, rest_api }) => {
const metatags = await app.getFeedHTMLMetatags({
$app: app,
} as unknown as Koa.Context);
assert.strictEqual(
await prettier.format(metatags, { parser: "html" }),
await prettier.format(
/* HTML */ `<link
href="/api/v1/collections/posts/feed"
type="application/atom+xml"
rel="alternate"
title="testing app / posts feed"
/>`,
{ parser: "html" }
)
);
}
));
});
});

File Metadata

Mime Type
text/x-java
Expires
Sat, Sep 20, 21:24 (4 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
949699
Default Alt Text
app.test.ts (2 KB)

Event Timeline