2023-04-06 19:56:46 -06:00
|
|
|
import test from "ava";
|
2023-03-30 19:58:28 -06:00
|
|
|
|
2023-06-02 13:00:48 -06:00
|
|
|
import {
|
|
|
|
convertId,
|
|
|
|
IdConvertType,
|
|
|
|
nativeInitIdGenerator,
|
|
|
|
nativeCreateId,
|
|
|
|
nativeRandomStr,
|
|
|
|
} from "../built/index.js";
|
2023-03-30 19:58:28 -06:00
|
|
|
|
2023-05-28 18:24:48 -06:00
|
|
|
test("convert to mastodon id", (t) => {
|
|
|
|
t.is(convertId("9gf61ehcxv", IdConvertType.MastodonId), "960365976481219");
|
2023-05-29 10:31:02 -06:00
|
|
|
t.is(
|
|
|
|
convertId("9fbr9z0wbrjqyd3u", IdConvertType.MastodonId),
|
2023-07-09 23:39:33 -06:00
|
|
|
"2083785058661759970208986",
|
2023-05-29 10:31:02 -06:00
|
|
|
);
|
|
|
|
t.is(
|
|
|
|
convertId("9fbs680oyviiqrol9md73p8g", IdConvertType.MastodonId),
|
2023-07-09 23:39:33 -06:00
|
|
|
"5878598648988104013828532260828151168",
|
2023-05-29 10:31:02 -06:00
|
|
|
);
|
2023-04-06 19:56:46 -06:00
|
|
|
});
|
2023-06-02 13:00:48 -06:00
|
|
|
|
|
|
|
test("create cuid2 with timestamp prefix", (t) => {
|
|
|
|
nativeInitIdGenerator(16, "");
|
2023-07-09 23:39:33 -06:00
|
|
|
t.not(nativeCreateId(Date.now()), nativeCreateId(Date.now()));
|
|
|
|
t.is(nativeCreateId(Date.now()).length, 16);
|
2023-06-02 13:00:48 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
test("create random string", (t) => {
|
|
|
|
t.not(nativeRandomStr(16), nativeRandomStr(16));
|
|
|
|
t.is(nativeRandomStr(24).length, 24);
|
|
|
|
});
|