chore: vault tests refactors and lint (#2374)
This commit is contained in:
@@ -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',
|
||||
},
|
||||
|
||||
@@ -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 : ''
|
||||
}`,
|
||||
|
||||
Reference in New Issue
Block a user