From e12f62c0a5cdf48878321b6d8f49c96c39f44b62 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Wed, 24 Jan 2024 23:50:36 +0000 Subject: [PATCH 1/2] Bump caniuselite to latest. --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 43cb2321..ac6e756c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7821,9 +7821,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001514", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001514.tgz", - "integrity": "sha512-ENcIpYBmwAAOm/V2cXgM7rZUrKKaqisZl4ZAI520FIkqGXUxJjmaIssbRW5HVVR5tyV6ygTLIm15aU8LUmQSaQ==", + "version": "1.0.30001579", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001579.tgz", + "integrity": "sha512-u5AUVkixruKHJjw/pj9wISlcMpgFWzSrczLZbrqBSxukQixmg0SJ5sZTpvaFvxU0HoQKd4yoyAogyrAz9pzJnA==", "dev": true, "funding": [ { @@ -25753,9 +25753,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001514", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001514.tgz", - "integrity": "sha512-ENcIpYBmwAAOm/V2cXgM7rZUrKKaqisZl4ZAI520FIkqGXUxJjmaIssbRW5HVVR5tyV6ygTLIm15aU8LUmQSaQ==", + "version": "1.0.30001579", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001579.tgz", + "integrity": "sha512-u5AUVkixruKHJjw/pj9wISlcMpgFWzSrczLZbrqBSxukQixmg0SJ5sZTpvaFvxU0HoQKd4yoyAogyrAz9pzJnA==", "dev": true }, "caseless": { From f4eb063b678e00e3bd794db1f7aa9f1a51dac313 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Wed, 24 Jan 2024 23:51:03 +0000 Subject: [PATCH 2/2] tests: Bring comments controller rest from reverted commit. Partial from 903bf1995 --- controllers/__tests__/comment.test.js | 105 ++++++++++++++++++++++++++ tests/globalSetup.js | 2 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 controllers/__tests__/comment.test.js diff --git a/controllers/__tests__/comment.test.js b/controllers/__tests__/comment.test.js new file mode 100644 index 00000000..01fcf1e9 --- /dev/null +++ b/controllers/__tests__/comment.test.js @@ -0,0 +1,105 @@ +/** + * Copyright: The PastVu contributors. + * GNU Affero General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/agpl.txt) + */ + +import { CommentN } from '../../models/Comment'; +import admin from '../admin'; +import comment from '../comment'; +import testHelpers from '../../tests/testHelpers'; + +describe('comment', () => { + beforeEach(async () => { + // Mock non-registerd user handshake. + admin.handshake = { 'usObj': { 'isAdmin': true } }; + }); + + afterEach(() => { + // Delete handshake. + delete admin.handshake; + }); + + describe('create for news', () => { + let news; + + beforeEach(async () => { + const data = { pdate: new Date(), 'title': 'Test news', 'txt': 'Test news content' }; + + ({ news } = await admin.saveOrCreateNews(data)); + + const user = await testHelpers.createUser({ login: 'user1', pass: 'pass1' }); + + // Mock non-registered user handshake. + comment.handshake = { 'usObj': { 'isAdmin': true, 'registered': true, user } }; + }); + + afterEach(() => { + // Delete handshake. + delete comment.handshake; + }); + + it('create', async () => { + expect.assertions(3); + + const data = { txt: 'news comment', type: 'news', obj: news.cid }; + + // Create two comments. + const result = await comment.create(data); + + expect(result.comment.txt).toMatch(data.txt); + expect(result.comment.user).toMatch('user1'); + + await expect(CommentN.count({ obj: news })).resolves.toBe(1); + }); + }); + + describe('retrive', () => { + let news; + + beforeEach(async () => { + const data = { pdate: new Date(), 'title': 'Test news', 'txt': 'Test news content' }; + + ({ news } = await admin.saveOrCreateNews(data)); + + const user = await testHelpers.createUser({ login: 'user1', pass: 'pass1' }); + + // Mock non-registered user handshake. + comment.handshake = { 'usObj': { 'isAdmin': true, 'registered': true, user } }; + }); + + afterEach(() => { + // Delete handshake. + delete comment.handshake; + }); + + it('give news comments for user', async () => { + expect.assertions(5); + + const data = { txt: 'news comment', type: 'news', obj: news.cid }; + + // Create 4 comments. + const comment0 = await comment.create(data); + const comment1 = await comment.create(data); + + data.parent = comment1.comment.cid; + data.level = comment1.comment.level + 1; + + const comment2 = await comment.create(data); + + data.parent = comment2.comment.cid; + data.level = comment2.comment.level + 1; + + const comment3 = await comment.create(data); + + // Sanity check. + await expect(CommentN.count({ obj: news })).resolves.toBe(4); + + const comments = await comment.giveForUser({ login: 'user1', type: 'news' }); + + expect(comments.type).toMatch('news'); + expect(comments.countActive).toBe(4); + expect(comments.objs[news.cid].cid).toStrictEqual(news.cid); + expect(comments.objs[news.cid].ccount).toBe(4); + }); + }); +}); diff --git a/tests/globalSetup.js b/tests/globalSetup.js index 0c5598eb..6c027a0b 100644 --- a/tests/globalSetup.js +++ b/tests/globalSetup.js @@ -9,7 +9,7 @@ import { MongoMemoryServer } from 'mongodb-memory-server'; process.argv.push('--config', __dirname + '/test.config.js'); // Define mongodb-memory-server version to use in tests. -process.env.MONGOMS_VERSION = '4.4.18'; +process.env.MONGOMS_VERSION = '4.4.22'; export default async function () { // Start mongodb-memory-server.