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
18 changes: 16 additions & 2 deletions backend/src/modules/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,23 @@ export class UsersService {
}

async getById(id: number): Promise<UserDto> {
const user = await this.prisma.user.findUnique({ where: { id } });
const [user, socials] = await Promise.all([
this.prisma.user.findUnique({ where: { id } }),
this.prisma.application.findUnique({
where: { userId: id },
select: {
linkedin: true,
twitter: true,
facebook: true,
github: true,
portfolio: true,
telegram: true,
whatsapp: true,
},
}),
]);
if (!user) throw new NotFoundException('User not found.');
return toUserDto(user);
return toUserDto(user, socials);
}

async recordPayment(id: number, dto: RecordPaymentDto): Promise<PaymentDto> {
Expand Down
38 changes: 38 additions & 0 deletions backend/test/unit/modules/users/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('UsersService', () => {
update: jest.Mock;
count: jest.Mock;
};
application: { findUnique: jest.Mock };
payment: { create: jest.Mock };
};
let mail: { send: jest.Mock };
Expand All @@ -52,6 +53,7 @@ describe('UsersService', () => {
update: jest.fn(),
count: jest.fn(),
},
application: { findUnique: jest.fn().mockResolvedValue(null) },
payment: { create: jest.fn() },
};
mail = { send: jest.fn().mockResolvedValue(undefined) };
Expand Down Expand Up @@ -79,6 +81,42 @@ describe('UsersService', () => {
const dto = await service.getById(1);
expect(dto.id).toBe(1);
});

it('includes social profile fields from the application record', async () => {
prisma.user.findUnique.mockResolvedValue(makeUser());
prisma.application.findUnique.mockResolvedValue({
linkedin: 'https://linkedin.com/in/ada',
twitter: 'https://x.com/ada',
facebook: 'https://facebook.com/ada',
github: 'https://github.com/ada',
portfolio: 'https://ada.dev',
telegram: '@ada',
whatsapp: '+14155552671',
});

const dto = await service.getById(1);

expect(dto.linkedin).toBe('https://linkedin.com/in/ada');
expect(dto.twitter).toBe('https://x.com/ada');
expect(dto.facebook).toBe('https://facebook.com/ada');
expect(dto.github).toBe('https://github.com/ada');
expect(dto.portfolio).toBe('https://ada.dev');
expect(dto.telegram).toBe('@ada');
expect(dto.whatsapp).toBe('+14155552671');
expect(prisma.application.findUnique).toHaveBeenCalledWith(
expect.objectContaining({ where: { userId: 1 } }),
);
});

it('defaults social fields to null when no application exists', async () => {
prisma.user.findUnique.mockResolvedValue(makeUser());
prisma.application.findUnique.mockResolvedValue(null);

const dto = await service.getById(1);

expect(dto.linkedin).toBeNull();
expect(dto.whatsapp).toBeNull();
});
});

describe('recordPayment', () => {
Expand Down
Loading