mirror of https://github.com/ghostfolio/ghostfolio
7 changed files with 127 additions and 36 deletions
@ -1,13 +1,28 @@ |
|||
import { Filter } from '@ghostfolio/common/interfaces'; |
|||
|
|||
import { Milliseconds } from 'cache-manager'; |
|||
|
|||
export const RedisCacheServiceMock = { |
|||
cache: new Map<string, string>(), |
|||
get: (key: string): Promise<string> => { |
|||
return Promise.resolve(null); |
|||
const value = RedisCacheServiceMock.cache.get(key) || null; |
|||
|
|||
return Promise.resolve(value); |
|||
}, |
|||
getPortfolioSnapshotKey: (userId: string): string => { |
|||
return `portfolio-snapshot-${userId}`; |
|||
getPortfolioSnapshotKey: ({ |
|||
filters, |
|||
userId |
|||
}: { |
|||
filters?: Filter[]; |
|||
userId: string; |
|||
}): string => { |
|||
const filtersHash = filters?.length; |
|||
|
|||
return `portfolio-snapshot-${userId}-${filtersHash}`; |
|||
}, |
|||
set: (key: string, value: string, ttl?: Milliseconds): Promise<string> => { |
|||
RedisCacheServiceMock.cache.set(key, value); |
|||
|
|||
return Promise.resolve(value); |
|||
} |
|||
}; |
|||
|
@ -1,3 +1,6 @@ |
|||
import { Filter } from '@ghostfolio/common/interfaces'; |
|||
|
|||
export interface IPortfolioSnapshotQueueJob { |
|||
filters: Filter[]; |
|||
userId: string; |
|||
} |
|||
|
@ -0,0 +1,28 @@ |
|||
import * as Bull from 'bull'; |
|||
import { setTimeout } from 'timers/promises'; |
|||
|
|||
import { IPortfolioSnapshotQueueJob } from './interfaces/portfolio-snapshot-queue-job.interface'; |
|||
|
|||
export const PortfolioSnapshotServiceMock = { |
|||
addJobToQueue({ |
|||
data, |
|||
name, |
|||
opts |
|||
}: { |
|||
data: IPortfolioSnapshotQueueJob; |
|||
name: string; |
|||
opts?: Bull.JobOptions; |
|||
}): Promise<Bull.Job<any>> { |
|||
// Mock the Job object with a finished method
|
|||
const mockJob: Partial<Bull.Job<any>> = { |
|||
// Mock the finished method to return a resolved promise
|
|||
finished: async () => { |
|||
await setTimeout(100); |
|||
|
|||
return Promise.resolve('Mocked job finished result'); |
|||
} |
|||
}; |
|||
|
|||
return Promise.resolve(mockJob as Bull.Job<any>); |
|||
} |
|||
}; |
Loading…
Reference in new issue