From 55118df53842fc08ae3b2f29fa25d91013ed9281 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Fri, 2 Jun 2023 15:00:48 -0400 Subject: [PATCH] add test --- .../native-utils/__test__/index.spec.mjs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/backend/native-utils/__test__/index.spec.mjs b/packages/backend/native-utils/__test__/index.spec.mjs index 1788dbb061..6e6a91858c 100644 --- a/packages/backend/native-utils/__test__/index.spec.mjs +++ b/packages/backend/native-utils/__test__/index.spec.mjs @@ -1,6 +1,12 @@ import test from "ava"; -import { convertId, IdConvertType } from "../built/index.js"; +import { + convertId, + IdConvertType, + nativeInitIdGenerator, + nativeCreateId, + nativeRandomStr, +} from "../built/index.js"; test("convert to mastodon id", (t) => { t.is(convertId("9gf61ehcxv", IdConvertType.MastodonId), "960365976481219"); @@ -13,3 +19,14 @@ test("convert to mastodon id", (t) => { "3494513243013053824", ); }); + +test("create cuid2 with timestamp prefix", (t) => { + nativeInitIdGenerator(16, ""); + t.not(nativeCreateId(BigInt(Date.now())), nativeCreateId(BigInt(Date.now()))); + t.is(nativeCreateId(BigInt(Date.now())).length, 16); +}); + +test("create random string", (t) => { + t.not(nativeRandomStr(16), nativeRandomStr(16)); + t.is(nativeRandomStr(24).length, 24); +});