* 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
85 lines
2.1 KiB
TypeScript
85 lines
2.1 KiB
TypeScript
import {
|
|
createTestNewsletterEmail,
|
|
createTestUser,
|
|
deleteTestUser,
|
|
} from '../db'
|
|
import { request } from '../util'
|
|
import { User } from '../../src/entity/user'
|
|
import 'mocha'
|
|
import * as jwt from 'jsonwebtoken'
|
|
import { expect } from 'chai'
|
|
import { getPageById } from '../../src/elastic/pages'
|
|
|
|
describe('PDF attachments Router', () => {
|
|
const username = 'fakeUser'
|
|
const newsletterEmail = 'fakeEmail@fake-email.com'
|
|
|
|
let user: User
|
|
let authToken: string
|
|
|
|
before(async () => {
|
|
// create test user and login
|
|
user = await createTestUser(username)
|
|
|
|
await createTestNewsletterEmail(user, newsletterEmail)
|
|
authToken = jwt.sign(newsletterEmail, process.env.JWT_SECRET || '')
|
|
})
|
|
|
|
after(async () => {
|
|
// clean up
|
|
await deleteTestUser(username)
|
|
})
|
|
|
|
describe('upload', () => {
|
|
it('create upload file request and return id and url', async () => {
|
|
const testFile = 'testFile.pdf'
|
|
|
|
const res = await request
|
|
.post('/svc/pdf-attachments/upload')
|
|
.set('Authorization', `${authToken}`)
|
|
.send({
|
|
email: newsletterEmail,
|
|
fileName: testFile,
|
|
})
|
|
.expect(200)
|
|
|
|
expect(res.body.id).to.be.a('string')
|
|
expect(res.body.url).to.be.a('string')
|
|
})
|
|
})
|
|
|
|
describe('create article', () => {
|
|
let uploadFileId: string
|
|
|
|
before(async () => {
|
|
// upload file first
|
|
const testFile = 'testFile.pdf'
|
|
const res = await request
|
|
.post('/svc/pdf-attachments/upload')
|
|
.set('Authorization', `${authToken}`)
|
|
.send({
|
|
email: newsletterEmail,
|
|
fileName: testFile,
|
|
})
|
|
uploadFileId = res.body.id
|
|
})
|
|
|
|
it('create article with uploaded file id and url', async () => {
|
|
// create article
|
|
const res2 = await request
|
|
.post('/svc/pdf-attachments/create-article')
|
|
.send({
|
|
email: newsletterEmail,
|
|
uploadFileId: uploadFileId,
|
|
})
|
|
.set('Authorization', `${authToken}`)
|
|
.expect(200)
|
|
|
|
expect(res2.body.id).to.be.a('string')
|
|
const link = await getPageById(res2.body.id)
|
|
|
|
expect(link).to.exist
|
|
})
|
|
})
|
|
})
|