Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions backend/src/auth-module/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { RegisterDto } from './dto/register.dto';
import { LoginDto } from './dto/login.dto';

@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
describe('AuthController', () => {
let controller: AuthController;

@Post('register')
async register(@Body() registerDto: RegisterDto) {
return this.authService.register(registerDto);
}
const mockAuthService = {};

@Post('login')
@HttpCode(HttpStatus.OK)
async login(@Body() loginDto: LoginDto) {
return this.authService.login(loginDto);
}
}
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [{ provide: AuthService, useValue: mockAuthService }],
}).compile();

controller = module.get<AuthController>(AuthController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
11 changes: 10 additions & 1 deletion backend/src/auth-module/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
import { UsersService } from '../users/users.service';

describe('AuthService', () => {
let service: AuthService;

const mockUsersService = {
findOne: jest.fn(),
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
providers: [
AuthService,
{ provide: UsersService, useValue: mockUsersService },
],
}).compile();

service = module.get<AuthService>(AuthService);
jest.clearAllMocks();
});

it('should be defined', () => {
Expand Down
14 changes: 13 additions & 1 deletion backend/src/auth-module/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { RegisterDto } from './dto/register.dto';
import { UsersService } from '../users/users.service';

@Injectable()
export class AuthService {
constructor(private readonly usersService: UsersService) {}

register(registerDto: RegisterDto) {
throw new Error('Method not implemented.');
}

async validateUser(userId: string) {
try {
return await this.usersService.findOne(userId);
} catch (e) {
if (e instanceof NotFoundException) return null;
throw e;
}
}
}
2 changes: 1 addition & 1 deletion backend/src/auth-module/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get('JWT_SECRET'),
secretOrKey: configService.getOrThrow<string>('JWT_SECRET'),
});
}

Expand Down
12 changes: 9 additions & 3 deletions backend/src/social-link/social-links.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, MaxLength } from 'class-validator';
import { Transform } from 'class-transformer';
import { IsSafeUrl, IsSocialHandle, sanitizeUrl, normalizeHandle } from '../common/social-links.validator';
import { IsSafeUrl, IsSocialHandle, sanitizeUrl, normalizeHandle } from './social-links.validator';

/**
* SocialLinksDto
Expand All @@ -18,7 +18,10 @@ export class SocialLinksDto {
@IsString()
@MaxLength(500)
@IsSafeUrl({ message: 'website_url must be a valid http or https URL' })
@Transform(({ value }) => sanitizeUrl(value))
@Transform(({ value }) => {
const sanitized = sanitizeUrl(value);
return sanitized !== null ? sanitized : value ?? null;
})
websiteUrl?: string | null;

@ApiPropertyOptional({
Expand Down Expand Up @@ -51,6 +54,9 @@ export class SocialLinksDto {
@IsString()
@MaxLength(500)
@IsSafeUrl({ message: 'other_link must be a valid http or https URL' })
@Transform(({ value }) => sanitizeUrl(value))
@Transform(({ value }) => {
const sanitized = sanitizeUrl(value);
return sanitized !== null ? sanitized : value ?? null;
})
otherLink?: string | null;
}
4 changes: 2 additions & 2 deletions backend/src/social-link/social-links.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SocialLinksService } from '../social-links.service';
import { SocialLinksResponseDto } from '../dto/user-profile.dto';
import { SocialLinksService } from './social-links.service';
import { SocialLinksResponseDto } from './user-profile.dto';

describe('SocialLinksService', () => {
let service: SocialLinksService;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/social-link/social-links.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { SocialLinksDto } from '../dto/social-links.dto';
import { SocialLinksResponseDto } from '../dto/user-profile.dto';
import { SocialLinksDto } from './social-links.dto';
import { SocialLinksResponseDto } from './user-profile.dto';

/**
* SocialLinksService
Expand Down
4 changes: 2 additions & 2 deletions backend/src/social-link/social-links.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
IsSocialHandleConstraint,
sanitizeUrl,
normalizeHandle,
} from '../common/social-links.validator';
import { SocialLinksDto } from '../dto/social-links.dto';
} from './social-links.validator';
import { SocialLinksDto } from './social-links.dto';

// ─── IsSafeUrlConstraint ─────────────────────────────────────────────────────

Expand Down