chore: ingest source code

58 files from https://github.com/gothinkster/node-express-realworld-example-app
This commit is contained in:
2026-03-13 11:38:49 +00:00
commit 1d0b844e76
58 changed files with 12898 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
import prismaMock from '../prisma-mock';
import { followUser, getProfile, unfollowUser } from '../../app/routes/profile/profile.service';
describe('ProfileService', () => {
describe('getProfile', () => {
test('should return a following property', async () => {
// Given
const username = 'RealWorld';
const id = 123;
const mockedResponse = {
id: 123,
username: 'RealWorld',
email: 'realworld@me',
password: '1234',
bio: null,
image: null,
token: '',
demo: false,
followedBy: [],
};
// When
// @ts-ignore
prismaMock.user.findUnique.mockResolvedValue(mockedResponse);
// Then
await expect(getProfile(username, id)).resolves.toHaveProperty('following');
});
test('should throw an error if no user is found', async () => {
// Given
const username = 'RealWorld';
const id = 123;
// When
prismaMock.user.findUnique.mockResolvedValue(null);
// Then
await expect(getProfile(username, id)).rejects.toThrowError();
});
});
describe('followUser', () => {
test('shoud return a following property', async () => {
// Given
const usernamePayload = 'AnotherUser';
const id = 123;
const mockedAuthUser = {
id: 123,
username: 'RealWorld',
email: 'realworld@me',
password: '1234',
bio: null,
image: null,
token: '',
demo: false,
followedBy: [],
};
const mockedResponse = {
id: 123,
username: 'AnotherUser',
email: 'another@me',
password: '1234',
bio: null,
image: null,
token: '',
demo: false,
followedBy: [],
};
// When
prismaMock.user.findUnique.mockResolvedValue(mockedAuthUser);
prismaMock.user.update.mockResolvedValue(mockedResponse);
// Then
await expect(followUser(usernamePayload, id)).resolves.toHaveProperty('following');
});
test('shoud throw an error if no user is found', async () => {
// Given
const usernamePayload = 'AnotherUser';
const id = 123;
// When
prismaMock.user.findUnique.mockResolvedValue(null);
// Then
await expect(followUser(usernamePayload, id)).rejects.toThrowError();
});
});
describe('unfollowUser', () => {
test('shoud return a following property', async () => {
// Given
const usernamePayload = 'AnotherUser';
const id = 123;
const mockedAuthUser = {
id: 123,
username: 'RealWorld',
email: 'realworld@me',
password: '1234',
bio: null,
image: null,
token: '',
demo: false,
followedBy: [],
};
const mockedResponse = {
id: 123,
username: 'AnotherUser',
email: 'another@me',
password: '1234',
bio: null,
image: null,
token: '',
demo: false,
followedBy: [],
};
// When
prismaMock.user.findUnique.mockResolvedValue(mockedAuthUser);
prismaMock.user.update.mockResolvedValue(mockedResponse);
// Then
await expect(unfollowUser(usernamePayload, id)).resolves.toHaveProperty('following');
});
test('shoud throw an error if no user is found', async () => {
// Given
const usernamePayload = 'AnotherUser';
const id = 123;
// When
prismaMock.user.findUnique.mockResolvedValue(null);
// Then
await expect(unfollowUser(usernamePayload, id)).rejects.toThrowError();
});
});
});