release/86 #2
No files matched your search
@@ -206,7 +206,7 @@ describe('MatchStatsService', () => {
|
|||||||
{ getMatchTimeline: jest.fn() } as never,
|
{ getMatchTimeline: jest.fn() } as never,
|
||||||
);
|
);
|
||||||
|
|
||||||
await service.buildAndUpsert(matchId);
|
await service.buildAndUpsert(matchId, { sourceRevision: 12 });
|
||||||
|
|
||||||
expect(riotFind).toHaveBeenCalledWith({
|
expect(riotFind).toHaveBeenCalledWith({
|
||||||
matchId: { $in: ['KR_COMPETITION'] },
|
matchId: { $in: ['KR_COMPETITION'] },
|
||||||
@@ -236,6 +236,54 @@ describe('MatchStatsService', () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not rebuild before the requested Competition revision is visible', async () => {
|
||||||
|
const matchId = new mongoose.Types.ObjectId();
|
||||||
|
const riotFind = jest.fn();
|
||||||
|
const connectionService = {
|
||||||
|
getModel: jest.fn().mockImplementation(async (name: string) => {
|
||||||
|
if (name === 'match') {
|
||||||
|
return {
|
||||||
|
findById: () =>
|
||||||
|
queryResult(
|
||||||
|
{
|
||||||
|
_id: matchId,
|
||||||
|
status: 'in-progress',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (name === 'competition') {
|
||||||
|
return {
|
||||||
|
findOne: () => queryResult({ revision: 11 }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (name === 'riotMatch') return { find: riotFind };
|
||||||
|
throw new Error(`Unexpected model: ${name}`);
|
||||||
|
}),
|
||||||
|
} as unknown as ConnectionService;
|
||||||
|
const repository = {
|
||||||
|
upsert: jest.fn(),
|
||||||
|
deleteByMatch: jest.fn(),
|
||||||
|
} as unknown as jest.Mocked<MatchStatsRepository>;
|
||||||
|
const builder = {
|
||||||
|
buildFragment: jest.fn(),
|
||||||
|
} as unknown as jest.Mocked<MatchStatsFragmentBuilder>;
|
||||||
|
const service = new MatchStatsService(
|
||||||
|
connectionService,
|
||||||
|
repository,
|
||||||
|
builder,
|
||||||
|
{ getMatchTimeline: jest.fn() } as never,
|
||||||
|
);
|
||||||
|
|
||||||
|
await service.buildAndUpsert(matchId, { sourceRevision: 12 });
|
||||||
|
|
||||||
|
expect(riotFind).not.toHaveBeenCalled();
|
||||||
|
expect(builder.buildFragment).not.toHaveBeenCalled();
|
||||||
|
expect(repository.upsert).not.toHaveBeenCalled();
|
||||||
|
expect(repository.deleteByMatch).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function participant(
|
function participant(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class MatchStatsService {
|
|||||||
|
|
||||||
public async buildAndUpsert(
|
public async buildAndUpsert(
|
||||||
matchId: mongoose.Types.ObjectId,
|
matchId: mongoose.Types.ObjectId,
|
||||||
options: { includeTimeline?: boolean } = {},
|
options: { includeTimeline?: boolean; sourceRevision?: number } = {},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const MatchModel = await this.connectionService.getModel('match');
|
const MatchModel = await this.connectionService.getModel('match');
|
||||||
const CompetitionModel =
|
const CompetitionModel =
|
||||||
@@ -37,6 +37,12 @@ export class MatchStatsService {
|
|||||||
const competition = await CompetitionModel.findOne({ matchId })
|
const competition = await CompetitionModel.findOne({ matchId })
|
||||||
.lean()
|
.lean()
|
||||||
.exec();
|
.exec();
|
||||||
|
if (
|
||||||
|
options.sourceRevision !== undefined &&
|
||||||
|
(!competition || competition.revision < options.sourceRevision)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const competitionSource = competition
|
const competitionSource = competition
|
||||||
? competitionStatsSource(match, competition)
|
? competitionStatsSource(match, competition)
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -148,7 +154,10 @@ export class MatchStatsService {
|
|||||||
const matches = await MatchModel.find({
|
const matches = await MatchModel.find({
|
||||||
communityId,
|
communityId,
|
||||||
status: { $in: ['finished', 'in-progress'] },
|
status: { $in: ['finished', 'in-progress'] },
|
||||||
'result.games.0': { $exists: true },
|
$or: [
|
||||||
|
{ competitionId: { $exists: true } },
|
||||||
|
{ 'result.games.0': { $exists: true } },
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.sort({ scheduledAt: -1 })
|
.sort({ scheduledAt: -1 })
|
||||||
.select({ _id: 1 })
|
.select({ _id: 1 })
|
||||||
|
|||||||
Reference in new issue
Block a user