mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix tests
This commit is contained in:
parent
166b324d63
commit
9259a9cfe3
2 changed files with 52 additions and 23 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { diff_match_patch } from 'diff-match-patch'
|
||||
import { DeepPartial, In, LessThan } from 'typeorm'
|
||||
import { DeepPartial, In } from 'typeorm'
|
||||
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'
|
||||
import { EntityLabel } from '../entity/entity_label'
|
||||
import { Highlight } from '../entity/highlight'
|
||||
|
|
@ -205,19 +205,26 @@ export const updateHighlight = async (
|
|||
return updatedHighlight
|
||||
}
|
||||
|
||||
export const deleteHighlightById = async (highlightId: string) => {
|
||||
const deletedHighlight = await authTrx(async (tx) => {
|
||||
const highlightRepo = tx.withRepository(highlightRepository)
|
||||
const highlight = await highlightRepo.findOneOrFail({
|
||||
where: { id: highlightId },
|
||||
relations: {
|
||||
user: true,
|
||||
},
|
||||
})
|
||||
export const deleteHighlightById = async (
|
||||
highlightId: string,
|
||||
userId?: string
|
||||
) => {
|
||||
const deletedHighlight = await authTrx(
|
||||
async (tx) => {
|
||||
const highlightRepo = tx.withRepository(highlightRepository)
|
||||
const highlight = await highlightRepo.findOneOrFail({
|
||||
where: { id: highlightId },
|
||||
relations: {
|
||||
user: true,
|
||||
},
|
||||
})
|
||||
|
||||
await highlightRepo.delete(highlightId)
|
||||
return highlight
|
||||
})
|
||||
await highlightRepo.delete(highlightId)
|
||||
return highlight
|
||||
},
|
||||
undefined,
|
||||
userId
|
||||
)
|
||||
|
||||
await enqueueUpdateHighlight({
|
||||
libraryItemId: deletedHighlight.libraryItemId,
|
||||
|
|
@ -227,6 +234,17 @@ export const deleteHighlightById = async (highlightId: string) => {
|
|||
return deletedHighlight
|
||||
}
|
||||
|
||||
export const deleteHighlightsByIds = async (
|
||||
userId: string,
|
||||
highlightIds: string[]
|
||||
) => {
|
||||
await authTrx(
|
||||
async (tx) => tx.getRepository(Highlight).delete(highlightIds),
|
||||
undefined,
|
||||
userId
|
||||
)
|
||||
}
|
||||
|
||||
export const findHighlightById = async (
|
||||
highlightId: string,
|
||||
userId: string
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import { HighlightEdge } from '../../src/generated/graphql'
|
|||
import {
|
||||
createHighlight,
|
||||
deleteHighlightById,
|
||||
deleteHighlightsByIds,
|
||||
findHighlightById,
|
||||
} from '../../src/services/highlights'
|
||||
import { createLabel, saveLabelsInHighlight } from '../../src/services/labels'
|
||||
import { deleteLibraryItemsByUserId } from '../../src/services/library_item'
|
||||
import { deleteUser } from '../../src/services/user'
|
||||
import { createTestLibraryItem, createTestUser } from '../db'
|
||||
import {
|
||||
|
|
@ -168,8 +168,14 @@ describe('Highlights API', () => {
|
|||
})
|
||||
|
||||
context('createHighlightMutation', () => {
|
||||
let highlightId: string
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteHighlightById(highlightId, user.id)
|
||||
})
|
||||
|
||||
it('does not fail', async () => {
|
||||
const highlightId = generateFakeUuid()
|
||||
highlightId = generateFakeUuid()
|
||||
const shortHighlightId = '_short_id'
|
||||
const highlightPositionPercent = 35.0
|
||||
const highlightPositionAnchorIndex = 15
|
||||
|
|
@ -197,31 +203,29 @@ describe('Highlights API', () => {
|
|||
|
||||
context('when highlight position is null', () => {
|
||||
it('sets highlight position = 0', async () => {
|
||||
const newHighlightId = generateFakeUuid()
|
||||
highlightId = generateFakeUuid()
|
||||
const newShortHighlightId = '_short_id_5'
|
||||
const query = createHighlightQuery(
|
||||
itemId,
|
||||
newHighlightId,
|
||||
highlightId,
|
||||
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()
|
||||
highlightId = generateFakeUuid()
|
||||
const newShortHighlightId = '_short_id_4'
|
||||
const highlightPositionPercent = 50.0
|
||||
const highlightPositionAnchorIndex = 25
|
||||
const query = createHighlightQuery(
|
||||
itemId,
|
||||
newHighlightId,
|
||||
highlightId,
|
||||
newShortHighlightId,
|
||||
highlightPositionPercent,
|
||||
highlightPositionAnchorIndex,
|
||||
|
|
@ -247,7 +251,7 @@ describe('Highlights API', () => {
|
|||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteHighlightById(highlightId)
|
||||
await deleteHighlightById(highlightId, user.id)
|
||||
})
|
||||
|
||||
it('should not fail', async () => {
|
||||
|
|
@ -321,6 +325,10 @@ describe('Highlights API', () => {
|
|||
highlightId = highlight.id
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await deleteHighlightById(highlightId, user.id)
|
||||
})
|
||||
|
||||
it('updates the quote when the quote is in HTML format when the annotation has HTML reserved characters', async () => {
|
||||
const quote = '> This is a test'
|
||||
const query = updateHighlightQuery({ highlightId, quote })
|
||||
|
|
@ -402,7 +410,10 @@ describe('Highlights API', () => {
|
|||
})
|
||||
|
||||
after(async () => {
|
||||
await deleteLibraryItemsByUserId(user.id)
|
||||
await deleteHighlightsByIds(
|
||||
user.id,
|
||||
existingHighlights.map((h) => h.id)
|
||||
)
|
||||
})
|
||||
|
||||
it('returns highlights', async () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue