fix(syncing-server): add missing messages and key system identifier sql representations (#663)

This commit is contained in:
Karol Sójko
2023-07-19 08:31:23 +02:00
committed by GitHub
parent 3f21a358d2
commit d026152ac8
18 changed files with 171 additions and 33 deletions
@@ -388,12 +388,12 @@ describe('SaveNewItem', () => {
expect(itemRepository.save).toHaveBeenCalled()
})
it('should return a failure if the item hash has an invalid key system uuid', async () => {
it('should return a failure if the item hash has an invalid key system identifier', async () => {
const useCase = createUseCase()
itemHash1 = ItemHash.create({
...itemHash1.props,
key_system_identifier: '1-2-3',
key_system_identifier: 123 as unknown as string,
}).getValue()
const result = await useCase.execute({
@@ -6,6 +6,7 @@ import {
UniqueEntityId,
UseCaseInterface,
Uuid,
Validator,
} from '@standardnotes/domain-core'
import { TimerInterface } from '@standardnotes/time'
import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
@@ -111,11 +112,11 @@ export class SaveNewItem implements UseCaseInterface<Item> {
let keySystemAssociation = undefined
if (dto.itemHash.hasDedicatedKeySystemAssociation()) {
const keySystemUuidOrError = Uuid.create(dto.itemHash.props.key_system_identifier as string)
if (keySystemUuidOrError.isFailed()) {
return Result.fail(keySystemUuidOrError.getError())
const keySystemIdentifiedValidationResult = Validator.isNotEmptyString(dto.itemHash.props.key_system_identifier)
if (keySystemIdentifiedValidationResult.isFailed()) {
return Result.fail(keySystemIdentifiedValidationResult.getError())
}
const keySystemUuid = keySystemUuidOrError.getValue()
const keySystemIdentifier = dto.itemHash.props.key_system_identifier as string
const keySystemAssociationOrError = KeySystemAssociation.create({
itemUuid: uuid,
@@ -123,7 +124,7 @@ export class SaveNewItem implements UseCaseInterface<Item> {
this.timer.getTimestampInMicroseconds(),
this.timer.getTimestampInMicroseconds(),
).getValue(),
keySystemUuid,
keySystemIdentifier,
})
if (keySystemAssociationOrError.isFailed()) {
return Result.fail(keySystemAssociationOrError.getError())
@@ -385,7 +385,7 @@ describe('UpdateExistingItem', () => {
})
expect(result.isFailed()).toBeFalsy()
expect(item1.props.keySystemAssociation).not.toBeUndefined()
expect(item1.props.keySystemAssociation?.props.keySystemUuid.value).toBe('00000000-0000-0000-0000-000000000000')
expect(item1.props.keySystemAssociation?.props.keySystemIdentifier).toBe('00000000-0000-0000-0000-000000000000')
})
it('should not add a key system association if item hash has a dedicated key system and the existing item is already associated to the key system', async () => {
@@ -398,7 +398,7 @@ describe('UpdateExistingItem', () => {
item1.props.keySystemAssociation = KeySystemAssociation.create({
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
keySystemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
keySystemIdentifier: '00000000-0000-0000-0000-000000000000',
timestamps: Timestamps.create(123, 123).getValue(),
}).getValue()
const idBefore = item1.props.keySystemAssociation?.id.toString()
@@ -416,12 +416,12 @@ describe('UpdateExistingItem', () => {
expect(item1.props.keySystemAssociation.id.toString()).toEqual(idBefore)
})
it('should return error if key system uuid is invalid', async () => {
it('should return error if key system identifier is invalid', async () => {
const useCase = createUseCase()
const itemHash = ItemHash.create({
...itemHash1.props,
key_system_identifier: 'invalid-uuid',
key_system_identifier: 123 as unknown as string,
}).getValue()
const result = await useCase.execute({
@@ -1,4 +1,4 @@
import { ContentType, Dates, Result, Timestamps, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
import { ContentType, Dates, Result, Timestamps, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core'
import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
import { TimerInterface } from '@standardnotes/time'
@@ -135,11 +135,11 @@ export class UpdateExistingItem implements UseCaseInterface<Item> {
dto.itemHash.hasDedicatedKeySystemAssociation() &&
!this.itemIsAlreadyAssociatedWithTheKeySystem(dto.existingItem, dto.itemHash)
) {
const keySystemUuidOrError = Uuid.create(dto.itemHash.props.key_system_identifier as string)
if (keySystemUuidOrError.isFailed()) {
return Result.fail(keySystemUuidOrError.getError())
const keySystemIdentifiedValidationResult = Validator.isNotEmptyString(dto.itemHash.props.key_system_identifier)
if (keySystemIdentifiedValidationResult.isFailed()) {
return Result.fail(keySystemIdentifiedValidationResult.getError())
}
const keySystemUuid = keySystemUuidOrError.getValue()
const keySystemIdentifier = dto.itemHash.props.key_system_identifier as string
const keySystemAssociationOrError = KeySystemAssociation.create({
itemUuid: Uuid.create(dto.existingItem.id.toString()).getValue(),
@@ -147,7 +147,7 @@ export class UpdateExistingItem implements UseCaseInterface<Item> {
this.timer.getTimestampInMicroseconds(),
this.timer.getTimestampInMicroseconds(),
).getValue(),
keySystemUuid,
keySystemIdentifier,
})
if (keySystemAssociationOrError.isFailed()) {
return Result.fail(keySystemAssociationOrError.getError())
@@ -203,7 +203,7 @@ export class UpdateExistingItem implements UseCaseInterface<Item> {
private itemIsAlreadyAssociatedWithTheKeySystem(item: Item, itemHash: ItemHash): boolean {
return (
item.props.keySystemAssociation !== undefined &&
item.props.keySystemAssociation.props.keySystemUuid.value === itemHash.props.key_system_identifier
item.props.keySystemAssociation.props.keySystemIdentifier === itemHash.props.key_system_identifier
)
}
}