From ed5149c41ebf933b04bad8e77cccf1bfe996f795 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 2 Nov 2023 19:16:41 +0100 Subject: [PATCH 1/2] raise backend unit test coverage, no promise all in notification spec --- backend/jest.config.js | 2 +- .../schema/resolvers/notifications.spec.ts | 183 +++++++++--------- 2 files changed, 92 insertions(+), 93 deletions(-) diff --git a/backend/jest.config.js b/backend/jest.config.js index a4a0ce1df4..d9a196ace3 100644 --- a/backend/jest.config.js +++ b/backend/jest.config.js @@ -12,7 +12,7 @@ module.exports = { ], coverageThreshold: { global: { - lines: 67, + lines: 72, }, }, testMatch: ['**/src/**/?(*.)+(spec|test).ts?(x)'], diff --git a/backend/src/schema/resolvers/notifications.spec.ts b/backend/src/schema/resolvers/notifications.spec.ts index 60539d77f0..58757c92db 100644 --- a/backend/src/schema/resolvers/notifications.spec.ts +++ b/backend/src/schema/resolvers/notifications.spec.ts @@ -56,98 +56,97 @@ describe('given some notifications', () => { Factory.build('user', { id: 'neighbor' }), Factory.build('category', { id: 'cat1' }), ]) - const [post1, post2, post3] = await Promise.all([ - Factory.build('post', { id: 'p1', content: 'Not for you' }, { author, categoryIds }), - Factory.build( - 'post', - { - id: 'p2', - content: 'Already seen post mention', - }, - { - author, - categoryIds, - }, - ), - Factory.build( - 'post', - { - id: 'p3', - content: 'You have been mentioned in a post', - }, - { - author, - categoryIds, - }, - ), - ]) - const [comment1, comment2, comment3] = await Promise.all([ - Factory.build( - 'comment', - { - id: 'c1', - content: 'You have seen this comment mentioning already', - }, - { - author, - postId: 'p3', - }, - ), - Factory.build( - 'comment', - { - id: 'c2', - content: 'You have been mentioned in a comment', - }, - { - author, - postId: 'p3', - }, - ), - Factory.build( - 'comment', - { - id: 'c3', - content: 'Somebody else was mentioned in a comment', - }, - { - author, - postId: 'p3', - }, - ), - ]) - await Promise.all([ - post1.relateTo(neighbor, 'notified', { - createdAt: '2019-08-29T17:33:48.651Z', - read: false, - reason: 'mentioned_in_post', - }), - post2.relateTo(user, 'notified', { - createdAt: '2019-08-30T17:33:48.651Z', - read: true, - reason: 'mentioned_in_post', - }), - post3.relateTo(user, 'notified', { - createdAt: '2019-08-31T17:33:48.651Z', - read: false, - reason: 'mentioned_in_post', - }), - comment1.relateTo(user, 'notified', { - createdAt: '2019-08-30T15:33:48.651Z', - read: true, - reason: 'mentioned_in_comment', - }), - comment2.relateTo(user, 'notified', { - createdAt: '2019-08-30T19:33:48.651Z', - read: false, - reason: 'mentioned_in_comment', - }), - comment3.relateTo(neighbor, 'notified', { - createdAt: '2019-09-01T17:33:48.651Z', - read: false, - reason: 'mentioned_in_comment', - }), - ]) + const post1 = await Factory.build( + 'post', + { id: 'p1', content: 'Not for you' }, + { author, categoryIds }, + ) + const post2 = await Factory.build( + 'post', + { + id: 'p2', + content: 'Already seen post mention', + }, + { + author, + categoryIds, + }, + ) + const post3 = await Factory.build( + 'post', + { + id: 'p3', + content: 'You have been mentioned in a post', + }, + { + author, + categoryIds, + }, + ) + const comment1 = await Factory.build( + 'comment', + { + id: 'c1', + content: 'You have seen this comment mentioning already', + }, + { + author, + postId: 'p3', + }, + ) + const comment2 = await Factory.build( + 'comment', + { + id: 'c2', + content: 'You have been mentioned in a comment', + }, + { + author, + postId: 'p3', + }, + ) + const comment3 = await Factory.build( + 'comment', + { + id: 'c3', + content: 'Somebody else was mentioned in a comment', + }, + { + author, + postId: 'p3', + }, + ) + + await post1.relateTo(neighbor, 'notified', { + createdAt: '2019-08-29T17:33:48.651Z', + read: false, + reason: 'mentioned_in_post', + }) + await post2.relateTo(user, 'notified', { + createdAt: '2019-08-30T17:33:48.651Z', + read: true, + reason: 'mentioned_in_post', + }) + await post3.relateTo(user, 'notified', { + createdAt: '2019-08-31T17:33:48.651Z', + read: false, + reason: 'mentioned_in_post', + }) + await comment1.relateTo(user, 'notified', { + createdAt: '2019-08-30T15:33:48.651Z', + read: true, + reason: 'mentioned_in_comment', + }) + await comment2.relateTo(user, 'notified', { + createdAt: '2019-08-30T19:33:48.651Z', + read: false, + reason: 'mentioned_in_comment', + }) + await comment3.relateTo(neighbor, 'notified', { + createdAt: '2019-09-01T17:33:48.651Z', + read: false, + reason: 'mentioned_in_comment', + }) }) describe('notifications', () => { From 07ddd882e14a71200898a9812f2783ebe5745e4a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 2 Nov 2023 19:30:06 +0100 Subject: [PATCH 2/2] exclude all db files from coverage, raise coverage to 90% --- backend/jest.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/jest.config.js b/backend/jest.config.js index d9a196ace3..15eb22477e 100644 --- a/backend/jest.config.js +++ b/backend/jest.config.js @@ -8,11 +8,11 @@ module.exports = { '!**/test/**', '!**/build/**', '!**/src/**/?(*.)+(spec|test).ts?(x)', - '!**/src/db/migrations/**' + '!**/src/db/**' ], coverageThreshold: { global: { - lines: 72, + lines: 90, }, }, testMatch: ['**/src/**/?(*.)+(spec|test).ts?(x)'],