Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Automated Testing for Resources Page - User Story 5 #52

Open
wants to merge 167 commits into
base: f24
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
51634c7
Added conflicting changes into my sidebar-left.tpl file
AlAnoud2003 Sep 26, 2024
4adc173
Made changes to a duplicated theme
Oct 7, 2024
5dc3e4a
Added resources changes in my topic.scss file
AlAnoud2003 Oct 7, 2024
82d75fd
Copied resources button code in the topic-list-bar.tpl
AlAnoud2003 Oct 7, 2024
6f77875
added code that imports the module in index.js
AlAnoud2003 Oct 7, 2024
e4b9bb9
added the code to render the button template
AlAnoud2003 Oct 7, 2024
6406612
Imported the resources button controller and set up a route to the co…
AlAnoud2003 Oct 8, 2024
23322d5
Added the HTML template for the Resources page that will display the …
AlAnoud2003 Oct 8, 2024
c0e3d93
Commented out plugin testing
AlAnoud2003 Oct 8, 2024
0934735
NEW MODIFICATIONS - added a line in create.js to extract links from t…
AlAnoud2003 Oct 8, 2024
8375365
Modified the resorces-button.js to getch and display the links
AlAnoud2003 Oct 8, 2024
1ed362c
Displaying links in on the resources button template
AlAnoud2003 Oct 8, 2024
7001460
Uncommented out code
AlAnoud2003 Oct 11, 2024
b4735c6
Testing extracted links from discussion posts
AlAnoud2003 Oct 11, 2024
1242bd6
Added a line for debugging
AlAnoud2003 Oct 11, 2024
cc3b0eb
Added code (Express and Handlebars) in app.js to link data with view
AlAnoud2003 Oct 11, 2024
8ec413f
Added routing in the app.js file
AlAnoud2003 Oct 11, 2024
e848171
Changed the port number for the added code in app.js
AlAnoud2003 Oct 11, 2024
91a11ea
Added a temporary database in the app.js file
AlAnoud2003 Oct 11, 2024
d82d4f7
Removed new code form app.js as it was causing errors
AlAnoud2003 Oct 11, 2024
fd4e3f5
Renamed a file
AlAnoud2003 Oct 11, 2024
bde6212
Combiend 2 definitions of getResourcesButtonPage into one definition
AlAnoud2003 Oct 11, 2024
95b0584
Modified the code to extract links from user posts in create.js
AlAnoud2003 Oct 11, 2024
12f721f
Modified the code to extract links from user posts in create.js
AlAnoud2003 Oct 11, 2024
c57bee0
Modified code routing in app.js and changed resources-button from tpl…
AlAnoud2003 Oct 11, 2024
25e0eaa
Modified code routing in app.js and changed resources-button from tpl…
AlAnoud2003 Oct 11, 2024
9759831
Reverted changes from app.js and resources-button.tpl
AlAnoud2003 Oct 11, 2024
85ab098
added theme repo to install/package.json
Oct 12, 2024
c43b683
Created a route that will fetch the links inputted by the users
AlAnoud2003 Oct 12, 2024
0cef8f3
Uncommented out code in test/controllers-admin.js
AlAnoud2003 Oct 12, 2024
197ac85
Added line to mount the resources route
AlAnoud2003 Oct 12, 2024
2d49381
Changed the rendered template in the controller
AlAnoud2003 Oct 12, 2024
7ad0d67
Moved the 'use script' line to the top of the tester file
AlAnoud2003 Oct 12, 2024
3b7b1fa
Deleted temporary tester file
AlAnoud2003 Oct 12, 2024
9084dda
Renamed rhe controller being called in index.js
AlAnoud2003 Oct 12, 2024
6bb3583
Update the import statement in index
AlAnoud2003 Oct 12, 2024
dab1dec
Modified the import in index
AlAnoud2003 Oct 12, 2024
e296387
Update the import statement in index
AlAnoud2003 Oct 12, 2024
e7bced2
Changed the name of the controller
AlAnoud2003 Oct 12, 2024
64cfca2
Changed the controller import name
AlAnoud2003 Oct 12, 2024
3931448
Reverted changes in controller
AlAnoud2003 Oct 12, 2024
29c8eb6
Renamed template
AlAnoud2003 Oct 12, 2024
91b525e
Reverted changes in controllers/inndex
AlAnoud2003 Oct 12, 2024
74b5844
Reverted changes in routes index
AlAnoud2003 Oct 12, 2024
e80cbc5
Defined resources route in app.js and added debugging line in the res…
AlAnoud2003 Oct 12, 2024
e5855e8
Removed changes in app
AlAnoud2003 Oct 12, 2024
639ab72
Modified the code in the routes to handle the resources controller
AlAnoud2003 Oct 12, 2024
8ffaddb
Changed the file type for the resources page
AlAnoud2003 Oct 12, 2024
0f8f550
Modified the code in the routes to handle the resources controller
AlAnoud2003 Oct 12, 2024
f5577a2
Changed file from handlers to template
AlAnoud2003 Oct 12, 2024
e54a6a7
added schema
Oct 12, 2024
29bfeae
added schema, fixed filename
Oct 12, 2024
f0621e4
modified resources-button.js to return json
Oct 12, 2024
68c1c99
Committed dump file
AlAnoud2003 Oct 12, 2024
02f08aa
Resolved conflicts when merging changes from Ruba's resources branch …
AlAnoud2003 Oct 13, 2024
b5abd83
Accepted incoming changes in sidebar-left.tpl file
AlAnoud2003 Oct 13, 2024
c4db7d1
Added script in resources-button.tpl that will fetch links and add th…
AlAnoud2003 Oct 13, 2024
2815246
Modified the controller to fetch and render the links
AlAnoud2003 Oct 13, 2024
16d529b
Added a route to to handle the API request
AlAnoud2003 Oct 13, 2024
700bdda
Imported database in resources-button.js and defined the API endpoint…
AlAnoud2003 Oct 13, 2024
3618fa3
Removed added code in routes/index.js
AlAnoud2003 Oct 13, 2024
39bf3b7
Added code in routes/index to define the API endpoint
AlAnoud2003 Oct 13, 2024
b92aed2
Removed a line in routes/index
AlAnoud2003 Oct 13, 2024
f36f6a6
Added a router in routes/index
AlAnoud2003 Oct 13, 2024
f923644
Removed changes in index
AlAnoud2003 Oct 13, 2024
5ebb13c
Modified the link extraction logic
AlAnoud2003 Oct 14, 2024
0bda13c
Deleted routes/resources.js as it was unnecessary
AlAnoud2003 Oct 14, 2024
8591c71
Removed unnecessary code in resources-button.tpl
AlAnoud2003 Oct 14, 2024
2beea35
Modified the link extraction logic to pass the links to the template
AlAnoud2003 Oct 14, 2024
ceb1b87
Fixed indentations in resources-button.js
AlAnoud2003 Oct 14, 2024
3547449
Ensured the routing that will fetch the links is correct
AlAnoud2003 Oct 14, 2024
6f25323
Removed code that did not start the sevrer
AlAnoud2003 Oct 14, 2024
4c76fc1
Modified the controller to generate the HTML for the links in the con…
AlAnoud2003 Oct 14, 2024
a25eb19
Used a placeholder in the resources-button.tpl to inject the generate…
AlAnoud2003 Oct 14, 2024
3d39343
Modified the controller to clean up the links before generating the HTML
AlAnoud2003 Oct 14, 2024
baecc1a
Passed the links as a JSON object to the template
AlAnoud2003 Oct 14, 2024
74924f5
Passed the links as a JSON object to the template
AlAnoud2003 Oct 14, 2024
09b2696
Used an inline script to generate the HTML for the links
AlAnoud2003 Oct 14, 2024
ab989ec
Ensured the correct JSON parsing of the links
AlAnoud2003 Oct 14, 2024
b9eba97
Ensured the correct JSON parsing of the links
AlAnoud2003 Oct 14, 2024
143ed17
Ensured the correct JSON parsing of the links
AlAnoud2003 Oct 14, 2024
5d0c57b
Ensured the JSON string is properly
AlAnoud2003 Oct 14, 2024
f6831e3
Edited the console log statement
AlAnoud2003 Oct 14, 2024
af5604b
Modified a line of code in resources-button.tpl
AlAnoud2003 Oct 14, 2024
c095088
Updated resources-button.tpl to pass the links to the template
AlAnoud2003 Oct 14, 2024
fb7e53e
Reverted changes in resources-button.tpl
AlAnoud2003 Oct 14, 2024
e14b608
Changed the way the links are rendered in resources-button.tpl
AlAnoud2003 Oct 14, 2024
ea0cf48
Changed the code so that it passes the linsk as a JSON string to the …
AlAnoud2003 Oct 14, 2024
3150361
Fixed syntax error
AlAnoud2003 Oct 14, 2024
d79499f
Edited a comment in controllers/index
AlAnoud2003 Oct 15, 2024
a9cefd7
Deleted a chunk of code for testing
AlAnoud2003 Oct 15, 2024
27885d0
Added automated tests in test/posts.
AlAnoud2003 Oct 15, 2024
e2d05c8
Fixed syntax error
AlAnoud2003 Oct 15, 2024
19ebac2
Modified the link extraction logic to avoid duplicates
AlAnoud2003 Oct 15, 2024
d3fb7b0
Modifying the link non-duplication logic
AlAnoud2003 Oct 15, 2024
ea590a0
Modifyed the test/posts.js to handle duplicate links
AlAnoud2003 Oct 15, 2024
79bb7ff
Fixed syntax errors
AlAnoud2003 Oct 15, 2024
0ddb0e4
Modifyed test/posts.js
AlAnoud2003 Oct 15, 2024
9ebbd71
Modifyed the testing logic for the post link extraction
AlAnoud2003 Oct 15, 2024
1ee9c38
Modifyed the link extraction test
AlAnoud2003 Oct 15, 2024
cd93b5c
Modifyed the link extraction test
AlAnoud2003 Oct 15, 2024
7e8a607
Modifyed the link extraction test
AlAnoud2003 Oct 15, 2024
e2645f7
Modifyed the link extraction test
AlAnoud2003 Oct 15, 2024
2ed593e
Modifyed the link extraction test
AlAnoud2003 Oct 15, 2024
950c8fd
Moved the link extraction function directly in the test file
AlAnoud2003 Oct 15, 2024
49abb7a
Moved link extraction test to a new file
AlAnoud2003 Oct 15, 2024
bcaa03e
Fixed syntax error
AlAnoud2003 Oct 15, 2024
55dbdf6
Modifyed the link extraction function
AlAnoud2003 Oct 15, 2024
40bb2de
Fixed syntax
AlAnoud2003 Oct 15, 2024
5a442ce
Fixed syntax
AlAnoud2003 Oct 15, 2024
282d0bf
Fixed syntax
AlAnoud2003 Oct 15, 2024
ad9642a
Fixed syntax
AlAnoud2003 Oct 15, 2024
ab6c2ef
Fixed syntax
AlAnoud2003 Oct 15, 2024
fbe7040
Fixed syntax
AlAnoud2003 Oct 15, 2024
a585b4c
Fixed syntax
AlAnoud2003 Oct 15, 2024
76c2478
Fixed syntax
AlAnoud2003 Oct 15, 2024
068e8ca
Created a file with automated testing for the resoures page
AlAnoud2003 Oct 15, 2024
b8e652f
modifyed the automated testing for the resoures page
AlAnoud2003 Oct 16, 2024
c99b12f
modifyed the automated testing for the resoures page
AlAnoud2003 Oct 16, 2024
768299b
Sorting the links alphabetically
AlAnoud2003 Oct 16, 2024
2a0093a
Included the user strict in test/resources-page-test.js
AlAnoud2003 Oct 16, 2024
ae82e0a
Modifyed the create.js file to handle Markdown links correctly
AlAnoud2003 Oct 16, 2024
9e27faf
Modifyed the create.js file to handle Markdown links correctly
AlAnoud2003 Oct 16, 2024
3ab7550
Fixing syntax error in create and adjusting the topic-list-bar.tpl
AlAnoud2003 Oct 17, 2024
0918c25
Fixed syntax error
AlAnoud2003 Oct 17, 2024
3861e74
Added a function to ensure the displayng of the resources button in t…
AlAnoud2003 Oct 17, 2024
8840433
Added code to regonize that a post was created to ensure the resource…
AlAnoud2003 Oct 17, 2024
9935e81
Reverted changes in create and topic-list-bar.tpl
AlAnoud2003 Oct 17, 2024
476cb9e
Added code to ensure the visibility of the button when the DOM changes
AlAnoud2003 Oct 17, 2024
cdcdfaf
Mofiyed the code to ensure resource button visibility
AlAnoud2003 Oct 17, 2024
41981f9
Reverted changes
AlAnoud2003 Oct 17, 2024
7a6af86
Updated code in resources-button.js to use the message property
AlAnoud2003 Oct 17, 2024
26c399c
Modifyed the code to define the links in the schema
AlAnoud2003 Oct 17, 2024
a4a783b
Fixed syntax errors
AlAnoud2003 Oct 17, 2024
94a768a
Fixed syntax
AlAnoud2003 Oct 18, 2024
2a4c903
Fixed syntax
AlAnoud2003 Oct 18, 2024
e00039d
Fixed syntax
AlAnoud2003 Oct 18, 2024
0fbe17a
Fixed syntax
AlAnoud2003 Oct 18, 2024
c1c82ab
Trying to fix for npm run test
AlAnoud2003 Oct 18, 2024
5b6fbee
Fixed syntax errors
AlAnoud2003 Oct 18, 2024
b89810f
Fixed syntax errors
AlAnoud2003 Oct 18, 2024
6d62fdb
Fixed syntax errors
AlAnoud2003 Oct 18, 2024
322c476
Fixed syntax errors
AlAnoud2003 Oct 18, 2024
7b4c76c
Uncommented out code to render the resources page
AlAnoud2003 Oct 18, 2024
0ccaa9e
Trying to fix npm run test
AlAnoud2003 Oct 18, 2024
e8fe640
Trying to fix npm run test
AlAnoud2003 Oct 18, 2024
83163f0
Modifyed the schema to include message and links
AlAnoud2003 Oct 18, 2024
dd50582
Ensured that npm run test works - still working on automated tesintg
AlAnoud2003 Oct 18, 2024
acc6a3b
Trying to fix resource page rendering
AlAnoud2003 Oct 18, 2024
8bddc13
Trying to fix resource page rendering
AlAnoud2003 Oct 18, 2024
a7f49d4
Trying to fix resource page rendering
AlAnoud2003 Oct 18, 2024
8f1a172
Modifyed code in resources-button.js to fix reousrce page render and …
AlAnoud2003 Oct 18, 2024
f9a6b77
Syntax error
AlAnoud2003 Oct 18, 2024
74e275a
Fixed website rendering
AlAnoud2003 Oct 18, 2024
bc4c84f
Trying to fix npm run test in topics.js
AlAnoud2003 Oct 18, 2024
4ad2391
Fixing testing issue
AlAnoud2003 Oct 18, 2024
fe67eca
Trying to fix npm run test
AlAnoud2003 Oct 18, 2024
9692f03
Reverted changes in controller
AlAnoud2003 Oct 18, 2024
ba82087
Deleted testing files in this branch to be created in another branch
AlAnoud2003 Oct 18, 2024
db62d65
Simplified the link extraction logic in create.js
AlAnoud2003 Oct 18, 2024
73b488d
Deleted unnecessary comments
AlAnoud2003 Oct 18, 2024
929ed28
Fixed lint error in create.js
AlAnoud2003 Oct 18, 2024
1e0231c
Trying to fix syntax error
AlAnoud2003 Oct 18, 2024
6059311
Added automated testing: link-extraction.js (for extracting links fro…
AlAnoud2003 Oct 19, 2024
989d23f
Added a test case in test/api.js to test the api for the resources-bu…
AlAnoud2003 Oct 19, 2024
6f5398c
Modified the autmated test files to be able to run successfuly using …
AlAnoud2003 Oct 19, 2024
39e3bc8
Fixed lint syntax errors and reverted changes in test/api.js
AlAnoud2003 Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ if (nconf.get('setup') || nconf.get('install')) {
} else {
require('./src/start').start();
}

Binary file added custom_themes/nodebb-theme-testing.zip
Binary file not shown.
1 change: 1 addition & 0 deletions custom_themes/nodebb-theme-testing1
Submodule nodebb-theme-testing1 added at d493d6
Binary file modified dump.rdb
Binary file not shown.
3 changes: 2 additions & 1 deletion install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
]
},
"dependencies": {
"nodebb-theme-testing": "github:rmmahmou/nodebb-theme-testing",
"@adactive/bootstrap-tagsinput": "0.8.2",
"@fontsource/inter": "5.0.18",
"@fontsource/poppins": "5.0.14",
Expand Down Expand Up @@ -195,4 +196,4 @@
"url": "https://github.com/barisusakli"
}
]
}
}
14 changes: 14 additions & 0 deletions node_modules/nodebb-theme-harmony/scss/topic.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion public/openapi/read.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,6 @@ paths:
"/api/groups/{slug}/members":
$ref: 'read/groups/slug/members.yaml'
/api/outgoing:
$ref: 'read/outgoing.yaml'
$ref: 'read/outgoing.yaml'
/api/resources-button:
$ref: 'read/resources-button.yaml'
18 changes: 18 additions & 0 deletions public/openapi/read/resources-button.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
get:
summary: "Retrieve resources button data"
description: "Endpoint to get resources button information"
responses:
'200':
description: "Successful response"
content:
application/json:
schema:
type: object
required:
- message
- title
properties:
message:
type: string
description: "A message indicating the result of the operation"

