Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unit tests for federation #18

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 11 additions & 0 deletions src/federation/collection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from "bun:test";
import { Object as APObject, Collection } from "@fedify/fedify";
import { iterateCollection } from './collection';

test("iteration over empty Collection", async () => {
const result: APObject[] = [];
for await (const item of iterateCollection(new Collection({}))) {
result.push(item);
}
expect(result).toEqual([]);
});
27 changes: 27 additions & 0 deletions src/federation/date.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from "bun:test";
import { Temporal } from "@js-temporal/polyfill";
import { toTemporalInstant, toDate } from "./date";

const date = new Date("2024-08-31T10:00:00");
const temporalInstant = Temporal.Instant.from(date.toISOString());

test("toTemporalInstant call with null", ()=>{
expect(toTemporalInstant(null)).toEqual(null)
});

test("toTemporalInstant call with Date", ()=>{
expect(toTemporalInstant(date)).not.toEqual(null);
});

test("toDate call with null", ()=>{
expect(toDate(null)).toEqual(null);
});

test("toDate call with Temporal.Instant", ()=>{
expect(toDate(temporalInstant)).not.toEqual(null);
});

test("idempotency test", ()=>{
expect(toDate(toTemporalInstant(date))).not.toEqual(null);
expect(toTemporalInstant(toDate(temporalInstant))).not.toEqual(null);
});