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