From 34d1b463a42ab82295b0254b7d97dfb9586600e9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 16 Oct 2023 12:58:17 +0900 Subject: [PATCH] fix tests --- .../backend/test/unit/AnnouncementService.ts | 2 +- packages/backend/test/unit/RoleService.ts | 4 +-- packages/backend/test/unit/activitypub.ts | 3 ++- packages/backend/test/unit/misc/id.ts | 26 +++++++++---------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/backend/test/unit/AnnouncementService.ts b/packages/backend/test/unit/AnnouncementService.ts index 5fe41d1962..f2aa5d35e4 100644 --- a/packages/backend/test/unit/AnnouncementService.ts +++ b/packages/backend/test/unit/AnnouncementService.ts @@ -35,7 +35,7 @@ describe('AnnouncementService', () => { function createUser(data: Partial = {}) { const un = secureRndstr(16); return usersRepository.insert({ - id: genAidx(new Date()), + id: genAidx(Date.now()), username: un, usernameLower: un, ...data, diff --git a/packages/backend/test/unit/RoleService.ts b/packages/backend/test/unit/RoleService.ts index 41a2e49ed0..8b5e3163c3 100644 --- a/packages/backend/test/unit/RoleService.ts +++ b/packages/backend/test/unit/RoleService.ts @@ -37,7 +37,7 @@ describe('RoleService', () => { function createUser(data: Partial = {}) { const un = secureRndstr(16); return usersRepository.insert({ - id: genAidx(new Date()), + id: genAidx(Date.now()), username: un, usernameLower: un, ...data, @@ -47,7 +47,7 @@ describe('RoleService', () => { function createRole(data: Partial = {}) { return rolesRepository.insert({ - id: genAidx(new Date()), + id: genAidx(Date.now()), updatedAt: new Date(), lastUsedAt: new Date(), description: '', diff --git a/packages/backend/test/unit/activitypub.ts b/packages/backend/test/unit/activitypub.ts index 2e9454927c..c418e8413d 100644 --- a/packages/backend/test/unit/activitypub.ts +++ b/packages/backend/test/unit/activitypub.ts @@ -23,6 +23,7 @@ import { secureRndstr } from '@/misc/secure-rndstr.js'; import { DownloadService } from '@/core/DownloadService.js'; import { MetaService } from '@/core/MetaService.js'; import type { MiRemoteUser } from '@/models/User.js'; +import { genAidx } from '@/misc/id/aidx.js'; import { MockResolver } from '../misc/mock-resolver.js'; const host = 'https://host1.test'; @@ -200,7 +201,7 @@ describe('ActivityPub', () => { describe('Renderer', () => { test('Render an announce with visibility: followers', () => { rendererService.renderAnnounce(null, { - createdAt: new Date(0), + id: genAidx(Date.now()), visibility: 'followers', } as MiNote); }); diff --git a/packages/backend/test/unit/misc/id.ts b/packages/backend/test/unit/misc/id.ts index 57b4ea9947..59783a9fa1 100644 --- a/packages/backend/test/unit/misc/id.ts +++ b/packages/backend/test/unit/misc/id.ts @@ -14,44 +14,44 @@ import { ulidRegExp, parseUlid } from '@/misc/id/ulid.js'; describe('misc:id', () => { test('aid', () => { - const date = new Date(); + const date = Date.now(); const gotAid = genAid(date); expect(gotAid).toMatch(aidRegExp); - expect(parseAid(gotAid).date.getTime()).toBe(date.getTime()); + expect(parseAid(gotAid).date.getTime()).toBe(date); }); test('aidx', () => { - const date = new Date(); + const date = Date.now(); const gotAidx = genAidx(date); expect(gotAidx).toMatch(aidxRegExp); - expect(parseAidx(gotAidx).date.getTime()).toBe(date.getTime()); + expect(parseAidx(gotAidx).date.getTime()).toBe(date); }); test('meid', () => { - const date = new Date(); + const date = Date.now(); const gotMeid = genMeid(date); expect(gotMeid).toMatch(meidRegExp); - expect(parseMeid(gotMeid).date.getTime()).toBe(date.getTime()); + expect(parseMeid(gotMeid).date.getTime()).toBe(date); }); test('meidg', () => { - const date = new Date(); + const date = Date.now(); const gotMeidg = genMeidg(date); expect(gotMeidg).toMatch(meidgRegExp); - expect(parseMeidg(gotMeidg).date.getTime()).toBe(date.getTime()); + expect(parseMeidg(gotMeidg).date.getTime()).toBe(date); }); test('objectid', () => { - const date = new Date(); + const date = Date.now(); const gotObjectId = genObjectId(date); expect(gotObjectId).toMatch(objectIdRegExp); - expect(Math.floor(parseObjectId(gotObjectId).date.getTime() / 1000)).toBe(Math.floor(date.getTime() / 1000)); + expect(Math.floor(parseObjectId(gotObjectId).date.getTime() / 1000)).toBe(Math.floor(date / 1000)); }); test('ulid', () => { - const date = new Date(); - const gotUlid = ulid(date.getTime()); + const date = Date.now(); + const gotUlid = ulid(date); expect(gotUlid).toMatch(ulidRegExp); - expect(parseUlid(gotUlid).date.getTime()).toBe(date.getTime()); + expect(parseUlid(gotUlid).date.getTime()).toBe(date); }); });