fxi(webscrobbler): Fix test data generation

This commit is contained in:
FoxxMD
2026-08-25 23:26:11 +00:00
parent 4b8d4932aa
commit 9c84e2d8e3
2 changed files with 24 additions and 18 deletions
+2 -2
View File
@@ -51,7 +51,7 @@ export const metadataSchema = z.looseObject({
notificationId: z.string().optional(),
trackArtUrl: z.string().optional(),
trackUrl: z.string().optional(),
userPlayCount: z.number().optional(),
userPlayCount: z.int().positive().optional(),
userloved: z.boolean().optional(),
});
export type Metadata = z.infer<typeof metadataSchema>;
@@ -64,7 +64,7 @@ export const connectorSchema = z.object({
export type Connector = z.infer<typeof connectorSchema>;
export const webScrobblerSongSchema = z.object({
controllerTabId: z.union([z.string(),z.number()]),
controllerTabId: z.union([z.string(),z.int().positive()]),
connector: connectorSchema,
parsed: parsedSongDataSchema,
processed: processedSongDataSchema,
+22 -16
View File
@@ -161,29 +161,35 @@ describe('Webscrobbler Endpoint', function() {
clients = new ScrobbleClients(new WildcardEmitter(), new WildcardEmitter(), internalConfig, loggerTest);
});
it('accepts request to /api/webscrobbler', async function() {
it('accepts request to /api/webscrobbler', async function () {
const sources = generateSources();
await sources.addSource('webscrobbler', [defaultWebscrobblerConfig]);
const source = sources.sources[0];
source.queueIdleMs = 2;
await source.initialize();
const [app] = await initServer({sources, clients}, {testMode: true});
const [app] = await initServer({ sources, clients }, { testMode: true });
const payload = zocker(webScrobblePayloadSchema)
.override(z.ZodString, faker.word.words({count: {min: 1, max: 5}}))
.supply(webScrobblePayloadSchema.shape.data.shape.currentlyPlaying, true)
.supply(webScrobblePayloadSchema.shape.time, dayjs().unix())
.supply(webScrobblePayloadSchema.shape.data.shape.song.shape.processed.shape.duration, faker.number.int({min: 30, max: 400}))
.supply(webScrobblePayloadSchema.shape.data.shape.song.shape.parsed.shape.duration, faker.number.int({min: 30, max: 400}))
.supply(webScrobblePayloadSchema.shape.eventName, 'scrobble').generate()
.override(z.ZodString,() => faker.word.words({ count: { min: 1, max: 5 } }))
.supply(webScrobblePayloadSchema.shape.data.shape.currentlyPlaying, true)
.supply(webScrobblePayloadSchema.shape.time, dayjs().unix())
.supply(webScrobblePayloadSchema.shape.data.shape.song.shape.processed.shape.duration, faker.number.int({ min: 30, max: 400 }))
.supply(webScrobblePayloadSchema.shape.data.shape.song.shape.parsed.shape.duration, faker.number.int({ min: 30, max: 400 }))
.supply(webScrobblePayloadSchema.shape.data.shape.song.shape.parsed.shape.isScrobblingAllowed, true)
.supply(webScrobblePayloadSchema.shape.eventName, 'scrobble').generate()
const [response, _] = await Promise.all([
request(app).post('/api/webscrobbler')
.set('Content-Type', 'application/json')
.send(JSON.stringify(payload)),
pEvent(source.emitter, 'playInsert', {timeout: 1000})
]);
expect(response.status).eq(200);
expect(source.getApiData().queued, JSON.stringify(payload)).eq(1);
try {
const [response, _] = await Promise.all([
request(app).post('/api/webscrobbler')
.set('Content-Type', 'application/json')
.send(JSON.stringify(payload)),
pEvent(source.emitter, 'playInsert', { timeout: 1000 })
]);
expect(response.status).eq(200);
expect(source.getApiData().queued, JSON.stringify(payload)).eq(1);
} catch (e) {
console.log(JSON.stringify(payload));
throw e;
}
});
});