From 843e9000efabdd117a1f3ea1700032b857d16905 Mon Sep 17 00:00:00 2001 From: Sobabili Thoriso Nkwanyana Date: Thu, 12 Nov 2026 08:36:10 +0200 Subject: [PATCH] initial commit --- tests/wil/office-5/activity.test.mjs | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/wil/office-5/activity.test.mjs diff --git a/tests/wil/office-5/activity.test.mjs b/tests/wil/office-5/activity.test.mjs new file mode 100644 index 0000000..83b9231 --- /dev/null +++ b/tests/wil/office-5/activity.test.mjs @@ -0,0 +1,83 @@ +// Import the necessary modules for testing +import test from 'node:test'; +// Import the assert module for assertions +import assert from 'node:assert/strict'; +// Import the Activity class from the specified path +import { Activity } from '../../../src/wil/office-5/activity.js'; + +// Import the toActivity Entry and newActivityEntry functions from the specified path +import { toActivityEntry, newActivityEntry } from '../../../src/wil/office-5/activity.js'; + +// Test case to check if stable fields are retained for player activity +test('retains stable fields for player activity', () => { + // Create a new Activity instance with specific properties + const activity = new Activity({ + id: '123', + category: 'game', + action : 'play', + timestamp: 1620000000, + actor: { id: 'player1', type: 'user' }, + server: { id: 'server1', type: 'server' }, + message: 'Player started a game session', + }); + + // Convert the activity to an activity entry using the toActivityEntry function + const result = toActivityEntry(activity); + // Assert that the result has the expected properties and values + assert.equal(result.id,activity.id); + // + assert.equal(result.category, "player"); + assert.equal(result.action, "join"); + assert.equal(result.timestamp, activity.timestamp); +}), + +test('server activity retains stable fields with null server', () => { + const activity = new Activity({ + id: '456', + category: 'server', + action: 'start', + timestamp: 1620000000, + actor: { id: 'player2', type: 'user' }, + server: null, + message: 'Server started', + }); + + const result = newActivityEntry(activity); + + assert.equal(result.id, '456'); + assert.equal(result.category, 'audit'); + assert.equal(result.action, "start"); + assert.equal(result.timestamp, activity.timestamp); + + assert.equal(result.actor.id, null); +}); + +test('does not invent actor or invalid link fields for server activity', () => { + const activity = new Activity({ + id: '789', + category: 'server', + action: 'stop', + timestamp: 1620000000, + actor: null, + server: null, + }); + + assert.equal(activity.actor, null); + + assert.ok(!('link' in activity) || isValidLink(activity.link)); +}); + +test('perserves plain text and omits private fields', () => { + const activity = new Activity({ + id: '101112', + category: 'game', + action: 'play', + timestamp: 1620000000, + message: 'Player started a game session', + privateField: 'should be omitted', + }); + + assert.equal(typeof result.message, 'string'); + assert.equal(result.message, 'Player started a game session'); + assert.ok(!('privateField' in result)); +}); \ No newline at end of file