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

Activity Log backend and WebUI #110

Merged
merged 21 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion main/activity-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ActivityLog {
*/
function loadStoredEntries () {
// A workaround to fix false TypeScript errors
return /** @type {any} */(activityLogStore.get('events', []))
return /** @type {any} */(activityLogStore.get('activities', []))
juliangruber marked this conversation as resolved.
Show resolved Hide resolved
}

module.exports = {
Expand Down
20 changes: 10 additions & 10 deletions main/test/activity-log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const { assertTimestampIsCloseToNow, pickProps } = require('./test-helpers')
/** @typedef {import('../typings').RecordActivityArgs} RecordActivityOptions */

describe('ActivityLog', function () {
beforeEach(function () { return new ActivityLog().reset() })
beforeEach(function () {
return new ActivityLog().reset()
})

it('record activities and assign them timestamp and id ', function () {
const activityLog = new ActivityLog()
Expand All @@ -20,34 +22,32 @@ describe('ActivityLog', function () {
assert.strictEqual(activityLog.getAllEntries().length, 1)
assert.deepStrictEqual(activityCreated, activityLog.getAllEntries()[0])

const { timestamp, ...activity } = activityLog.getAllEntries()[0]
const { id, timestamp, ...activity } = activityLog.getAllEntries()[0]
assert.deepStrictEqual(activity, {
id: '1',
source: 'Station',
type: 'info',
message: 'Hello world!'
})

assert.equal(typeof id, 'string')
assertTimestampIsCloseToNow(timestamp, 'activity.timestamp')
})

it('assigns unique ids', function () {
const activityLog = new ActivityLog()
activityLog.record(givenActivity({ message: 'one' }))
activityLog.record(givenActivity({ message: 'two' }))
assert.deepStrictEqual(activityLog.getAllEntries().map(it => pickProps(it, 'id', 'message')), [
{ id: '1', message: 'one' },
{ id: '2', message: 'two' }
])
const [first, second] = activityLog.getAllEntries()
assert(first.id !== second.id, `Expected unique ids. Got the same value: ${first.id}`)
})

it('preserves activities across restarts', function () {
new ActivityLog().record(givenActivity({ message: 'first run' }))
const activityLog = new ActivityLog()
activityLog.record(givenActivity({ message: 'second run' }))
assert.deepStrictEqual(activityLog.getAllEntries().map(it => pickProps(it, 'id', 'message')), [
{ id: '1', message: 'first run' },
{ id: '2', message: 'second run' }
assert.deepStrictEqual(activityLog.getAllEntries().map(it => pickProps(it, 'message')), [
{ message: 'first run' },
{ message: 'second run' }
])
})

Expand Down