2023-07-27 08:31:52 +03:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { ulid } from 'ulid';
|
|
|
|
import { describe, test, expect } from '@jest/globals';
|
2023-04-08 22:41:06 +03:00
|
|
|
import { aidRegExp, genAid, parseAid } from '@/misc/id/aid.js';
|
2023-09-06 12:33:51 +03:00
|
|
|
import { aidxRegExp, genAidx, parseAidx } from '@/misc/id/aidx.js';
|
2023-04-08 22:41:06 +03:00
|
|
|
import { genMeid, meidRegExp, parseMeid } from '@/misc/id/meid.js';
|
|
|
|
import { genMeidg, meidgRegExp, parseMeidg } from '@/misc/id/meidg.js';
|
|
|
|
import { genObjectId, objectIdRegExp, parseObjectId } from '@/misc/id/object-id.js';
|
|
|
|
import { ulidRegExp, parseUlid } from '@/misc/id/ulid.js';
|
|
|
|
|
|
|
|
describe('misc:id', () => {
|
2023-07-27 08:31:52 +03:00
|
|
|
test('aid', () => {
|
2023-10-16 06:58:17 +03:00
|
|
|
const date = Date.now();
|
2023-07-27 08:31:52 +03:00
|
|
|
const gotAid = genAid(date);
|
|
|
|
expect(gotAid).toMatch(aidRegExp);
|
2023-10-16 06:58:17 +03:00
|
|
|
expect(parseAid(gotAid).date.getTime()).toBe(date);
|
2023-07-27 08:31:52 +03:00
|
|
|
});
|
2023-04-08 22:41:06 +03:00
|
|
|
|
2023-09-06 12:33:51 +03:00
|
|
|
test('aidx', () => {
|
2023-10-16 06:58:17 +03:00
|
|
|
const date = Date.now();
|
2023-09-06 12:33:51 +03:00
|
|
|
const gotAidx = genAidx(date);
|
|
|
|
expect(gotAidx).toMatch(aidxRegExp);
|
2023-10-16 06:58:17 +03:00
|
|
|
expect(parseAidx(gotAidx).date.getTime()).toBe(date);
|
2023-09-06 12:33:51 +03:00
|
|
|
});
|
|
|
|
|
2023-07-27 08:31:52 +03:00
|
|
|
test('meid', () => {
|
2023-10-16 06:58:17 +03:00
|
|
|
const date = Date.now();
|
2023-07-27 08:31:52 +03:00
|
|
|
const gotMeid = genMeid(date);
|
|
|
|
expect(gotMeid).toMatch(meidRegExp);
|
2023-10-16 06:58:17 +03:00
|
|
|
expect(parseMeid(gotMeid).date.getTime()).toBe(date);
|
2023-07-27 08:31:52 +03:00
|
|
|
});
|
2023-04-08 22:41:06 +03:00
|
|
|
|
2023-07-27 08:31:52 +03:00
|
|
|
test('meidg', () => {
|
2023-10-16 06:58:17 +03:00
|
|
|
const date = Date.now();
|
2023-07-27 08:31:52 +03:00
|
|
|
const gotMeidg = genMeidg(date);
|
|
|
|
expect(gotMeidg).toMatch(meidgRegExp);
|
2023-10-16 06:58:17 +03:00
|
|
|
expect(parseMeidg(gotMeidg).date.getTime()).toBe(date);
|
2023-07-27 08:31:52 +03:00
|
|
|
});
|
2023-04-08 22:41:06 +03:00
|
|
|
|
2023-07-27 08:31:52 +03:00
|
|
|
test('objectid', () => {
|
2023-10-16 06:58:17 +03:00
|
|
|
const date = Date.now();
|
2023-07-27 08:31:52 +03:00
|
|
|
const gotObjectId = genObjectId(date);
|
|
|
|
expect(gotObjectId).toMatch(objectIdRegExp);
|
2023-10-16 06:58:17 +03:00
|
|
|
expect(Math.floor(parseObjectId(gotObjectId).date.getTime() / 1000)).toBe(Math.floor(date / 1000));
|
2023-07-27 08:31:52 +03:00
|
|
|
});
|
2023-04-08 22:41:06 +03:00
|
|
|
|
2023-07-27 08:31:52 +03:00
|
|
|
test('ulid', () => {
|
2023-10-16 06:58:17 +03:00
|
|
|
const date = Date.now();
|
|
|
|
const gotUlid = ulid(date);
|
2023-07-27 08:31:52 +03:00
|
|
|
expect(gotUlid).toMatch(ulidRegExp);
|
2023-10-16 06:58:17 +03:00
|
|
|
expect(parseUlid(gotUlid).date.getTime()).toBe(date);
|
2023-07-27 08:31:52 +03:00
|
|
|
});
|
2023-04-08 22:41:06 +03:00
|
|
|
});
|