@Test void savesReferralAndCreatesBounty() { Principal referee = () -> "davyvanroy"; CreateRefCommand command = CreateRefCommand.builder().principal(referee).ref("referrer").build(); when(keycloakRepository.userExists(referee.getName())).thenReturn(true); when(keycloakRepository.userExists(command.getRef())).thenReturn(true); when(referralRepository.existsByReferee(referee.getName())).thenReturn(false); when(keycloakRepository.isVerifiedDeveloper(referee.getName())).thenReturn(true); referralService.createNewRef(command); verify(referralRepository, times(2)).save(Referral.builder() .referrer(command.getRef()) .referee(referee.getName()) .status(ReferralStatus.PENDING) .build()); verify(bountyService).createBounty(CreateBountyCommand.builder() .type(BountyType.REFERRAL) .userId(command.getRef()) .build()); }
@Override @Transactional public void createNewRef(CreateRefCommand command) { String referrer = command.getRef(); String referee = command.getPrincipal().getName(); validReferral(referrer, referee); if (!repository.existsByReferee(referee)) { Referral referral = Referral.builder() .referrer(referrer) .referee(referee) .status(ReferralStatus.PENDING) .build(); repository.save(referral); sendBountyIfPossible(referral); } else { throw new RuntimeException("This ref already exists!"); } }
ReferralServiceImpl implements ReferralService { @Override @Transactional public void createNewRef(CreateRefCommand command) { String referrer = command.getRef(); String referee = command.getPrincipal().getName(); validReferral(referrer, referee); if (!repository.existsByReferee(referee)) { Referral referral = Referral.builder() .referrer(referrer) .referee(referee) .status(ReferralStatus.PENDING) .build(); repository.save(referral); sendBountyIfPossible(referral); } else { throw new RuntimeException("This ref already exists!"); } } }
ReferralServiceImpl implements ReferralService { @Override @Transactional public void createNewRef(CreateRefCommand command) { String referrer = command.getRef(); String referee = command.getPrincipal().getName(); validReferral(referrer, referee); if (!repository.existsByReferee(referee)) { Referral referral = Referral.builder() .referrer(referrer) .referee(referee) .status(ReferralStatus.PENDING) .build(); repository.save(referral); sendBountyIfPossible(referral); } else { throw new RuntimeException("This ref already exists!"); } } ReferralServiceImpl(ReferralRepository repository,
                               KeycloakRepository keycloakRepository,
                               BountyService bountyService); }
ReferralServiceImpl implements ReferralService { @Override @Transactional public void createNewRef(CreateRefCommand command) { String referrer = command.getRef(); String referee = command.getPrincipal().getName(); validReferral(referrer, referee); if (!repository.existsByReferee(referee)) { Referral referral = Referral.builder() .referrer(referrer) .referee(referee) .status(ReferralStatus.PENDING) .build(); repository.save(referral); sendBountyIfPossible(referral); } else { throw new RuntimeException("This ref already exists!"); } } ReferralServiceImpl(ReferralRepository repository,
                               KeycloakRepository keycloakRepository,
                               BountyService bountyService); @EventListener @Transactional void onProviderLinked(UserLinkedProviderEvent event); @Transactional(readOnly = true) @Override ReferralOverviewDto getOverview(Principal principal); @Override @Cacheable("ref_links") String generateRefLink(String userId, String source); @Transactional(readOnly = true) @Override List<ReferralDto> getReferrals(Principal principal); @Override @Transactional void createNewRef(CreateRefCommand command); }
ReferralServiceImpl implements ReferralService { @Override @Transactional public void createNewRef(CreateRefCommand command) { String referrer = command.getRef(); String referee = command.getPrincipal().getName(); validReferral(referrer, referee); if (!repository.existsByReferee(referee)) { Referral referral = Referral.builder() .referrer(referrer) .referee(referee) .status(ReferralStatus.PENDING) .build(); repository.save(referral); sendBountyIfPossible(referral); } else { throw new RuntimeException("This ref already exists!"); } } ReferralServiceImpl(ReferralRepository repository,
                               KeycloakRepository keycloakRepository,
                               BountyService bountyService); @EventListener @Transactional void onProviderLinked(UserLinkedProviderEvent event); @Transactional(readOnly = true) @Override ReferralOverviewDto getOverview(Principal principal); @Override @Cacheable("ref_links") String generateRefLink(String userId, String source); @Transactional(readOnly = true) @Override List<ReferralDto> getReferrals(Principal principal); @Override @Transactional void createNewRef(CreateRefCommand command);  }