fix failure of saving highlight when position is null
This commit is contained in:
@ -59,11 +59,11 @@ export class Highlight {
|
||||
@Column('timestamp')
|
||||
sharedAt?: Date
|
||||
|
||||
@Column('real')
|
||||
highlightPositionPercent?: number | null
|
||||
@Column('real', { default: 0 })
|
||||
highlightPositionPercent!: number
|
||||
|
||||
@Column('integer')
|
||||
highlightPositionAnchorIndex?: number | null
|
||||
@Column('integer', { default: 0 })
|
||||
highlightPositionAnchorIndex!: number
|
||||
|
||||
@Column('enum', {
|
||||
enum: HighlightType,
|
||||
|
||||
@ -47,7 +47,9 @@ export const createHighlightResolver = authorized<
|
||||
...input,
|
||||
user: { id: uid },
|
||||
libraryItem: { id: input.articleId },
|
||||
highlightType: input.type as HighlightType,
|
||||
highlightType: input.type || HighlightType.Highlight,
|
||||
highlightPositionAnchorIndex: input.highlightPositionAnchorIndex || 0,
|
||||
highlightPositionPercent: input.highlightPositionPercent || 0,
|
||||
},
|
||||
input.articleId,
|
||||
uid,
|
||||
@ -125,6 +127,8 @@ export const mergeHighlightResolver = authorized<
|
||||
color,
|
||||
user: { id: uid },
|
||||
libraryItem: { id: input.articleId },
|
||||
highlightPositionAnchorIndex: input.highlightPositionAnchorIndex || 0,
|
||||
highlightPositionPercent: input.highlightPositionPercent || 0,
|
||||
}
|
||||
|
||||
const newHighlight = await mergeHighlights(
|
||||
|
||||
@ -3,8 +3,10 @@ import { expect } from 'chai'
|
||||
import chaiString from 'chai-string'
|
||||
import 'mocha'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { createHighlight } from '../../src/services/highlights'
|
||||
import { updateLibraryItem } from '../../src/services/library_item'
|
||||
import {
|
||||
createHighlight,
|
||||
deleteHighlightById,
|
||||
} from '../../src/services/highlights'
|
||||
import { deleteUser } from '../../src/services/user'
|
||||
import { createTestLibraryItem, createTestUser } from '../db'
|
||||
import { generateFakeUuid, graphqlRequest, request } from '../util'
|
||||
@ -15,8 +17,8 @@ const createHighlightQuery = (
|
||||
linkId: string,
|
||||
highlightId: string,
|
||||
shortHighlightId: string,
|
||||
highlightPositionPercent = 0.0,
|
||||
highlightPositionAnchorIndex = 0,
|
||||
highlightPositionPercent: number | null = null,
|
||||
highlightPositionAnchorIndex: number | null = null,
|
||||
annotation = '_annotation',
|
||||
html: string | null = null,
|
||||
prefix = '_prefix',
|
||||
@ -182,6 +184,24 @@ describe('Highlights API', () => {
|
||||
expect(res.body.data.createHighlight.highlight.html).to.eq(html)
|
||||
})
|
||||
|
||||
context('when highlight position is null', () => {
|
||||
it('sets highlight position = 0', async () => {
|
||||
const newHighlightId = generateFakeUuid()
|
||||
const newShortHighlightId = '_short_id_5'
|
||||
const query = createHighlightQuery(
|
||||
itemId,
|
||||
newHighlightId,
|
||||
newShortHighlightId
|
||||
)
|
||||
const res = await graphqlRequest(query, authToken).expect(200)
|
||||
expect(
|
||||
res.body.data.createHighlight.highlight.highlightPositionPercent
|
||||
).to.eq(0)
|
||||
|
||||
await deleteHighlightById(newHighlightId)
|
||||
})
|
||||
})
|
||||
|
||||
context('when the annotation has HTML reserved characters', () => {
|
||||
it('unescapes the annotation and creates', async () => {
|
||||
const newHighlightId = generateFakeUuid()
|
||||
|
||||
Reference in New Issue
Block a user