fix tests

This commit is contained in:
syuilo 2023-10-16 12:58:17 +09:00
parent 24437a04d4
commit 34d1b463a4
4 changed files with 18 additions and 17 deletions

View file

@ -35,7 +35,7 @@ describe('AnnouncementService', () => {
function createUser(data: Partial<MiUser> = {}) { function createUser(data: Partial<MiUser> = {}) {
const un = secureRndstr(16); const un = secureRndstr(16);
return usersRepository.insert({ return usersRepository.insert({
id: genAidx(new Date()), id: genAidx(Date.now()),
username: un, username: un,
usernameLower: un, usernameLower: un,
...data, ...data,

View file

@ -37,7 +37,7 @@ describe('RoleService', () => {
function createUser(data: Partial<MiUser> = {}) { function createUser(data: Partial<MiUser> = {}) {
const un = secureRndstr(16); const un = secureRndstr(16);
return usersRepository.insert({ return usersRepository.insert({
id: genAidx(new Date()), id: genAidx(Date.now()),
username: un, username: un,
usernameLower: un, usernameLower: un,
...data, ...data,
@ -47,7 +47,7 @@ describe('RoleService', () => {
function createRole(data: Partial<MiRole> = {}) { function createRole(data: Partial<MiRole> = {}) {
return rolesRepository.insert({ return rolesRepository.insert({
id: genAidx(new Date()), id: genAidx(Date.now()),
updatedAt: new Date(), updatedAt: new Date(),
lastUsedAt: new Date(), lastUsedAt: new Date(),
description: '', description: '',

View file

@ -23,6 +23,7 @@ import { secureRndstr } from '@/misc/secure-rndstr.js';
import { DownloadService } from '@/core/DownloadService.js'; import { DownloadService } from '@/core/DownloadService.js';
import { MetaService } from '@/core/MetaService.js'; import { MetaService } from '@/core/MetaService.js';
import type { MiRemoteUser } from '@/models/User.js'; import type { MiRemoteUser } from '@/models/User.js';
import { genAidx } from '@/misc/id/aidx.js';
import { MockResolver } from '../misc/mock-resolver.js'; import { MockResolver } from '../misc/mock-resolver.js';
const host = 'https://host1.test'; const host = 'https://host1.test';
@ -200,7 +201,7 @@ describe('ActivityPub', () => {
describe('Renderer', () => { describe('Renderer', () => {
test('Render an announce with visibility: followers', () => { test('Render an announce with visibility: followers', () => {
rendererService.renderAnnounce(null, { rendererService.renderAnnounce(null, {
createdAt: new Date(0), id: genAidx(Date.now()),
visibility: 'followers', visibility: 'followers',
} as MiNote); } as MiNote);
}); });

View file

@ -14,44 +14,44 @@ import { ulidRegExp, parseUlid } from '@/misc/id/ulid.js';
describe('misc:id', () => { describe('misc:id', () => {
test('aid', () => { test('aid', () => {
const date = new Date(); const date = Date.now();
const gotAid = genAid(date); const gotAid = genAid(date);
expect(gotAid).toMatch(aidRegExp); expect(gotAid).toMatch(aidRegExp);
expect(parseAid(gotAid).date.getTime()).toBe(date.getTime()); expect(parseAid(gotAid).date.getTime()).toBe(date);
}); });
test('aidx', () => { test('aidx', () => {
const date = new Date(); const date = Date.now();
const gotAidx = genAidx(date); const gotAidx = genAidx(date);
expect(gotAidx).toMatch(aidxRegExp); expect(gotAidx).toMatch(aidxRegExp);
expect(parseAidx(gotAidx).date.getTime()).toBe(date.getTime()); expect(parseAidx(gotAidx).date.getTime()).toBe(date);
}); });
test('meid', () => { test('meid', () => {
const date = new Date(); const date = Date.now();
const gotMeid = genMeid(date); const gotMeid = genMeid(date);
expect(gotMeid).toMatch(meidRegExp); expect(gotMeid).toMatch(meidRegExp);
expect(parseMeid(gotMeid).date.getTime()).toBe(date.getTime()); expect(parseMeid(gotMeid).date.getTime()).toBe(date);
}); });
test('meidg', () => { test('meidg', () => {
const date = new Date(); const date = Date.now();
const gotMeidg = genMeidg(date); const gotMeidg = genMeidg(date);
expect(gotMeidg).toMatch(meidgRegExp); expect(gotMeidg).toMatch(meidgRegExp);
expect(parseMeidg(gotMeidg).date.getTime()).toBe(date.getTime()); expect(parseMeidg(gotMeidg).date.getTime()).toBe(date);
}); });
test('objectid', () => { test('objectid', () => {
const date = new Date(); const date = Date.now();
const gotObjectId = genObjectId(date); const gotObjectId = genObjectId(date);
expect(gotObjectId).toMatch(objectIdRegExp); 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', () => { test('ulid', () => {
const date = new Date(); const date = Date.now();
const gotUlid = ulid(date.getTime()); const gotUlid = ulid(date);
expect(gotUlid).toMatch(ulidRegExp); expect(gotUlid).toMatch(ulidRegExp);
expect(parseUlid(gotUlid).date.getTime()).toBe(date.getTime()); expect(parseUlid(gotUlid).date.getTime()).toBe(date);
}); });
}); });