Hey, I'm trying to write unit tests for my controller but I don't want to use my real databse since I don't want the test to modify it. I have an in memory repository to handle those fake db operations but I don't know how to actually use it on the controller tests:
describe('UserController', () => {
let userController: UserController;
let repository: InMemoryUserRepository;
beforeEach(async () => {
const user: TestingModule = await Test.createTestingModule({
controllers: [UserController],
providers: [UserService, PrismaUsersRepository],
})
.overrideProvider(PrismaUsersRepository)
.useClass(InMemoryUserRepository)
.compile();
userController = user.get<UserController>(UserController);
repository = new InMemoryUserRepository();
});
describe('root', () => {
it('should return all users', async () => {
const data = new UserBuilder().makeSimpleUser();
repository.create(data);
const { users } = await userController.findUsers('1');
expect(users).toHaveLength(1);
});
});
});