diff --git a/backend/src/diffs/diffs.service.ts b/backend/src/diffs/diffs.service.ts index b0b49f7e..d002c293 100644 --- a/backend/src/diffs/diffs.service.ts +++ b/backend/src/diffs/diffs.service.ts @@ -183,7 +183,7 @@ export class DiffsService { ).fill(0); for (let idx = 0; idx < arrLength; idx++) { const logicalIndex = this.getLogicalIndex( - diffDTOs[idx].S3DiffID, + diffDTOs[idx].S3DiffIndex, nextDiffID, arrLength, ); diff --git a/backend/src/diffs/dto/diffs.dto.ts b/backend/src/diffs/dto/diffs.dto.ts index bdb2ae3c..69d761f6 100644 --- a/backend/src/diffs/dto/diffs.dto.ts +++ b/backend/src/diffs/dto/diffs.dto.ts @@ -3,7 +3,7 @@ export class DiffDTO { MarkdownID: string; UserID: number; DisplayID: number; - S3DiffID: number; + S3DiffIndex: number; LastModified: Date; Content: string; SnapshotID: string; @@ -13,7 +13,7 @@ export class DiffDTO { this.MarkdownID = undefined; this.UserID = undefined; this.DisplayID = undefined; - this.S3DiffID = undefined; + this.S3DiffIndex = undefined; this.LastModified = undefined; this.Content = undefined; this.SnapshotID = undefined; diff --git a/backend/src/s3/s3.service.ts b/backend/src/s3/s3.service.ts index e6d51587..31bda753 100644 --- a/backend/src/s3/s3.service.ts +++ b/backend/src/s3/s3.service.ts @@ -427,7 +427,7 @@ export class S3Service { const diffDTOs: DiffDTO[] = []; const firstDiffID = - snapshotDTO.S3SnapshotID * + snapshotDTO.S3SnapshotIndex * parseInt(process.env.DIFFS_PER_SNAPSHOT); for ( @@ -584,11 +584,6 @@ export class S3Service { const filePath = `${diffDTO.UserID}/${diffDTO.MarkdownID}`; - console.log( - 'fileDTO.Content: ', - fileDTO.Content, - ); - try { await this.s3Client.send( new PutObjectCommand({ diff --git a/backend/src/snapshots/dto/snapshot.dto.ts b/backend/src/snapshots/dto/snapshot.dto.ts index cd66fd73..70ebe8ab 100644 --- a/backend/src/snapshots/dto/snapshot.dto.ts +++ b/backend/src/snapshots/dto/snapshot.dto.ts @@ -3,7 +3,7 @@ export class SnapshotDTO { MarkdownID: string; UserID: number; DisplayID: number; - S3SnapshotID: number; + S3SnapshotIndex: number; LastModified: Date; Content: string; OldestSnapshot: boolean; @@ -13,7 +13,7 @@ export class SnapshotDTO { this.MarkdownID = undefined; this.UserID = undefined; this.DisplayID = undefined; - this.S3SnapshotID = undefined; + this.S3SnapshotIndex = undefined; this.LastModified = undefined; this.Content = undefined; this.OldestSnapshot = false; diff --git a/backend/src/snapshots/snapshots.service.ts b/backend/src/snapshots/snapshots.service.ts index b57ad64e..86a8c639 100644 --- a/backend/src/snapshots/snapshots.service.ts +++ b/backend/src/snapshots/snapshots.service.ts @@ -188,7 +188,7 @@ export class SnapshotService { ).fill(0); for (let idx = 0; idx < arrLength; idx++) { const logicalIndex = this.getLogicalIndex( - snapshotDTOs[idx].S3SnapshotID, + snapshotDTOs[idx].S3SnapshotIndex, nextDiffID, arrLength, ); diff --git a/backend/src/version_control/version_control.service.spec.ts b/backend/src/version_control/version_control.service.spec.ts index 3c66216d..f0c48451 100644 --- a/backend/src/version_control/version_control.service.spec.ts +++ b/backend/src/version_control/version_control.service.spec.ts @@ -13,11 +13,13 @@ import { Repository } from 'typeorm'; import { MarkdownFile } from '../markdown_files/entities/markdown_file.entity'; import { SnapshotService } from '../snapshots/snapshots.service'; import { Snapshot } from '../snapshots/entities/snapshots.entity'; +import { DiffDTO } from '../diffs/dto/diffs.dto'; describe('VersionControlService', () => { let service: VersionControlService; let diffsService: DiffsService; let markdownFilesService: MarkdownFilesService; + let snapshotService: SnapshotService; let s3Service: S3Service; let s3ServiceMock: S3ServiceMock; @@ -64,9 +66,56 @@ describe('VersionControlService', () => { s3ServiceMock = module.get( S3ServiceMock, ); + + snapshotService = module.get( + SnapshotService, + ); }); it('should be defined', () => { expect(service).toBeDefined(); }); + + describe('saveSnapshot', () => { + const diffDTO = new DiffDTO(); + const nextSnaphshotID = 0; + it('should call the s3Service and save snapshot correctly', async () => { + jest.spyOn(s3Service, 'saveSnapshot'); + + jest + .spyOn(Repository.prototype, 'findOne') + .mockResolvedValueOnce(new Snapshot()); + + jest + .spyOn(Repository.prototype, 'save') + .mockResolvedValueOnce(new Snapshot()); + + jest + .spyOn(Repository.prototype, 'findOneBy') + .mockResolvedValueOnce( + new MarkdownFile(), + ); + + jest + .spyOn(Repository.prototype, 'save') + .mockResolvedValueOnce( + new MarkdownFile(), + ); + + jest.spyOn( + snapshotService, + 'updateSnapshot', + ); + + jest.spyOn( + markdownFilesService, + 'incrementNextSnapshotID', + ); + + const response = await service.saveSnapshot( + diffDTO, + nextSnaphshotID, + ); + }); + }); }); diff --git a/backend/src/version_control/version_control.service.ts b/backend/src/version_control/version_control.service.ts index 815e2220..33f9c272 100644 --- a/backend/src/version_control/version_control.service.ts +++ b/backend/src/version_control/version_control.service.ts @@ -272,7 +272,7 @@ export class VersionControlService { snapshotDTO.MarkdownID = snapshot.MarkdownID; snapshotDTO.UserID = snapshot.UserID; - snapshotDTO.S3SnapshotID = + snapshotDTO.S3SnapshotIndex = snapshot.S3SnapshotIndex; snapshotDTO.LastModified = snapshot.LastModified; @@ -291,7 +291,7 @@ export class VersionControlService { diffDTO.DiffID = diff.DiffID; diffDTO.MarkdownID = diff.MarkdownID; diffDTO.UserID = diff.UserID; - diffDTO.S3DiffID = diff.S3DiffIndex; + diffDTO.S3DiffIndex = diff.S3DiffIndex; diffDTO.LastModified = diff.LastModified; diffDTO.SnapshotID = diff.SnapshotID; diffDTOs.push(diffDTO);