This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { UserDTO } from '@shared/dto/user.dto'; | |
import axios, { AxiosInstance } from 'axios'; | |
class BackendClient { | |
private instance: AxiosInstance; | |
constructor() { | |
this.instance = axios.create({ | |
baseURL: process.env.BACKEND_API_URL, | |
headers: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { UserDTOFactory } from '@shared/factories/User.dto.factory'; | |
import { render } from '@testing-library/react'; | |
import UserProfile from '@frontend/pages/user-profile'; | |
describe('UserProfile', () => { | |
it('matches snapshot', () => { | |
const user = UserDTOFactory.fixtureSync( | |
__dirname + '/UserProfile.spec.json', | |
) | |
const { container } = render(<UserProfile user={user} /> ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const UserDTOFactory = new FixtureFactory<UserDTO>(() => { | |
const { profile, ...user } = UserFactory.buildSync(); | |
return { | |
...user, | |
...profile, | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as faker from 'faker'; | |
import { FixtureFactory } from 'interface-forge'; | |
import { UserDTO } from '@shared/dto/User.dto'; | |
export const UserDTOFactory = new FixtureFactory<UserDTO>(() => ({ | |
id: faker.datatype.uuid(), | |
firstName: faker.name.firstName(), | |
lastName: faker.name.lastName(), | |
isActive: true, | |
email: faker.internet.email(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class UserDTO { | |
id: string; | |
firstName: string; | |
lastName: string; | |
email: string; | |
isActive: boolean; | |
location: string; | |
employer: string; | |
profession: string; | |
phoneNumber: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const UserFactory = new TypeFactory< | |
EntityInterface<User, AbstractUUIDPrimaryKeyEntity> | |
>(() => ({ | |
... | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type EntityInterface<Entity, Base> = { | |
[K in keyof Omit<Entity, keyof Base>]: K extends Base | |
? Omit<Entity, keyof Base> | |
: Entity[K]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export abstract class AbstractUUIDPrimaryKeyEntity extends BaseEntity { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@CreateDateColumn() | |
createdDate: Date; | |
@UpdateDateColumn() | |
updatedDate: Date; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { User } from '@backend/db/entities/User'; | |
import { UserFactory } from '@backend/db/factories/User.factory'; | |
import { getConnection } from 'typeorm'; | |
describe('Some Other Test', () => { | |
const connection = getConnection('default'); | |
let users: User[]; | |
beforeEach(async () => { | |
const userRepository = connection.getRepository(User); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { User } from '@backend/db/entities/User'; | |
import { UserFactory } from '@backend/db/factories/User.factory'; | |
import { getConnection } from 'typeorm'; | |
describe('Some Test', () => { | |
const connection = getConnection('default'); | |
let user: User; | |
beforeEach(async () => { | |
const userRepository = connection.getRepository(User); |