chore: vault tests refactors and lint (#2374)

This commit is contained in:
Karol Sójko
2023-08-02 00:23:56 +02:00
committed by GitHub
parent a0bc1d2488
commit 247daddf5a
96 changed files with 1463 additions and 751 deletions

View File

@@ -8,14 +8,16 @@ import { IntegrityApiInterface } from './IntegrityApiInterface'
import { IntegrityService } from './IntegrityService'
import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { IntegrityPayload } from '@standardnotes/responses'
import { LoggerInterface } from '@standardnotes/utils'
describe('IntegrityService', () => {
let integrityApi: IntegrityApiInterface
let itemApi: ItemsServerInterface
let payloadManager: PayloadManagerInterface
let logger: LoggerInterface
let internalEventBus: InternalEventBusInterface
const createService = () => new IntegrityService(integrityApi, itemApi, payloadManager, internalEventBus)
const createService = () => new IntegrityService(integrityApi, itemApi, payloadManager, logger, internalEventBus)
beforeEach(() => {
integrityApi = {} as jest.Mocked<IntegrityApiInterface>
@@ -29,6 +31,10 @@ describe('IntegrityService', () => {
internalEventBus = {} as jest.Mocked<InternalEventBusInterface>
internalEventBus.publishSync = jest.fn()
logger = {} as jest.Mocked<LoggerInterface>
logger.info = jest.fn()
logger.error = jest.fn()
})
it('should check integrity of payloads and publish mismatches', async () => {
@@ -63,7 +69,7 @@ describe('IntegrityService', () => {
uuid: '1-2-3',
},
],
source: "AfterDownloadFirst",
source: 'AfterDownloadFirst',
},
type: 'IntegrityCheckCompleted',
},
@@ -90,7 +96,7 @@ describe('IntegrityService', () => {
{
payload: {
rawPayloads: [],
source: "AfterDownloadFirst",
source: 'AfterDownloadFirst',
},
type: 'IntegrityCheckCompleted',
},
@@ -140,7 +146,7 @@ describe('IntegrityService', () => {
{
payload: {
rawPayloads: [],
source: "AfterDownloadFirst",
source: 'AfterDownloadFirst',
},
type: 'IntegrityCheckCompleted',
},

View File

@@ -10,6 +10,7 @@ import { SyncEvent } from '../Event/SyncEvent'
import { IntegrityEventPayload } from './IntegrityEventPayload'
import { SyncSource } from '../Sync/SyncSource'
import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { LoggerInterface } from '@standardnotes/utils'
export class IntegrityService
extends AbstractService<IntegrityEvent, IntegrityEventPayload>
@@ -19,6 +20,7 @@ export class IntegrityService
private integrityApi: IntegrityApiInterface,
private itemApi: ItemsServerInterface,
private payloadManager: PayloadManagerInterface,
private logger: LoggerInterface,
protected override internalEventBus: InternalEventBusInterface,
) {
super(internalEventBus)
@@ -31,7 +33,7 @@ export class IntegrityService
const integrityCheckResponse = await this.integrityApi.checkIntegrity(this.payloadManager.integrityPayloads)
if (isErrorResponse(integrityCheckResponse)) {
this.log(`Could not obtain integrity check: ${integrityCheckResponse.data.error?.message}`)
this.logger.error(`Could not obtain integrity check: ${integrityCheckResponse.data.error?.message}`)
return
}
@@ -50,7 +52,7 @@ export class IntegrityService
isErrorResponse(serverItemResponse) ||
!('item' in serverItemResponse.data)
) {
this.log(
this.logger.error(
`Could not obtain item for integrity adjustments: ${
isErrorResponse(serverItemResponse) ? serverItemResponse.data.error?.message : ''
}`,