next/react doesnt want child elements of the paragraphs Improve formatting Improve wording Use buttons in the subscribe directly blocks Simplify docs on setting up forwarding rules Add extra padding on bottom of help docs Remove unused style Add emails help page Improve formatting Prefetch page content on iOS Reduce the reader overly length now that items are precached Add invalidation when highlights are added to items fix missing index_settings.json file in api dockerfile for creating elastic index (#363) Handle full email address objects in the to param from sendgrid These come in a format like: "jacksonh-dfdf@inbox.omnivore.app" <jacksonh-dfdf@inbox-demo.omnivore.app> New IDs for short highlights because they dont cascade delete now Testing CI issues Simplify test CI test Use promises for async tests Temporarily remove test to debug CI Re-enable re-enable test, return error Specify a userId when looking up saved email pages create a unique url for newsletters without a URL Use 500ms on page test timeouts Increase timeout Dont use deep equal to match newsletter label Run just the labels API Run against just the newsletter emails Run without the page tests Fix Set the allow uncaught flag Remove highlight tests Remove newsletters tests more resolver tests Remove newsetter tests Comment out resolver tests Use nock for external requests in tests Specify puppeteer url for tests Comment out more tests uncomment tests re-enable re-enable email test Re-disable Re-enable one pdf attachment test Re-disable pdf attachment test Use promises on setTimeout tests rm label tests mv label tests into a context Comment out pdf tests Comment out pdf tests Async test Async wrappers Delay when creating test pages More debugging Unique short ids Remove potentially problematic test Fetch page before returning for test handler in before block more debugging More debugging Move errors checks into contexts Use a context when saving newsletters to force index refresh Prettier fix Fix newsletter label check, remove setTimeout Re-enable test timeout on pdf router handler Fix method call comment out PDF test Unique fake username Comment out PDF test Debugging signed urls Re-enable New email pdf test PDF tests Comment out pdf test Add nock stubs for email URLs Use full address for PDF test Remove debug Use full email addresses
208 lines
5.0 KiB
TypeScript
208 lines
5.0 KiB
TypeScript
import 'mocha'
|
|
import {
|
|
addLabelInPage,
|
|
countByCreatedAt,
|
|
createPage,
|
|
deletePage,
|
|
getPageById,
|
|
getPageByParam,
|
|
searchPages,
|
|
updatePage,
|
|
} from '../../src/elastic'
|
|
import { PageType } from '../../src/generated/graphql'
|
|
import { expect } from 'chai'
|
|
import { InFilter, ReadFilter } from '../../src/utils/search'
|
|
import { Page, PageContext } from '../../src/elastic/types'
|
|
import { createPubSubClient } from '../../src/datalayer/pubsub'
|
|
|
|
describe('elastic api', () => {
|
|
const userId = 'userId'
|
|
const ctx: PageContext = {
|
|
pubsub: createPubSubClient(),
|
|
refresh: true,
|
|
uid: userId,
|
|
}
|
|
|
|
let page: Page
|
|
|
|
before(async () => {
|
|
// create a testing page
|
|
page = {
|
|
id: '',
|
|
hash: 'test hash',
|
|
userId: userId,
|
|
pageType: PageType.Article,
|
|
title: 'test title',
|
|
content: '<p>test</p>',
|
|
slug: 'test slug',
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
readingProgressPercent: 100,
|
|
readingProgressAnchorIndex: 0,
|
|
url: 'https://blog.omnivore.app/p/getting-started-with-omnivore',
|
|
archivedAt: new Date(),
|
|
labels: [
|
|
{
|
|
id: 'Test label id',
|
|
name: 'test label',
|
|
color: '#ffffff',
|
|
createdAt: new Date(),
|
|
},
|
|
{
|
|
id: 'Test label id 2',
|
|
name: 'test label 2',
|
|
color: '#eeeeee',
|
|
createdAt: new Date(),
|
|
},
|
|
],
|
|
}
|
|
const pageId = await createPage(page, ctx)
|
|
if (!pageId) {
|
|
expect.fail('Failed to create page')
|
|
}
|
|
page.id = pageId
|
|
})
|
|
|
|
after(async () => {
|
|
// delete the testing page
|
|
await deletePage(page.id, ctx)
|
|
})
|
|
|
|
describe('createPage', () => {
|
|
let newPageId: string | undefined
|
|
|
|
after(async () => {
|
|
if (newPageId) {
|
|
await deletePage(newPageId, ctx)
|
|
}
|
|
})
|
|
|
|
it('creates a page', async () => {
|
|
const newPageData: Page = {
|
|
id: '',
|
|
hash: 'hash',
|
|
userId: 'userId',
|
|
pageType: PageType.Article,
|
|
title: 'test',
|
|
content: 'test',
|
|
slug: 'test',
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
readingProgressPercent: 0,
|
|
readingProgressAnchorIndex: 0,
|
|
url: 'https://blog.omnivore.app/testUrl',
|
|
}
|
|
|
|
newPageId = await createPage(newPageData, ctx)
|
|
|
|
expect(newPageId).to.be.a('string')
|
|
})
|
|
})
|
|
|
|
describe('getPageByParam', () => {
|
|
it('gets a page by url', async () => {
|
|
const pageFound = await getPageByParam({
|
|
userId: page.userId,
|
|
url: page.url,
|
|
})
|
|
|
|
expect(pageFound).not.undefined
|
|
})
|
|
})
|
|
|
|
describe('getPageById', () => {
|
|
it('gets a page by id', async () => {
|
|
const pageFound = await getPageById(page.id)
|
|
expect(pageFound).not.undefined
|
|
})
|
|
})
|
|
|
|
describe('updatePage', () => {
|
|
it('updates a page', async () => {
|
|
const newTitle = 'new title'
|
|
const updatedPageData: Partial<Page> = {
|
|
title: newTitle,
|
|
}
|
|
|
|
await updatePage(page.id, updatedPageData, ctx)
|
|
|
|
const updatedPage = await getPageById(page.id)
|
|
expect(updatedPage?.title).to.eql(newTitle)
|
|
})
|
|
})
|
|
|
|
describe('searchPages', () => {
|
|
it('searches pages', async () => {
|
|
const searchResults = await searchPages(
|
|
{
|
|
inFilter: InFilter.ALL,
|
|
labelFilters: [],
|
|
readFilter: ReadFilter.ALL,
|
|
query: 'test',
|
|
},
|
|
page.userId
|
|
)
|
|
expect(searchResults).not.undefined
|
|
})
|
|
})
|
|
|
|
describe('addLabelInPage', () => {
|
|
context('when the label not exist in the page', () => {
|
|
it('adds the label to the page', async () => {
|
|
const newLabel = {
|
|
id: 'new label id',
|
|
name: 'new label',
|
|
color: '#07D2D1',
|
|
}
|
|
|
|
const result = await addLabelInPage(page.id, newLabel, ctx)
|
|
expect(result).to.be.true
|
|
|
|
const updatedPage = await getPageById(page.id)
|
|
expect(updatedPage?.labels).to.deep.include(newLabel)
|
|
})
|
|
})
|
|
|
|
context('when the label exists in the page', () => {
|
|
it('does not add the label to the page', async () => {
|
|
const newLabel = {
|
|
id: 'Test label id',
|
|
name: 'test label',
|
|
color: '#07D2D1',
|
|
}
|
|
|
|
const result = await addLabelInPage(page.id, newLabel, ctx)
|
|
|
|
expect(result).to.be.false
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('countByCreatedAt', () => {
|
|
const createdAt = Date.now() - 60 * 60 * 24 * 1000
|
|
|
|
before(async () => {
|
|
const newPageData: Page = {
|
|
id: '',
|
|
hash: 'hash',
|
|
userId: userId,
|
|
pageType: PageType.Article,
|
|
title: 'test',
|
|
content: 'test',
|
|
slug: 'test',
|
|
createdAt: new Date(createdAt),
|
|
readingProgressPercent: 0,
|
|
readingProgressAnchorIndex: 0,
|
|
url: 'https://blog.omnivore.app/testCount',
|
|
}
|
|
|
|
await createPage(newPageData, ctx)
|
|
})
|
|
|
|
it('counts pages by createdAt', async () => {
|
|
const count = await countByCreatedAt(userId, createdAt, createdAt)
|
|
expect(count).to.eq(1)
|
|
})
|
|
})
|
|
})
|