refactor: test utils (#16588)

This commit is contained in:
Jason Rasmussen 2025-03-04 11:15:41 -05:00 committed by GitHub
parent 1423cfd53c
commit 63c01b78e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 245 additions and 216 deletions

View file

@ -34,7 +34,7 @@ describe(MetadataService.name, () => {
let mocks: ServiceMocks;
beforeEach(() => {
({ sut, mocks } = newTestService(MetadataService, { metadataRepository }));
({ sut, mocks } = newTestService(MetadataService, { metadata: metadataRepository }));
mocks.storage.stat.mockResolvedValue({ size: 123_456 } as Stats);

View file

@ -37,7 +37,7 @@ describe(SyncService.name, () => {
it('should detect and sync the first user', async () => {
const { context, auth, sut, testSync } = await setup();
const user = await context.userRepository.get(auth.user.id, { withDeleted: false });
const user = await context.user.get(auth.user.id, { withDeleted: false });
if (!user) {
expect.fail('First user should exist');
}
@ -109,7 +109,7 @@ describe(SyncService.name, () => {
const { auth, context, sut, testSync } = await setup();
const user = await context.createUser();
await context.userRepository.delete({ id: user.id }, true);
await context.user.delete({ id: user.id }, true);
const response = await testSync(auth, [SyncRequestType.UsersV1]);
@ -167,7 +167,7 @@ describe(SyncService.name, () => {
const acks = [initialSyncResponse[0].ack];
await sut.setAcks(auth, { acks });
const updated = await context.userRepository.update(auth.user.id, { name: 'new name' });
const updated = await context.user.update(auth.user.id, { name: 'new name' });
const updatedSyncResponse = await testSync(auth, [SyncRequestType.UsersV1]);
@ -230,7 +230,7 @@ describe(SyncService.name, () => {
const user2 = await context.createUser();
const partner = await context.createPartner({ sharedById: user2.id, sharedWithId: user1.id });
await context.partnerRepository.remove(partner);
await context.partner.remove(partner);
const response = await testSync(auth, [SyncRequestType.PartnersV1]);
@ -326,7 +326,7 @@ describe(SyncService.name, () => {
const acks = [initialSyncResponse[0].ack];
await sut.setAcks(auth, { acks });
const updated = await context.partnerRepository.update(
const updated = await context.partner.update(
{ sharedById: partner.sharedById, sharedWithId: partner.sharedWithId },
{ inTimeline: true },
);

View file

@ -21,12 +21,12 @@ describe(VersionService.name, () => {
it('record the current version on startup', async () => {
const { context, sut } = await setup();
const itemsBefore = await context.versionHistoryRepository.getAll();
const itemsBefore = await context.versionHistory.getAll();
expect(itemsBefore).toHaveLength(0);
await sut.onBootstrap();
const itemsAfter = await context.versionHistoryRepository.getAll();
const itemsAfter = await context.versionHistory.getAll();
expect(itemsAfter).toHaveLength(1);
expect(itemsAfter[0]).toEqual({
createdAt: expect.any(Date),
@ -38,7 +38,7 @@ describe(VersionService.name, () => {
it('should queue memory creation when upgrading from 1.128.0', async () => {
const { context, jobMock, sut } = await setup();
await context.versionHistoryRepository.create({ version: 'v1.128.0' });
await context.versionHistory.create({ version: 'v1.128.0' });
await sut.onBootstrap();
expect(jobMock.queue).toHaveBeenCalledWith({ name: JobName.MEMORIES_CREATE });
@ -47,7 +47,7 @@ describe(VersionService.name, () => {
it('should not queue memory creation when upgrading from 1.129.0', async () => {
const { context, jobMock, sut } = await setup();
await context.versionHistoryRepository.create({ version: 'v1.129.0' });
await context.versionHistory.create({ version: 'v1.129.0' });
await sut.onBootstrap();
expect(jobMock.queue).not.toHaveBeenCalled();