Files
sd1-office-5-Sobabili-feat-…/tests/wil/office-5/activity.test.mjs
T

83 lines
2.6 KiB
JavaScript

// 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));
});