mirror of
https://github.com/l5yth/potato-mesh.git
synced 2026-08-09 10:22:52 +02:00
Added comprehensive helper unit tests (#457)
* Added comprehensive helper unit tests * run black
This commit is contained in:
@@ -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!
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user