UNPKG

@sync-in/server

Version:

The secure, open-source platform for file storage, sharing, collaboration, and sync

65 lines (64 loc) 2.65 kB
/* * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com> * This file is part of Sync-in | The open source file sync and share solution * See the LICENSE file for licensing details */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _tsjest = require("@golevelup/ts-jest"); const _config = require("@nestjs/config"); const _passport = require("@nestjs/passport"); const _testing = require("@nestjs/testing"); const _nestjspino = require("nestjs-pino"); const _usersmanagerservice = require("../../applications/users/services/users-manager.service"); const _configenvironment = require("../../configuration/config.environment"); const _authanonymousguard = require("./auth-anonymous.guard"); const _authanonymousstrategy = require("./auth-anonymous.strategy"); describe(_authanonymousguard.AuthAnonymousGuard.name, ()=>{ let authAnonymousGuard; let authAnonymousStrategy; let context; beforeAll(async ()=>{ const module = await _testing.Test.createTestingModule({ imports: [ await _config.ConfigModule.forRoot({ load: [ _configenvironment.exportConfiguration ], isGlobal: true }), _passport.PassportModule ], providers: [ _authanonymousguard.AuthAnonymousGuard, _authanonymousstrategy.AuthAnonymousStrategy, { provide: _usersmanagerservice.UsersManager, useValue: {} }, { provide: _nestjspino.PinoLogger, useValue: { assign: ()=>undefined } } ] }).compile(); authAnonymousStrategy = module.get(_authanonymousstrategy.AuthAnonymousStrategy); authAnonymousGuard = module.get(_authanonymousguard.AuthAnonymousGuard); }); it('should be defined', ()=>{ expect(authAnonymousGuard).toBeDefined(); expect(authAnonymousStrategy).toBeDefined(); }); it('should pass without a valid auth', async ()=>{ context = (0, _tsjest.createMock)(); const spyAuthenticate = jest.spyOn(authAnonymousStrategy, 'authenticate'); context.switchToHttp().getRequest.mockReturnValue({}); expect(await authAnonymousGuard.canActivate(context)).toBe(true); expect(spyAuthenticate).toHaveBeenCalledTimes(1); spyAuthenticate.mockClear(); }); }); //# sourceMappingURL=auth-anonymous.guard.spec.js.map