mirror of
https://github.com/FoxxMD/multi-scrobbler.git
synced 2026-09-03 05:10:00 +03:00
fxi(webscrobbler): Fix test data generation
This commit is contained in:
+2
-2
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user