test: Setup transient di cache

This commit is contained in:
FoxxMD 2025-08-27 16:52:41 +00:00
parent 78f4767dd2
commit 32e2aa6974
4 changed files with 19 additions and 7 deletions

View file

@ -3,5 +3,8 @@
"extension": "ts",
"import": "tsx/esm",
"spec": "./src/backend/tests/**/*.test.ts",
"file": [
"./src/backend/tests/setup.ts"
],
"exit": true
}

View file

@ -28,6 +28,11 @@ export class TestScrobbler extends AbstractScrobbleClient {
return (await this.existingScrobble(playObj)) !== undefined;
}
protected async doParseCache() {
await this.cache.init();
return super.doParseCache();
}
playToClientPayload(playObject: PlayObject): object {

View file

@ -8,16 +8,14 @@ import { http, HttpResponse } from 'msw';
import pEvent from 'p-event';
import { PlayObject } from "../../../core/Atomic.js";
import { genGroupIdStr, sleep } from "../../utils.js";
import mixedDuration from '../plays/mixedDuration.json';
import withDuration from '../plays/withDuration.json';
import mixedDuration from '../plays/mixedDuration.json' with { type: 'json' };
import withDuration from '../plays/withDuration.json' with { type: 'json' };
import { MockNetworkError, withRequestInterception } from "../utils/networking.js";
import { asPlays, generatePlay, generatePlayPlatformId, generatePlays, normalizePlays } from "../utils/PlayTestUtils.js";
import MockDate from 'mockdate';
import { NowPlayingScrobbler, TestAuthScrobbler, TestScrobbler } from "./TestScrobbler.js";
import { PlayPlatformId } from '../../common/infrastructure/Atomic.js';
import { getRoot } from '../../ioc.js';
import { loggerTest } from '@foxxmd/logging';
chai.use(asPromised);
@ -31,8 +29,6 @@ const normalizedWithMixedDur = normalizePlays(mixedDurPlays, {initialDate: first
const normalizedWithMixedDurOlder = normalizePlays(mixedDurPlays, {initialDate: olderFirstPlayDate});
getRoot({cache: {scrobble: {provider: 'memory'}}, logger: loggerTest});
const generateTestScrobbler = () => {
const testScrobbler = new TestScrobbler();
testScrobbler.verboseOptions = {
@ -665,7 +661,7 @@ describe('Scrobble client uses transform plays correctly', function() {
describe('Manages scrobble queue', function() {
before(async function() {
beforeEach(async function() {
testScrobbler = generateTestScrobbler();
await testScrobbler.initialize();
testScrobbler.recentScrobbles = normalizedWithMixedDur;

View file

@ -0,0 +1,8 @@
import { loggerTest } from '@foxxmd/logging';
import { getRoot } from "../ioc.js";
import { MSCache } from '../common/Cache.js';
const transientCache = () => new MSCache(loggerTest, {scrobble: {provider: 'memory'}});
const root = getRoot({cache: transientCache, logger: loggerTest});
root.items.cache().init();