From b4c9fb0c83180069d5cb1530b7a1f31a51d3715c Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 18 Mar 2024 11:56:37 +0800 Subject: [PATCH 01/13] feat(Article): add article transcript contributors --- src/graphql/models/Article.js | 5 +++++ src/graphql/models/Contributor.js | 10 ++++++++++ src/graphql/mutations/CreateArticle.js | 1 + 3 files changed, 16 insertions(+) create mode 100644 src/graphql/models/Contributor.js diff --git a/src/graphql/models/Article.js b/src/graphql/models/Article.js index 8164a7f7..952eab2e 100644 --- a/src/graphql/models/Article.js +++ b/src/graphql/models/Article.js @@ -44,6 +44,7 @@ import Hyperlink from './Hyperlink'; import ReplyRequest from './ReplyRequest'; import ArticleTypeEnum from './ArticleTypeEnum'; import Cooccurrence from './Cooccurrence'; +import Contributor from './Contributor'; const ATTACHMENT_URL_DURATION_DAY = 1; @@ -580,6 +581,10 @@ const Article = new GraphQLObjectType({ }, }), }, + contributors: { + type: new GraphQLList(Contributor), + description: 'Transcript contributors of the article', + }, }), }); diff --git a/src/graphql/models/Contributor.js b/src/graphql/models/Contributor.js new file mode 100644 index 00000000..641c3467 --- /dev/null +++ b/src/graphql/models/Contributor.js @@ -0,0 +1,10 @@ +import { GraphQLObjectType, GraphQLString, GraphQLNonNull } from 'graphql'; + +export default new GraphQLObjectType({ + name: 'Contributor', + fields: () => ({ + userId: { type: GraphQLNonNull(GraphQLString) }, + appId: { type: GraphQLNonNull(GraphQLString) }, + updatedAt: { type: GraphQLString }, + }), +}); diff --git a/src/graphql/mutations/CreateArticle.js b/src/graphql/mutations/CreateArticle.js index 0aace2d6..31ea74be 100644 --- a/src/graphql/mutations/CreateArticle.js +++ b/src/graphql/mutations/CreateArticle.js @@ -82,6 +82,7 @@ async function createNewArticle({ text, reference: originalReference, user }) { attachmentUrl: '', attachmentHash: '', status: getContentDefaultStatus(user), + contributors: [], }, }, refresh: 'true', // Make sure the data is indexed when we create ReplyRequest From 5bde597fa94ca8209c92f9276af19c866eea9b64 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 18 Mar 2024 12:00:20 +0800 Subject: [PATCH 02/13] feat(Article): add article transcribedAt field --- src/graphql/models/Article.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/graphql/models/Article.js b/src/graphql/models/Article.js index 952eab2e..f4f11f74 100644 --- a/src/graphql/models/Article.js +++ b/src/graphql/models/Article.js @@ -585,6 +585,21 @@ const Article = new GraphQLObjectType({ type: new GraphQLList(Contributor), description: 'Transcript contributors of the article', }, + transcribedAt: { + type: GraphQLString, + description: 'Time when the article was last transcribed', + resolve: async ({ contributors }) => { + if (!contributors || contributors.length === 0) { + return null; + } + const maxUpdatedAt = contributors.reduce( + (max, contributor) => + contributor.updatedAt > max ? contributor.updatedAt : max, + contributors[0].updatedAt + ); + return maxUpdatedAt; + }, + }, }), }); From 1bd228686d95e9d59dd8be06ff73f91a1cf61b31 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 18 Mar 2024 12:00:33 +0800 Subject: [PATCH 03/13] feat(ListArticles): ListArticles can filter by contributors.userId --- src/graphql/models/Contributor.js | 6 ++++++ src/graphql/queries/ListArticles.js | 31 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/graphql/models/Contributor.js b/src/graphql/models/Contributor.js index 641c3467..5bf4cb78 100644 --- a/src/graphql/models/Contributor.js +++ b/src/graphql/models/Contributor.js @@ -1,8 +1,14 @@ import { GraphQLObjectType, GraphQLString, GraphQLNonNull } from 'graphql'; +import User, { userFieldResolver } from './User'; export default new GraphQLObjectType({ name: 'Contributor', fields: () => ({ + user: { + type: User, + description: 'The user who contributed to this article.', + resolve: userFieldResolver, + }, userId: { type: GraphQLNonNull(GraphQLString) }, appId: { type: GraphQLNonNull(GraphQLString) }, updatedAt: { type: GraphQLString }, diff --git a/src/graphql/queries/ListArticles.js b/src/graphql/queries/ListArticles.js index a05cad39..04706bff 100644 --- a/src/graphql/queries/ListArticles.js +++ b/src/graphql/queries/ListArticles.js @@ -153,6 +153,18 @@ export default { }, }), }, + articleContributesFrom: { + description: + 'Show only articles with article transcript contributed by specified user', + type: new GraphQLInputObjectType({ + name: 'ArticleContributeInput', + fields: { + userId: { + type: new GraphQLNonNull(GraphQLString), + }, + }, + }), + }, hasArticleReplyWithMorePositiveFeedback: { type: GraphQLBoolean, description: ` @@ -548,6 +560,25 @@ export default { }); } + if (filter.articleContributesFrom) { + filterQueries.push({ + nested: { + path: 'contributors', + query: { + bool: { + must: [ + { + term: { + 'contributors.userId': filter.articleContributesFrom.userId, + }, + }, + ], + }, + }, + }, + }); + } + if (filter.replyTypes) { filterQueries.push({ nested: { From f8e14e1fb65caf7a905ecd68c648acd1900bc5f6 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 18 Mar 2024 12:02:18 +0800 Subject: [PATCH 04/13] test(db): update test db to latest --- test/rumors-db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rumors-db b/test/rumors-db index 032b83e6..623c0c38 160000 --- a/test/rumors-db +++ b/test/rumors-db @@ -1 +1 @@ -Subproject commit 032b83e6a9b5758bc979dde99db81333501755f3 +Subproject commit 623c0c38741b900d69a09c89a7908d2abea47bc4 From 17bc20df3b5ae9a1383f5a94a46cfe3336d444b8 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 18 Mar 2024 12:04:33 +0800 Subject: [PATCH 05/13] test(Article): test article contributors query and its filter --- .../__snapshots__/CreateArticle.js.snap | 1 + .../queries/__fixtures__/ListArticles.js | 29 +++++++++++ src/graphql/queries/__tests__/ListArticles.js | 24 +++++++++ .../__snapshots__/ListArticles.js.snap | 52 +++++++++++++++++++ 4 files changed, 106 insertions(+) diff --git a/src/graphql/mutations/__tests__/__snapshots__/CreateArticle.js.snap b/src/graphql/mutations/__tests__/__snapshots__/CreateArticle.js.snap index cbf68fa2..bbcad3c4 100644 --- a/src/graphql/mutations/__tests__/__snapshots__/CreateArticle.js.snap +++ b/src/graphql/mutations/__tests__/__snapshots__/CreateArticle.js.snap @@ -28,6 +28,7 @@ Object { "articleType": "TEXT", "attachmentHash": "", "attachmentUrl": "", + "contributors": Array [], "createdAt": "2017-01-28T08:45:57.011Z", "hyperlinks": Array [ Object { diff --git a/src/graphql/queries/__fixtures__/ListArticles.js b/src/graphql/queries/__fixtures__/ListArticles.js index 2cc002ea..75744e8f 100644 --- a/src/graphql/queries/__fixtures__/ListArticles.js +++ b/src/graphql/queries/__fixtures__/ListArticles.js @@ -46,6 +46,18 @@ export default { negativeFeedbackCount: 0, }, ], + contributors: [ + { + userId: 'user1', + appId: 'WEBSITE', + updatedAt: '2020-02-05T14:41:19.044Z', + }, + { + userId: 'user2', + appId: 'WEBSITE', + updatedAt: '2020-02-05T14:41:19.044Z', + }, + ], attachmentUrl: '', attachmentHash: '', articleType: 'TEXT', @@ -105,6 +117,23 @@ export default { negativeFeedbackCount: 0, }, ], + contributors: [ + { + userId: 'user1', + appId: 'WEBSITE', + updatedAt: '2020-02-04T15:11:04.472Z', + }, + { + userId: 'user3', + appId: 'WEBSITE', + updatedAt: '2020-02-08T14:41:19.044Z', + }, + { + userId: 'user4', + appId: 'WEBSITE', + updatedAt: '2020-02-06T00:00:00.000Z', + }, + ], attachmentUrl: '', attachmentHash: '', articleType: 'TEXT', diff --git a/src/graphql/queries/__tests__/ListArticles.js b/src/graphql/queries/__tests__/ListArticles.js index d7aa4a4e..e71895dd 100644 --- a/src/graphql/queries/__tests__/ListArticles.js +++ b/src/graphql/queries/__tests__/ListArticles.js @@ -885,6 +885,30 @@ describe('ListArticles', () => { ).toMatchSnapshot('do not have articleReply from user1'); }); + it('filters via articleContributesFrom', async () => { + expect( + await gql` + { + ListArticles( + filter: { articleContributesFrom: { userId: "user1" } } + ) { + edges { + node { + id + contributors { + user { + id + } + } + transcribedAt + } + } + } + } + `({}, { appId: 'WEBSITE' }) + ).toMatchSnapshot('articleContributesFrom from user1'); + }); + it('filters by reply types', async () => { expect( await gql` diff --git a/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap b/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap index 6b3b5e42..4699f4f8 100644 --- a/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap +++ b/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap @@ -709,6 +709,58 @@ Object { } `; +exports[`ListArticles filters via articleContributesFrom: articleContributesFrom from user1 1`] = ` +Object { + "data": Object { + "ListArticles": Object { + "edges": Array [ + Object { + "node": Object { + "contributors": Array [ + Object { + "user": Object { + "id": "user1", + }, + }, + Object { + "user": Object { + "id": "user3", + }, + }, + Object { + "user": Object { + "id": "user4", + }, + }, + ], + "id": "listArticleTest2", + "transcribedAt": "2020-02-08T14:41:19.044Z", + }, + }, + Object { + "node": Object { + "contributors": Array [ + Object { + "user": Object { + "id": "user1", + }, + }, + Object { + "user": Object { + "id": "user2", + }, + }, + ], + "id": "listArticleTest1", + "transcribedAt": "2020-02-05T14:41:19.044Z", + }, + }, + ], + }, + }, +} +`; + exports[`ListArticles filters via articleRepliesFrom: do not have articleReply from user1 1`] = ` Object { "data": Object { From 19c4950a89ef4dd89e784db58fc63acad2b05efe Mon Sep 17 00:00:00 2001 From: nonumpa Date: Wed, 10 Apr 2024 15:06:56 +0800 Subject: [PATCH 06/13] feat(ListArticles): remove redundant bool query Co-authored-by: Johnson Liang --- src/graphql/queries/ListArticles.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/graphql/queries/ListArticles.js b/src/graphql/queries/ListArticles.js index 04706bff..a3c7c421 100644 --- a/src/graphql/queries/ListArticles.js +++ b/src/graphql/queries/ListArticles.js @@ -565,14 +565,8 @@ export default { nested: { path: 'contributors', query: { - bool: { - must: [ - { - term: { - 'contributors.userId': filter.articleContributesFrom.userId, - }, - }, - ], + term: { + 'contributors.userId': filter.articleContributesFrom.userId, }, }, }, From ccc6b59e047d24e1ede294b1e2f4c3e7b6e32065 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 16:11:04 +0800 Subject: [PATCH 07/13] feat(Article): add default value for CreateMediaArticle contributors --- src/graphql/mutations/CreateMediaArticle.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphql/mutations/CreateMediaArticle.js b/src/graphql/mutations/CreateMediaArticle.js index f3454356..f6fb1da7 100644 --- a/src/graphql/mutations/CreateMediaArticle.js +++ b/src/graphql/mutations/CreateMediaArticle.js @@ -162,6 +162,7 @@ async function createNewMediaArticle({ articleType, attachmentHash, status: getContentDefaultStatus(user), + contributors: [], }, }); From d437e8679674248c8576d71ad85759337434eb6f Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 19:51:02 +0800 Subject: [PATCH 08/13] test(Article): update CreateMediaArticle test --- src/graphql/mutations/__tests__/CreateMediaArticle.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphql/mutations/__tests__/CreateMediaArticle.js b/src/graphql/mutations/__tests__/CreateMediaArticle.js index 2031ede9..7c4ffd94 100644 --- a/src/graphql/mutations/__tests__/CreateMediaArticle.js +++ b/src/graphql/mutations/__tests__/CreateMediaArticle.js @@ -84,6 +84,7 @@ describe('creation', () => { "articleReplies": Array [], "articleType": "IMAGE", "attachmentHash": "mock_image_hash", + "contributors": Array [], "createdAt": "2017-01-28T08:45:57.011Z", "hyperlinks": Array [], "lastRequestedAt": "2017-01-28T08:45:57.011Z", From 9dd907d6cca3d1043e649dce67fc7b604a702ff2 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 16:14:11 +0800 Subject: [PATCH 09/13] feat(Article): update article contributors to be a non-nullable type --- src/graphql/models/Article.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphql/models/Article.js b/src/graphql/models/Article.js index f4f11f74..44fd70ae 100644 --- a/src/graphql/models/Article.js +++ b/src/graphql/models/Article.js @@ -582,8 +582,11 @@ const Article = new GraphQLObjectType({ }), }, contributors: { - type: new GraphQLList(Contributor), + type: new GraphQLNonNull( + new GraphQLList(new GraphQLNonNull(Contributor)) + ), description: 'Transcript contributors of the article', + resolve: ({ contributors }) => contributors ?? [], }, transcribedAt: { type: GraphQLString, From 5f7d09ec0ebb71bd67dfbfe6ad50dd7ff2a70944 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 16:20:46 +0800 Subject: [PATCH 10/13] feat(ListArticles): ListArticles can filter by userAndExistInput - Use userAndExistInput so that we can also list articles that a person did not transcribe - Rename articleContributesFrom as transcribedBy --- src/graphql/queries/ListArticles.js | 40 ++++++++--------------------- src/graphql/util.js | 17 ++++++++++++ 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/graphql/queries/ListArticles.js b/src/graphql/queries/ListArticles.js index a3c7c421..6ce629c5 100644 --- a/src/graphql/queries/ListArticles.js +++ b/src/graphql/queries/ListArticles.js @@ -16,6 +16,7 @@ import { intRangeInput, timeRangeInput, moreLikeThisInput, + userAndExistInput, getRangeFieldParamFromArithmeticExpression, createCommonListFilter, attachCommonListFilter, @@ -136,34 +137,12 @@ export default { articleRepliesFrom: { description: 'Show only articles with(out) article replies created by specified user', - type: new GraphQLInputObjectType({ - name: 'UserAndExistInput', - fields: { - userId: { - type: new GraphQLNonNull(GraphQLString), - }, - exists: { - type: GraphQLBoolean, - defaultValue: true, - description: ` - When true (or not specified), return only entries with the specified user's involvement. - When false, return only entries that the specified user did not involve. - `, - }, - }, - }), + type: userAndExistInput, }, - articleContributesFrom: { + transcribedBy: { description: - 'Show only articles with article transcript contributed by specified user', - type: new GraphQLInputObjectType({ - name: 'ArticleContributeInput', - fields: { - userId: { - type: new GraphQLNonNull(GraphQLString), - }, - }, - }), + 'Show only articles with(out) article transcript contributed by specified user', + type: userAndExistInput, }, hasArticleReplyWithMorePositiveFeedback: { type: GraphQLBoolean, @@ -560,13 +539,16 @@ export default { }); } - if (filter.articleContributesFrom) { - filterQueries.push({ + if (filter.transcribedBy) { + (filter.transcribedBy.exists === false + ? mustNotQueries + : filterQueries + ).push({ nested: { path: 'contributors', query: { term: { - 'contributors.userId': filter.articleContributesFrom.userId, + 'contributors.userId': filter.transcribedBy.userId, }, }, }, diff --git a/src/graphql/util.js b/src/graphql/util.js index f2ef4141..322e4962 100644 --- a/src/graphql/util.js +++ b/src/graphql/util.js @@ -103,6 +103,23 @@ export const moreLikeThisInput = new GraphQLInputObjectType({ }, }); +export const userAndExistInput = new GraphQLInputObjectType({ + name: 'UserAndExistInput', + fields: { + userId: { + type: new GraphQLNonNull(GraphQLString), + }, + exists: { + type: GraphQLBoolean, + defaultValue: true, + description: ` + When true (or not specified), return only entries with the specified user's involvement. + When false, return only entries that the specified user did not involve. + `, + }, + }, +}); + export function createFilterType(typeName, args) { const filterType = new GraphQLInputObjectType({ name: typeName, From 09e9c18c040db87454f2c1965796c583d820af93 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 18:41:54 +0800 Subject: [PATCH 11/13] feat(Article): simplify maxUpdatedAt logic --- src/graphql/models/Article.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/graphql/models/Article.js b/src/graphql/models/Article.js index 44fd70ae..e0b4d921 100644 --- a/src/graphql/models/Article.js +++ b/src/graphql/models/Article.js @@ -595,12 +595,12 @@ const Article = new GraphQLObjectType({ if (!contributors || contributors.length === 0) { return null; } - const maxUpdatedAt = contributors.reduce( - (max, contributor) => - contributor.updatedAt > max ? contributor.updatedAt : max, - contributors[0].updatedAt + const maxUpdatedAt = new Date( + Math.max( + ...contributors.map(contributor => new Date(contributor.updatedAt)) + ) ); - return maxUpdatedAt; + return maxUpdatedAt.toISOString(); }, }, }), From 53dda1256b978dca424ff2df4d45a71625e61845 Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 18:45:00 +0800 Subject: [PATCH 12/13] test(ListArticles): update transcribedBy test with/out userAndExistInput --- .../queries/__fixtures__/ListArticles.js | 22 +++--- src/graphql/queries/__tests__/ListArticles.js | 26 ++++++- .../__snapshots__/ListArticles.js.snap | 72 +++++++++++++++---- 3 files changed, 93 insertions(+), 27 deletions(-) diff --git a/src/graphql/queries/__fixtures__/ListArticles.js b/src/graphql/queries/__fixtures__/ListArticles.js index 75744e8f..f4ff8713 100644 --- a/src/graphql/queries/__fixtures__/ListArticles.js +++ b/src/graphql/queries/__fixtures__/ListArticles.js @@ -55,7 +55,17 @@ export default { { userId: 'user2', appId: 'WEBSITE', - updatedAt: '2020-02-05T14:41:19.044Z', + updatedAt: '2020-02-09T14:41:19.044Z', + }, + { + userId: 'user3', + appId: 'WEBSITE', + updatedAt: '2020-02-08T14:41:19.044Z', + }, + { + userId: 'user4', + appId: 'WEBSITE', + updatedAt: '2020-02-07T14:41:19.044Z', }, ], attachmentUrl: '', @@ -123,16 +133,6 @@ export default { appId: 'WEBSITE', updatedAt: '2020-02-04T15:11:04.472Z', }, - { - userId: 'user3', - appId: 'WEBSITE', - updatedAt: '2020-02-08T14:41:19.044Z', - }, - { - userId: 'user4', - appId: 'WEBSITE', - updatedAt: '2020-02-06T00:00:00.000Z', - }, ], attachmentUrl: '', attachmentHash: '', diff --git a/src/graphql/queries/__tests__/ListArticles.js b/src/graphql/queries/__tests__/ListArticles.js index e71895dd..44e10e4c 100644 --- a/src/graphql/queries/__tests__/ListArticles.js +++ b/src/graphql/queries/__tests__/ListArticles.js @@ -885,12 +885,32 @@ describe('ListArticles', () => { ).toMatchSnapshot('do not have articleReply from user1'); }); - it('filters via articleContributesFrom', async () => { + it('filters via transcribedBy', async () => { + expect( + await gql` + { + ListArticles(filter: { transcribedBy: { userId: "user1" } }) { + edges { + node { + id + contributors { + user { + id + } + } + transcribedAt + } + } + } + } + `({}, { appId: 'WEBSITE' }) + ).toMatchSnapshot('transcribedBy user1'); + expect( await gql` { ListArticles( - filter: { articleContributesFrom: { userId: "user1" } } + filter: { transcribedBy: { userId: "user1", exists: false } } ) { edges { node { @@ -906,7 +926,7 @@ describe('ListArticles', () => { } } `({}, { appId: 'WEBSITE' }) - ).toMatchSnapshot('articleContributesFrom from user1'); + ).toMatchSnapshot('is not transcribedBy user1'); }); it('filters by reply types', async () => { diff --git a/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap b/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap index 4699f4f8..d4812ef7 100644 --- a/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap +++ b/src/graphql/queries/__tests__/__snapshots__/ListArticles.js.snap @@ -709,7 +709,53 @@ Object { } `; -exports[`ListArticles filters via articleContributesFrom: articleContributesFrom from user1 1`] = ` +exports[`ListArticles filters via transcribedBy: is not transcribedBy user1 1`] = ` +Object { + "data": Object { + "ListArticles": Object { + "edges": Array [ + Object { + "node": Object { + "contributors": Array [], + "id": "listArticleTest7", + "transcribedAt": null, + }, + }, + Object { + "node": Object { + "contributors": Array [], + "id": "listArticleTest6", + "transcribedAt": null, + }, + }, + Object { + "node": Object { + "contributors": Array [], + "id": "listArticleTest5", + "transcribedAt": null, + }, + }, + Object { + "node": Object { + "contributors": Array [], + "id": "listArticleTest4", + "transcribedAt": null, + }, + }, + Object { + "node": Object { + "contributors": Array [], + "id": "listArticleTest3", + "transcribedAt": null, + }, + }, + ], + }, + }, +} +`; + +exports[`ListArticles filters via transcribedBy: transcribedBy user1 1`] = ` Object { "data": Object { "ListArticles": Object { @@ -722,19 +768,9 @@ Object { "id": "user1", }, }, - Object { - "user": Object { - "id": "user3", - }, - }, - Object { - "user": Object { - "id": "user4", - }, - }, ], "id": "listArticleTest2", - "transcribedAt": "2020-02-08T14:41:19.044Z", + "transcribedAt": "2020-02-04T15:11:04.472Z", }, }, Object { @@ -750,9 +786,19 @@ Object { "id": "user2", }, }, + Object { + "user": Object { + "id": "user3", + }, + }, + Object { + "user": Object { + "id": "user4", + }, + }, ], "id": "listArticleTest1", - "transcribedAt": "2020-02-05T14:41:19.044Z", + "transcribedAt": "2020-02-09T14:41:19.044Z", }, }, ], From 625fbb1a6a47a27dffde8b2391d33fee20c1963d Mon Sep 17 00:00:00 2001 From: Nonumpa Date: Mon, 22 Apr 2024 21:51:03 +0800 Subject: [PATCH 13/13] fix(test): ai response partially match --- src/graphql/__tests__/util.js | 58 +++++++++-------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/src/graphql/__tests__/util.js b/src/graphql/__tests__/util.js index 2d912765..110e61c5 100644 --- a/src/graphql/__tests__/util.js +++ b/src/graphql/__tests__/util.js @@ -120,6 +120,7 @@ if (process.env.GCS_BUCKET_NAME) { createdAt, // eslint-disable-next-line no-unused-vars updatedAt, + text, ...aiResponse } = await createTranscript( { @@ -130,50 +131,21 @@ if (process.env.GCS_BUCKET_NAME) { { id: 'user-id', appId: 'app-id' } ); + // Expect some keywords are identified. + // The whole text are not always 100% identical, but these keywords should be always included. + expect(text).toMatch(/^排/); + expect(text).toMatch(/德國醫學博士艾倫斯特發現/); + expect(text).toMatch(/汗也具有調節體溫的重要作用/); expect(aiResponse).toMatchInlineSnapshot(` - Object { - "appId": "app-id", - "docId": "foo", - "status": "SUCCESS", - "text": "排 - 汗 - 汗和排尿的差別 - 想要健康長壽就要想辦法一天一次大量排汗 - 德國醫學博士艾倫斯特發現:所有運動選手中 - 唯獨馬拉松選手沒有罹患癌症病例。 - 艾倫斯特博士採集了每天跑步 30 公里以上的 - 馬拉松選手的汗水,分析其汗水的成份結果 - 發現汗水中含有 鎘 鉛銅鎳等之重金屬物質。 - 證明出汗是排泄體內疲勞物質及對人體有害的 - 重金屬毒素的重要途徑 - 雖然排泄體內不需要物質的基本功能,有排便 - 排尿與出汗。而尿也會排出重金屬,但是排出 - 功能卻遠不及汗。 - 汗與尿中的重金屬元素量 - 鉛(微克)鎘(微克)鈷(微克) - 6.5 - 1.2 - 0.65 - 0.6 - 汗 84 - 尿 4.9 - 100 克 中〉 - 鎳(微克)銅(毫克) - 32 - 0.11 - 3.1 - 0.01 - 汗也具有調節體溫的重要作用。 全身健康的 - 出汗,就能夠強化現代最欠缺的體溫調節功能 - 與自律神經。 - 藉著汗,氣化熱消耗熱量,能夠提升代謝力, - 不但減少體脂肪,還有助於消除肥胖。 - 可以先從關掉冷氣做起 - ", - "type": "TRANSCRIPT", - "userId": "user-id", - } - `); + Object { + "appId": "app-id", + "docId": "foo", + "status": "SUCCESS", + "type": "TRANSCRIPT", + "userId": "user-id", + } + `); + // Cleanup await client.delete({ index: 'airesponses',