mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-04 22:06:06 +02:00
feat: add Exclude home world for activity tab
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
execute: vi.fn()
|
||||
}));
|
||||
|
||||
vi.mock('../../sqlite.js', () => ({
|
||||
default: {
|
||||
execute: mocks.execute,
|
||||
executeNonQuery: vi.fn()
|
||||
}
|
||||
}));
|
||||
vi.mock('../index.js', () => ({
|
||||
dbVars: {
|
||||
maxTableSize: 500,
|
||||
userPrefix: ''
|
||||
}
|
||||
}));
|
||||
|
||||
import { gameLog } from '../gameLog.js';
|
||||
|
||||
describe('gameLog.getMyTopWorlds', () => {
|
||||
beforeEach(() => {
|
||||
mocks.execute.mockReset();
|
||||
});
|
||||
|
||||
test('adds an exclude clause when a home world id is provided', async () => {
|
||||
mocks.execute.mockImplementation(async (callback, sql, params) => {
|
||||
callback(['wrld_1', 'World One', 3, 9000]);
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const result = await gameLog.getMyTopWorlds(30, 5, 'time', 'wrld_home');
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
worldId: 'wrld_1',
|
||||
worldName: 'World One',
|
||||
visitCount: 3,
|
||||
totalTime: 9000
|
||||
}
|
||||
]);
|
||||
expect(mocks.execute).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.execute.mock.calls[0][1]).toContain('AND world_id != @excludeWorldId');
|
||||
expect(mocks.execute.mock.calls[0][2]).toMatchObject({
|
||||
'@limit': 5,
|
||||
'@daysOffset': '-30 days',
|
||||
'@excludeWorldId': 'wrld_home'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1449,18 +1449,23 @@ const gameLog = {
|
||||
* @param {number} [days] - Number of days to look back. Omit or 0 for all time.
|
||||
* @param {number} [limit=5] - Maximum number of worlds to return.
|
||||
* @param {'time'|'count'} [sortBy='time'] - Sort by total time or visit count.
|
||||
* @param {string} [excludeWorldId=''] - Optional world ID to exclude from results.
|
||||
* @returns {Promise<Array<{worldId: string, worldName: string, visitCount: number, totalTime: number}>>}
|
||||
*/
|
||||
async getMyTopWorlds(days = 0, limit = 5, sortBy = 'time') {
|
||||
async getMyTopWorlds(days = 0, limit = 5, sortBy = 'time', excludeWorldId = '') {
|
||||
const results = [];
|
||||
const whereClause =
|
||||
days > 0 ? `AND created_at >= datetime('now', @daysOffset)` : '';
|
||||
const excludeClause = excludeWorldId ? 'AND world_id != @excludeWorldId' : '';
|
||||
const orderBy =
|
||||
sortBy === 'count' ? 'visit_count DESC' : 'total_time DESC';
|
||||
const params = { '@limit': limit };
|
||||
if (days > 0) {
|
||||
params['@daysOffset'] = `-${days} days`;
|
||||
}
|
||||
if (excludeWorldId) {
|
||||
params['@excludeWorldId'] = excludeWorldId;
|
||||
}
|
||||
await sqliteService.execute(
|
||||
(dbRow) => {
|
||||
results.push({
|
||||
@@ -1480,6 +1485,7 @@ const gameLog = {
|
||||
AND world_id != ''
|
||||
AND world_id LIKE 'wrld_%'
|
||||
${whereClause}
|
||||
${excludeClause}
|
||||
GROUP BY world_id
|
||||
ORDER BY ${orderBy}
|
||||
LIMIT @limit`,
|
||||
|
||||
Reference in New Issue
Block a user