2 changes: 2 additions & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Controllers.osd = require('./osd');
Controllers['404'] = require('./404');
Controllers.errors = require('./errors');
Controllers.composer = require('./composer');
Controllers.resourcesButton = require('./resources-button');


Controllers.write = require('./write');

Expand Down
27 changes: 27 additions & 0 deletions src/controllers/resources-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

// Import the db module
const db = require('../database');

const controllers = {};

controllers.getResourcesButtonPage = async (req, res) => {
try {
const links = await db.getSetMembers('resources:links');
const cleanedLinks = links.map(link => link.replace(/\]\(.*?\)/g, ''));
console.log('Extracted links:', cleanedLinks); // Log the cleaned links to the console

res.render('resources-button', {
message: 'Links retrieved successfully',
links: JSON.stringify(cleanedLinks),
});
} catch (err) {
console.error('Error retrieving links:', err);
res.status(500).json({
message: 'An error occurred while fetching links',
error: err.message,
});
}
};

module.exports = controllers;
28 changes: 28 additions & 0 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const categories = require('../categories');
const groups = require('../groups');
const privileges = require('../privileges');


module.exports = function (Posts) {
Posts.create = async function (data) {
// This is an internal method, consider using Topics.reply instead
Expand Down Expand Up @@ -54,6 +55,33 @@ module.exports = function (Posts) {
const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']);
postData.cid = topicData.cid;

// Define the link extraction logic
function extractLinks(text) {
const urlRegex = /\[.*?\]\((https?:\/\/[^\s)]+)\)|\bhttps?:\/\/[^\s)]+/g;
const links = [];

let match = urlRegex.exec(text);
while (match !== null) {
if (match[1]) {
links.push(match[1]); // Extract URL from Markdown link
} else {
links.push(match[0]); // Extract plain URL
}
match = urlRegex.exec(text); // Re-execute regex for the next match
}

console.log('Raw Extracted links:', links); // Log the extracted links
return [...new Set(links)]; // Remove duplicates
}

// Extract links from post content
const links = extractLinks(postData.content);
if (links.length > 0) {
console.log('Extracted links:', links);
await db.setAdd(`post:${postData.pid}:links`, links);
await db.setAdd('resources:links', links);
}

await Promise.all([
db.sortedSetAdd('posts:pid', timestamp, postData.pid),
db.incrObjectField('global', 'postCount'),
Expand Down
3 changes: 3 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const express = require('express');

const meta = require('../meta');
const controllers = require('../controllers');
const resourcesButtonController = require('../controllers/resources-button');
const controllerHelpers = require('../controllers/helpers');
const plugins = require('../plugins');

Expand Down Expand Up @@ -80,6 +81,7 @@ _mounts.categories = (app, name, middleware, controllers) => {
setupPageRoute(app, '/recent', [], controllers.recent.get);
setupPageRoute(app, '/top', [], controllers.top.get);
setupPageRoute(app, '/unread', [middleware.ensureLoggedIn], controllers.unread.get);
setupPageRoute(app, '/resources-button', [], resourcesButtonController.getResourcesButtonPage);
};

_mounts.category = (app, name, middleware, controllers) => {
Expand Down Expand Up @@ -158,6 +160,7 @@ function addCoreRoutes(app, router, middleware, mounts) {
_mounts.mod(router, middleware, controllers);
_mounts.globalMod(router, middleware, controllers);


addRemountableRoutes(app, router, middleware, mounts);

const relativePath = nconf.get('relative_path');
Expand Down
31 changes: 31 additions & 0 deletions src/views/resources-button.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
</head>
<body>
<div class="container">
<h1>Resources</h1>
<p>Welcome to the resources page! Here you can find various links and materials.</p>

<h2>Useful Links</h2>
<ul id="links-list"></ul>
</div>
<script>
// Parse the links JSON string
const links = JSON.parse('{{links}}');
links.sort();
const linksList = document.getElementById('links-list');

// Generate the HTML for the links
links.forEach(link => {
const li = document.createElement('li');
const a = document.createElement('a');
a.href = link;
a.target = '_blank';
a.textContent = link;
li.appendChild(a);
linksList.appendChild(li);
});
</script>
</body>
77 changes: 77 additions & 0 deletions test/api-resources-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

const assert = require('assert');

// Custom implementation of describe and it functions
function describe(description, callback) {
console.log(description);
callback();
}

function it(description, callback) {
try {
console.log(` ${description}`);
callback();
console.log(' ✓ Test passed');
} catch (error) {
console.error(' ✗ Test failed:', error);
}
}

// Mock function to simulate supertest
function mockSupertest(url) {
return {
get: async function (endpoint) {
console.log(`Mock GET request to ${url}${endpoint}`);
if (endpoint === '/api/resources-button') {
return {
status: 200,
body: { property1: 'value1', property2: 'value2', property3: 'value3' },
};
} else if (endpoint === '/api/resources-button?invalidParam=true') {
return {
status: 400,
body: { message: 'Invalid request' },
};
}
return { status: 404, body: {} };
},
};
}

describe('API /resources-button', () => {
it('should return a successful response', async () => {
console.log('Sending GET request to /api/resources-button...');
const response = await mockSupertest('http://localhost:4567').get('/api/resources-button');
console.log('Received response:', response.body);

assert.strictEqual(response.status, 200);
console.log('Assertion passed: status is 200');
});

it('should return the expected properties in the response', async () => {
console.log('Sending GET request to /api/resources-button...');
const response = await mockSupertest('http://localhost:4567').get('/api/resources-button');
console.log('Received response:', response.body);

const expectedProperties = ['property1', 'property2', 'property3']; // Replace with actual properties
expectedProperties.forEach((prop) => {
assert(response.body.hasOwnProperty(prop), `"${prop}" is missing in the response`);
console.log(`Assertion passed: "${prop}" is present in the response`);
});
});

it('should handle invalid requests gracefully', async () => {
console.log('Sending GET request to /api/resources-button with invalid parameters...');
const response = await mockSupertest('http://localhost:4567').get('/api/resources-button?invalidParam=true');
console.log('Received response:', response.body);

assert.strictEqual(response.status, 400); // Adjust the expected status code
console.log('Assertion passed: status is 400');

assert.strictEqual(response.body.message, 'Invalid request'); // Adjust the expected error message
console.log('Assertion passed: response.body.message is "Invalid request"');
});

console.log('All tests completed successfully.');
});
2 changes: 2 additions & 0 deletions test/controllers-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ describe('Admin Controllers', () => {
}
});


it('should load /admin/extend/plugins', async function () {
this.timeout(50000);
const { body } = await request.get(`${nconf.get('url')}/api/admin/extend/plugins`, { jar: jar });
Expand All @@ -199,6 +200,7 @@ describe('Admin Controllers', () => {
assert(body.hasOwnProperty('incompatible'));
});


it('should load /admin/manage/users', async () => {
const { response, body } = await request.get(`${nconf.get('url')}/api/admin/manage/users`, { jar: jar, json: true });
assert.strictEqual(response.statusCode, 200);
Expand Down
Loading
Loading