* add highlight mappings * return highlight in resolvers * temporarily skip highlight tests * add test for getting highlights * update merge highlight * separate elastic methods * roll back merge highlight test * add highlight to elastic script * update delete highlight in elastic * migrate highlight data from postgres to elastic * rescue not found exception when page is not found in the migration script * exclude highlights in searching pages results * search pages with highlights only with has:highlight query * add search endpoint to search pages or highlights * reduce code smell in search api * fix rebase error * fix tests * add test for search highlight * add test for new search endpoint * add labels to search results * update schema * update search query * fix update/share highlights * fix rebase error * fix tests * add highlight model in elastic * add savedAt and publishedAt date range in search query * add sort by updated and recently read * fix tests * close db connection when tests are done * test github action * revert github action test * fix rebase error * add docker-compose for api-test * remove unused env * remove highlights with no page attached to * allow get_articles resolver to search for query so we can merge it without web changes
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import 'mocha'
|
|
import { expect } from 'chai'
|
|
import 'chai/register-should'
|
|
import { createTestUser, deleteTestUser } from '../db'
|
|
import { createNewsletterEmail } from '../../src/services/newsletters'
|
|
import { saveNewsletterEmail } from '../../src/services/save_newsletter_email'
|
|
import { User } from '../../src/entity/user'
|
|
import { NewsletterEmail } from '../../src/entity/newsletter_email'
|
|
import { SaveContext } from '../../src/services/save_email'
|
|
import { createPubSubClient } from '../../src/datalayer/pubsub'
|
|
import { getPageByParam } from '../../src/elastic/pages'
|
|
|
|
describe('saveNewsletterEmail', () => {
|
|
const username = 'fakeUser'
|
|
|
|
let user: User
|
|
let email: NewsletterEmail
|
|
let ctx: SaveContext
|
|
|
|
before(async () => {
|
|
user = await createTestUser(username)
|
|
email = await createNewsletterEmail(user.id)
|
|
ctx = {
|
|
pubsub: createPubSubClient(),
|
|
refresh: true,
|
|
uid: user.id,
|
|
}
|
|
})
|
|
|
|
after(async () => {
|
|
await deleteTestUser(username)
|
|
})
|
|
|
|
it('adds the newsletter to the library', async () => {
|
|
await saveNewsletterEmail({
|
|
email: email.address,
|
|
content: 'fake content',
|
|
url: 'https://example.com',
|
|
title: 'fake title',
|
|
author: 'fake author',
|
|
}, ctx)
|
|
|
|
setTimeout(async () => {
|
|
const page = await getPageByParam({ userId: user.id })
|
|
if (!page) {
|
|
expect.fail('page not found')
|
|
}
|
|
expect(page.url).to.equal('https://example.com')
|
|
expect(page.title).to.equal('fake title')
|
|
expect(page.author).to.equal('fake author')
|
|
expect(page.content).to.contain('fake content')
|
|
})
|
|
})
|
|
|
|
it('should adds a Newsletter label to that page', async () => {
|
|
const newLabel = {
|
|
name: 'Newsletter',
|
|
color: '#07D2D1',
|
|
}
|
|
|
|
await saveNewsletterEmail({
|
|
email: email.address,
|
|
content: 'fake content 2',
|
|
url: 'https://example.com/2',
|
|
title: 'fake title',
|
|
author: 'fake author',
|
|
}, ctx)
|
|
|
|
setTimeout(async () => {
|
|
const page = await getPageByParam({ userId: user.id })
|
|
expect(page?.labels).to.deep.include(newLabel)
|
|
})
|
|
})
|
|
})
|