Preserve tournament result jobs through lock contention and transient failures, atomically schedule retries before acknowledgement, and publish initial polls after releasing the preparation lock. Fix Redis connection blocking, durability Hash cleanup, duplicate auction request ordering, and scheduled-job promotion. Use native Redis 8.10 stream, lock, counter, and field-expiring cache operations with invalidation fencing. Repair 90 test type errors and add a repeatable API typecheck command. Validation: 704 API tests, 129 web tests, 31 real Redis integration tests, 3 dependency checks, workspace type checks and builds, and changed-file lint.
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { ExecutionContext } from '@nestjs/common';
|
|
import mongoose from 'mongoose';
|
|
import { ConnectionService } from '../global/database/connection.service';
|
|
import { IdentityDocument, UserDocument } from '../global/database/schema';
|
|
import { UserResolverGuard } from './user-resolver.guard';
|
|
import './auth-request';
|
|
import type { Request } from 'express';
|
|
|
|
function createContext(request: Record<string, unknown>): ExecutionContext {
|
|
return {
|
|
switchToHttp: () => ({
|
|
getRequest: () => request,
|
|
}),
|
|
} as ExecutionContext;
|
|
}
|
|
|
|
describe('UserResolverGuard', () => {
|
|
it('resolves the community membership before role guards run', async () => {
|
|
const communityId = new mongoose.Types.ObjectId();
|
|
const identityId = new mongoose.Types.ObjectId();
|
|
const user = { _id: new mongoose.Types.ObjectId() } as UserDocument;
|
|
const findOne = jest.fn().mockReturnValue({
|
|
exec: jest.fn().mockResolvedValue(user),
|
|
});
|
|
const connectionService = {
|
|
getModel: jest.fn().mockResolvedValue({ findOne }),
|
|
} as unknown as ConnectionService;
|
|
const request: Pick<Request, 'params' | 'identity' | 'user'> = {
|
|
params: { communityId: communityId.toString() },
|
|
identity: { _id: identityId } as IdentityDocument,
|
|
};
|
|
const guard = new UserResolverGuard(connectionService);
|
|
|
|
await expect(guard.canActivate(createContext(request))).resolves.toBe(true);
|
|
|
|
expect(findOne).toHaveBeenCalledWith({
|
|
communityId,
|
|
identityId,
|
|
});
|
|
expect(request.user).toBe(user);
|
|
});
|
|
|
|
it('skips lookup when there is no resolved identity', async () => {
|
|
const connectionService = {
|
|
getModel: jest.fn(),
|
|
} as unknown as ConnectionService;
|
|
const request = {
|
|
params: { communityId: new mongoose.Types.ObjectId().toString() },
|
|
};
|
|
const guard = new UserResolverGuard(connectionService);
|
|
|
|
await expect(guard.canActivate(createContext(request))).resolves.toBe(true);
|
|
|
|
expect(connectionService.getModel).not.toHaveBeenCalled();
|
|
});
|
|
});
|