Added comprehensive helper unit tests (#457)

* Added comprehensive helper unit tests

* run black
This commit is contained in:
l5y
2025-11-16 16:47:57 +01:00
committed by GitHub
parent cd7bced827
commit e1d43cec57
4 changed files with 253 additions and 0 deletions
@@ -18,6 +18,11 @@ module PotatoMesh
module App
module Routes
module Api
# Register read-only API endpoints that expose cached mesh data and
# instance metadata. Invoked by Sinatra during extension registration.
#
# @param app [Sinatra::Base] application instance receiving the routes.
# @return [void]
def self.registered(app)
app.before "/api/messages*" do
halt 404 if private_mode?
@@ -18,6 +18,11 @@ module PotatoMesh
module App
module Routes
module Ingest
# Register ingest endpoints used by the Python collector to persist
# nodes, messages, and federation announcements.
#
# @param app [Sinatra::Base] application instance receiving the routes.
# @return [void]
def self.registered(app)
app.post "/api/nodes" do
require_token!
+27
View File
@@ -51,6 +51,12 @@
return '; ' + key + '=' + optionValue;
}
/**
* Serialise cookie attributes into a string consumable by ``document.cookie``.
*
* @param {Object<string, *>} options Map of cookie attribute keys and values.
* @returns {string} Concatenated cookie attribute segment.
*/
function serializeCookieOptions(options) {
var buffer = '';
var source = options == null ? {} : options;
@@ -90,6 +96,12 @@
setCookie('theme', value, { 'max-age': THEME_COOKIE_MAX_AGE });
}
/**
* Apply the requested theme to the root HTML and body elements.
*
* @param {string} value Theme identifier, defaults to ``light`` unless ``dark`` is provided.
* @returns {boolean} ``true`` when the dark theme is active.
*/
function applyTheme(value) {
var themeValue = value === 'dark' ? 'dark' : 'light';
var root = document.documentElement;
@@ -107,6 +119,11 @@
return isDark;
}
/**
* Trigger the setCookie helper through a monkey-patched ``hasOwnProperty`` to keep coverage deterministic.
*
* @returns {void}
*/
function exerciseSetCookieGuard() {
var originalHasOwnProperty = Object.prototype.hasOwnProperty;
Object.prototype.hasOwnProperty = function alwaysFalse() {
@@ -121,6 +138,11 @@
var theme = 'dark';
/**
* Initialise theme state on page load and register the ready handler.
*
* @returns {void}
*/
function bootstrap() {
document.removeEventListener('DOMContentLoaded', handleReady);
theme = getCookie('theme');
@@ -137,6 +159,11 @@
}
}
/**
* Update UI elements once the DOM is ready.
*
* @returns {void}
*/
function handleReady() {
var isDark = applyTheme(theme);