Process seed accounts through analysis pipeline
This commit is contained in:
1 parent
63a4aeace7
commit
d18e36e962
7 files changed
+343
-11
No files matched your search
@@ -245,6 +245,7 @@ interface PipelineHarnessOptions {
|
||||
accountError?: Error;
|
||||
existingMatchRaw?: Record<string, unknown> | null;
|
||||
existingTimeline?: Record<string, unknown>;
|
||||
findOneAccountResult?: Account | null;
|
||||
getMatch?: jest.Mock<Promise<Record<string, unknown>>, [string, string]>;
|
||||
getMatchTimeline?: jest.Mock<
|
||||
Promise<Record<string, unknown>>,
|
||||
@@ -266,6 +267,15 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
|
||||
const updateAccount: UpdateOneMock = jest
|
||||
.fn<ExecQuery<AcknowledgedUpdate>, Parameters<UpdateOneMock>>()
|
||||
.mockReturnValue(execResolved({ acknowledged: true }));
|
||||
const findOneAccount = jest
|
||||
.fn()
|
||||
.mockReturnValue(
|
||||
leanExecResolved(
|
||||
options.findOneAccountResult === undefined
|
||||
? (options.storedAccount ?? createStoredAccount())
|
||||
: options.findOneAccountResult,
|
||||
),
|
||||
);
|
||||
const findOneRiotMatch = jest.fn().mockReturnValue(
|
||||
leanExecResolved(
|
||||
options.existingMatchRaw
|
||||
@@ -288,6 +298,7 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
|
||||
|
||||
const models = {
|
||||
account: {
|
||||
findOne: findOneAccount,
|
||||
findOneAndUpdate: findOneAndUpdateAccount,
|
||||
updateOne: updateAccount,
|
||||
},
|
||||
@@ -327,6 +338,9 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
|
||||
jest
|
||||
.fn<Promise<Record<string, unknown>>, [string, string]>()
|
||||
.mockResolvedValue(createTimelinePayload());
|
||||
const getMatchIds = jest
|
||||
.fn<Promise<string[]>, [string, Record<string, unknown>]>()
|
||||
.mockResolvedValue(options.matchIds ?? ['KR_1']);
|
||||
const riotApiClient = {
|
||||
getAccountByRiotId,
|
||||
getSummonerByPuuid: jest.fn().mockResolvedValue({
|
||||
@@ -335,13 +349,15 @@ function createPipelineHarness(options: PipelineHarnessOptions = {}) {
|
||||
summonerLevel: 500,
|
||||
}),
|
||||
getLeagueEntriesByPuuid: jest.fn().mockResolvedValue([]),
|
||||
getMatchIds: jest.fn().mockResolvedValue(options.matchIds ?? ['KR_1']),
|
||||
getMatchIds,
|
||||
getMatch,
|
||||
getMatchTimeline,
|
||||
} as unknown as RiotApiClient;
|
||||
|
||||
return {
|
||||
findOneAccount,
|
||||
findOneRiotMatch,
|
||||
getMatchIds,
|
||||
getMatch,
|
||||
getMatchTimeline,
|
||||
service: new AnalysisPipelineService(
|
||||
@@ -523,6 +539,97 @@ describe('AnalysisPipelineService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('processes a stored seed account through the shared match feature pipeline', async () => {
|
||||
const {
|
||||
findOneAccount,
|
||||
getMatchIds,
|
||||
service,
|
||||
updateAnalysisJob,
|
||||
updatePlayerMatchFeature,
|
||||
updatePlayerProfile,
|
||||
} = createPipelineHarness({
|
||||
findOneAccountResult: createStoredAccount({
|
||||
isSeed: true,
|
||||
puuid: 'target-puuid',
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await service.processSeedAccountPipeline(
|
||||
{
|
||||
puuid: 'target-puuid',
|
||||
platformRoute: 'kr',
|
||||
regionalRoute: 'asia',
|
||||
queueId: 420,
|
||||
requestedMatchCount: 30,
|
||||
},
|
||||
'seed-job-1',
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
puuid: 'target-puuid',
|
||||
fetchedMatches: 1,
|
||||
extractedFeatures: 1,
|
||||
profileBuilt: true,
|
||||
});
|
||||
expect(findOneAccount).toHaveBeenCalledWith({
|
||||
puuid: 'target-puuid',
|
||||
isSeed: true,
|
||||
});
|
||||
expect(getMatchIds).toHaveBeenCalledWith('target-puuid', {
|
||||
count: 30,
|
||||
queue: 420,
|
||||
regionalRoute: 'asia',
|
||||
});
|
||||
expect(updatePlayerMatchFeature).toHaveBeenCalledTimes(1);
|
||||
|
||||
const playerProfileUpdate = updatePlayerProfile.mock.calls[0][1];
|
||||
expect(playerProfileUpdate).toMatchObject({
|
||||
$set: {
|
||||
isSeed: true,
|
||||
puuid: 'target-puuid',
|
||||
queueId: 420,
|
||||
sampleGameCount: 1,
|
||||
},
|
||||
});
|
||||
const seedStageUpdate = updateAnalysisJob.mock.calls.find(
|
||||
([, update]) =>
|
||||
asRecord(asRecord(update).$set).jobType === 'seed-collection' &&
|
||||
asRecord(asRecord(update).$set).stage === 'extract-features',
|
||||
);
|
||||
expect(seedStageUpdate).toBeDefined();
|
||||
});
|
||||
|
||||
it('skips seed pipeline processing when the seed account is missing', async () => {
|
||||
const { findOneAccount, getMatchIds, service, updatePlayerProfile } =
|
||||
createPipelineHarness({
|
||||
findOneAccountResult: null,
|
||||
});
|
||||
|
||||
const result = await service.processSeedAccountPipeline(
|
||||
{
|
||||
puuid: 'missing-puuid',
|
||||
platformRoute: 'kr',
|
||||
regionalRoute: 'asia',
|
||||
queueId: 420,
|
||||
requestedMatchCount: 30,
|
||||
},
|
||||
'seed-job-1',
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
puuid: 'missing-puuid',
|
||||
fetchedMatches: 0,
|
||||
extractedFeatures: 0,
|
||||
profileBuilt: false,
|
||||
});
|
||||
expect(findOneAccount).toHaveBeenCalledWith({
|
||||
puuid: 'missing-puuid',
|
||||
isSeed: true,
|
||||
});
|
||||
expect(getMatchIds).not.toHaveBeenCalled();
|
||||
expect(updatePlayerProfile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('completes without building a profile when no ranked matches are returned', async () => {
|
||||
const { service, updateAnalysisJob, updatePlayerProfile } =
|
||||
createPipelineHarness({
|
||||
|
||||
Reference in new issue
Block a user