Skip to content

Commit

Permalink
test(CreateMediaArticle): add unit test for transcript
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Sep 28, 2023
1 parent 6ee0c01 commit 21e4d6f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/graphql/mutations/__fixtures__/CreateMediaArticle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export default {
[`/articles/doc/image1`]: {
'/articles/doc/image1': {
text: '',
attachmentUrl: 'http://foo/image.jpeg',
attachmentHash: 'ffff8000',
replyRequestCount: 1,
references: [{ type: 'LINE' }],
},
'/airesponses/doc/ocr': {
docId: 'mock_image_hash',
type: 'TRANSCRIPT',
text: 'OCR result of output image',
status: 'SUCCESS',
createdAt: '2020-01-01T00:00:00.000Z',
},
};
32 changes: 28 additions & 4 deletions src/graphql/mutations/__tests__/CreateMediaArticle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Y from 'yjs';
import MockDate from 'mockdate';

import gql from 'util/GraphQL';
import { loadFixtures, unloadFixtures } from 'util/fixtures';
import client from 'util/client';
import MockDate from 'mockdate';
import fixtures from '../__fixtures__/CreateMediaArticle';
import { getReplyRequestId } from '../CreateOrUpdateReplyRequest';
import mediaManager from 'util/mediaManager';
Expand All @@ -15,7 +17,7 @@ describe('creation', () => {
});
afterAll(() => unloadFixtures(fixtures));

it('creates a media article and a reply request', async () => {
it('creates a media article, a reply request, a ydoc and fills in OCR result', async () => {
MockDate.set(1485593157011);
const userId = 'test';
const appId = 'foo';
Expand Down Expand Up @@ -98,7 +100,7 @@ describe('creation', () => {
"replyRequestCount": 1,
"status": "NORMAL",
"tags": Array [],
"text": "",
"text": "OCR result of output image",
"updatedAt": "2017-01-28T08:45:57.011Z",
"userId": "test",
}
Expand Down Expand Up @@ -133,7 +135,23 @@ describe('creation', () => {
}
`);

// // Cleanup
const {
body: {
_source: { ydoc: encodedYdoc },
},
} = await client.get({
index: 'ydocs',
type: 'doc',
id: data.CreateMediaArticle.id,
});

const ydoc = new Y.Doc();
Y.applyUpdate(ydoc, Buffer.from(encodedYdoc, 'base64'));
expect(ydoc.getXmlFragment('prosemirror')).toMatchInlineSnapshot(
`"<paragraph>OCR result of output image</paragraph>"`
);

// Cleanup
await client.delete({
index: 'articles',
type: 'doc',
Expand All @@ -145,6 +163,12 @@ describe('creation', () => {
type: 'doc',
id: replyRequestId,
});

await client.delete({
index: 'ydocs',
type: 'doc',
id: data.CreateMediaArticle.id,
});
});

it('avoids creating duplicated media articles and adds replyRequests automatically', async () => {
Expand Down

0 comments on commit 21e4d6f

Please sign in to comment.