From bf409dd89cf4172a393eea1b25d1c88d26319269 Mon Sep 17 00:00:00 2001 From: AliceeLe Date: Mon, 7 Oct 2024 18:50:29 -0400 Subject: [PATCH 1/5] Set up testing file for create.js --- test/posts/create.js | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/posts/create.js diff --git a/test/posts/create.js b/test/posts/create.js new file mode 100644 index 0000000000..fd3d8944f7 --- /dev/null +++ b/test/posts/create.js @@ -0,0 +1,55 @@ +'use strict'; + +const assert = require('assert'); +const db = require('../mocks/databasemock'); +const plugins = require('../../src/plugins'); +const user = require('../../src/user'); +const topics = require('../../src/topics'); +const categories = require('../../src/categories'); +const groups = require('../../src/groups'); +const privileges = require('../../src/privileges'); +const meta = require('../../src/meta'); +const Posts = {}; + + +describe('create post', function () { + let pid; + let purgePid; + let cid; + let uid; + let endorsed; + + + it('create a post', async function () { + try { + uid = await user.create({ + username: 'uploads user', + password: 'abracadabra', + gdpr_consent: 1, + }); + + ({ cid } = await categories.create({ + name: 'Test Category', + description: 'Test category created by testing script', + })); + + endorsed = false; + + const topicPostData = await topics.post({ + uid, + cid, + title: 'topic with some images', + content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', + endorsed + }); + } catch (error) { + assert.strictEqual(error.message, '[[error:invalid-uid]]'); + } + }); +}); + +describe('addReplyTo', function () { +}); + +describe('checkToPid', function () { +}); From 0133736b601e5d229da90a3d17d893608719a089 Mon Sep 17 00:00:00 2001 From: AliceeLe Date: Mon, 7 Oct 2024 19:22:39 -0400 Subject: [PATCH 2/5] Unit test that upon initialization, endorse is false --- test/posts/create.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/posts/create.js b/test/posts/create.js index fd3d8944f7..709e514db1 100644 --- a/test/posts/create.js +++ b/test/posts/create.js @@ -14,36 +14,39 @@ const Posts = {}; describe('create post', function () { let pid; - let purgePid; - let cid; - let uid; + let purgePid; + let cid; + let uid; let endorsed; - - it('create a post', async function () { + it('create a post where endorsed is false', async function () { try { + // Create a user uid = await user.create({ username: 'uploads user', password: 'abracadabra', gdpr_consent: 1, }); + // Create a test category ({ cid } = await categories.create({ name: 'Test Category', description: 'Test category created by testing script', })); - endorsed = false; - + // Create a post within the category const topicPostData = await topics.post({ uid, cid, title: 'topic with some images', content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', - endorsed }); - } catch (error) { - assert.strictEqual(error.message, '[[error:invalid-uid]]'); + + // Check if 'endorsed' is false + endorsed = topicPostData.postData.endorsed; + assert.strictEqual(endorsed, false); + } catch (error) { + console.log(error); } }); }); From cc1525a18ff203116ae22123c2a1a56f0193520d Mon Sep 17 00:00:00 2001 From: AliceeLe Date: Mon, 7 Oct 2024 19:26:26 -0400 Subject: [PATCH 3/5] Finalize test suite for create that is relevant with endorse --- test/posts/create.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/posts/create.js b/test/posts/create.js index 709e514db1..43bfa2ab34 100644 --- a/test/posts/create.js +++ b/test/posts/create.js @@ -19,8 +19,7 @@ describe('create post', function () { let uid; let endorsed; - it('create a post where endorsed is false', async function () { - try { + before(async function () { // Create a user uid = await user.create({ username: 'uploads user', @@ -33,7 +32,10 @@ describe('create post', function () { name: 'Test Category', description: 'Test category created by testing script', })); - + }); + + it('create a post where endorsed is automatically false', async function () { + try { // Create a post within the category const topicPostData = await topics.post({ uid, @@ -41,7 +43,7 @@ describe('create post', function () { title: 'topic with some images', content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', }); - + // Check if 'endorsed' is false endorsed = topicPostData.postData.endorsed; assert.strictEqual(endorsed, false); @@ -49,10 +51,24 @@ describe('create post', function () { console.log(error); } }); -}); -describe('addReplyTo', function () { + it('create a post where endorsed is initialized to be true', async function () { + try { + // Create a post within the category + const topicPostData = await topics.post({ + uid, + cid, + title: 'topic with some images', + content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', + endorsed: true + }); + + // Check if 'endorsed' is false + endorsed = topicPostData.postData.endorsed; + assert.strictEqual(endorsed, true); + } catch (error) { + console.log(error); + } + }); }); -describe('checkToPid', function () { -}); From 45092c49225fd9fbc761c912da160ea8ba9ce3d1 Mon Sep 17 00:00:00 2001 From: AliceeLe Date: Thu, 10 Oct 2024 23:48:08 -0400 Subject: [PATCH 4/5] Improve styling based on eslint suggestions --- test/posts/create.js | 46 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/test/posts/create.js b/test/posts/create.js index 43bfa2ab34..fa1c0e0102 100644 --- a/test/posts/create.js +++ b/test/posts/create.js @@ -11,31 +11,30 @@ const privileges = require('../../src/privileges'); const meta = require('../../src/meta'); const Posts = {}; - -describe('create post', function () { +describe('create post', () => { let pid; let purgePid; let cid; let uid; let endorsed; - before(async function () { - // Create a user - uid = await user.create({ - username: 'uploads user', - password: 'abracadabra', - gdpr_consent: 1, - }); - - // Create a test category - ({ cid } = await categories.create({ - name: 'Test Category', - description: 'Test category created by testing script', - })); + before(async () => { + // Create a user + uid = await user.create({ + username: 'uploads user', + password: 'abracadabra', + gdpr_consent: 1, + }); + + // Create a test category + ({ cid } = await categories.create({ + name: 'Test Category', + description: 'Test category created by testing script', + })); }); - it('create a post where endorsed is automatically false', async function () { - try { + it('create a post where endorsed is automatically false', async () => { + try { // Create a post within the category const topicPostData = await topics.post({ uid, @@ -43,7 +42,7 @@ describe('create post', function () { title: 'topic with some images', content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', }); - + // Check if 'endorsed' is false endorsed = topicPostData.postData.endorsed; assert.strictEqual(endorsed, false); @@ -52,18 +51,18 @@ describe('create post', function () { } }); - it('create a post where endorsed is initialized to be true', async function () { - try { + it('create a post where endorsed is initialized to be true', async () => { + try { // Create a post within the category const topicPostData = await topics.post({ uid, cid, title: 'topic with some images', content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', - endorsed: true + endorsed: true, }); - - // Check if 'endorsed' is false + + // Check if 'endorsed' is true endorsed = topicPostData.postData.endorsed; assert.strictEqual(endorsed, true); } catch (error) { @@ -71,4 +70,3 @@ describe('create post', function () { } }); }); - From d4f33771cbb97b6effa0c674168ff3ec16a3ee9d Mon Sep 17 00:00:00 2001 From: AliceeLe Date: Fri, 11 Oct 2024 00:46:19 -0400 Subject: [PATCH 5/5] Adjust styling --- .prettierrc | 9 ++++ test/posts/create.js | 105 ++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 51 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..041802b4f1 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "useTabs": true, + "arrowParens": "always", + "endOfLine": "auto", + "singleQuote": true, + "tabWidth": 1, + "requirePragma": false, + "insertPragma": false +} \ No newline at end of file diff --git a/test/posts/create.js b/test/posts/create.js index fa1c0e0102..d4b13debc1 100644 --- a/test/posts/create.js +++ b/test/posts/create.js @@ -9,64 +9,67 @@ const categories = require('../../src/categories'); const groups = require('../../src/groups'); const privileges = require('../../src/privileges'); const meta = require('../../src/meta'); + const Posts = {}; describe('create post', () => { - let pid; - let purgePid; - let cid; - let uid; - let endorsed; + let pid; + let purgePid; + let cid; + let uid; + let endorsed; - before(async () => { - // Create a user - uid = await user.create({ - username: 'uploads user', - password: 'abracadabra', - gdpr_consent: 1, - }); + before(async () => { + // Create a user + uid = await user.create({ + username: 'uploads user', + password: 'abracadabra', + gdpr_consent: 1, + }); - // Create a test category - ({ cid } = await categories.create({ - name: 'Test Category', - description: 'Test category created by testing script', - })); - }); + // Create a test category + ({ cid } = await categories.create({ + name: 'Test Category', + description: 'Test category created by testing script', + })); + }); - it('create a post where endorsed is automatically false', async () => { - try { - // Create a post within the category - const topicPostData = await topics.post({ - uid, - cid, - title: 'topic with some images', - content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', - }); + it('create a post where endorsed is automatically false', async () => { + try { + // Create a post within the category + const topicPostData = await topics.post({ + uid, + cid, + title: 'topic with some images', + content: + 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', + }); - // Check if 'endorsed' is false - endorsed = topicPostData.postData.endorsed; - assert.strictEqual(endorsed, false); - } catch (error) { - console.log(error); - } - }); + // Check if 'endorsed' is false + endorsed = topicPostData.postData.endorsed; + assert.strictEqual(endorsed, false); + } catch (error) { + console.log(error); + } + }); - it('create a post where endorsed is initialized to be true', async () => { - try { - // Create a post within the category - const topicPostData = await topics.post({ - uid, - cid, - title: 'topic with some images', - content: 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', - endorsed: true, - }); + it('create a post where endorsed is initialized to be true', async () => { + try { + // Create a post within the category + const topicPostData = await topics.post({ + uid, + cid, + title: 'topic with some images', + content: + 'here is an image [alt text](/assets/uploads/files/abracadabra.png) and another [alt text](/assets/uploads/files/shazam.jpg)', + endorsed: true, + }); - // Check if 'endorsed' is true - endorsed = topicPostData.postData.endorsed; - assert.strictEqual(endorsed, true); - } catch (error) { - console.log(error); - } - }); + // Check if 'endorsed' is true + endorsed = topicPostData.postData.endorsed; + assert.strictEqual(endorsed, true); + } catch (error) { + console.log(error); + } + }); });