mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1635 from omnivore-app/fix/content-display-reports
Fix creation of content display report
This commit is contained in:
commit
786ad35da9
5 changed files with 72 additions and 1 deletions
|
|
@ -21,7 +21,7 @@ export const saveContentDisplayReport = async (
|
|||
// reparsed or updated later, this gives us a view of exactly
|
||||
// what the user saw.
|
||||
const result = await repo.save({
|
||||
userId: uid,
|
||||
user: { id: uid },
|
||||
elasticPageId: input.pageId,
|
||||
content: page.content,
|
||||
originalHtml: page.originalHtml || undefined,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { SnakeNamingStrategy } from 'typeorm-naming-strategies'
|
|||
import { SubscriptionStatus } from '../src/generated/graphql'
|
||||
import { Integration } from '../src/entity/integration'
|
||||
import { FindOptionsWhere } from 'typeorm'
|
||||
import { ContentDisplayReport } from '../src/entity/reports/content_display_report'
|
||||
|
||||
const runMigrations = async () => {
|
||||
const migrationDirectory = __dirname + '/../../db/migrations'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
import 'mocha'
|
||||
import chai, { expect } from 'chai'
|
||||
import 'chai/register-should'
|
||||
import { createTestUser, deleteTestUser } from '../db'
|
||||
import sinonChai from 'sinon-chai'
|
||||
import sinon from 'sinon'
|
||||
import * as util from '../../src/utils/sendEmail'
|
||||
import { MailDataRequired } from '@sendgrid/helpers/classes/mail'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { getRepository } from '../../src/entity/utils'
|
||||
import { ContentDisplayReport } from '../../src/entity/reports/content_display_report'
|
||||
import { saveContentDisplayReport } from '../../src/services/reports'
|
||||
import { ReportType } from '../../src/generated/graphql'
|
||||
import { createTestElasticPage } from '../util'
|
||||
import { Page } from '../../src/elastic/types'
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
describe('saveContentDisplayReport', () => {
|
||||
let user: User
|
||||
let page: Page
|
||||
|
||||
before(async () => {
|
||||
user = await createTestUser('fakeContentUser')
|
||||
page = await createTestElasticPage(user.id)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await deleteTestUser(user.id)
|
||||
})
|
||||
|
||||
it('creates a report', async () => {
|
||||
const result = await saveContentDisplayReport(user.id, {
|
||||
itemUrl: 'https://fake.url.com',
|
||||
pageId: page.id,
|
||||
reportComment: 'report comment',
|
||||
reportTypes: [ReportType.ContentDisplay],
|
||||
})
|
||||
expect(result).to.eql(true)
|
||||
const saved = await getRepository(ContentDisplayReport).findOneBy({
|
||||
user: { id: user.id },
|
||||
elasticPageId: page.id,
|
||||
})
|
||||
|
||||
expect(saved?.reportComment).to.eql('report comment')
|
||||
})
|
||||
})
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
-- Type: DO
|
||||
-- Name: remove_constraints_from_content_display_reports
|
||||
-- Description: Remove constraints from CD reports as they should not be deleted
|
||||
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.content_display_report DROP CONSTRAINT content_display_report_page_id_fkey;
|
||||
ALTER TABLE omnivore.content_display_report DROP CONSTRAINT content_display_report_user_id_fkey;
|
||||
|
||||
COMMIT;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
-- Type: UNDO
|
||||
-- Name: remove_constraints_from_content_display_reports
|
||||
-- Description: Remove constraints from CD reports as they should not be deleted
|
||||
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.content_display_report
|
||||
ADD CONSTRAINT content_display_report_user_id_fkey FOREIGN KEY (user_id) REFERENCES omnivore."user"(id);
|
||||
|
||||
ALTER TABLE omnivore.content_display_report
|
||||
ADD CONSTRAINT content_display_report_page_id_fkey FOREIGN KEY (page_id) REFERENCES omnivore.pages(id);
|
||||
|
||||
COMMIT;
|
||||
Loading…
Reference in a new issue