Skip to content

Commit

Permalink
incoming affiliation now normalized before trying to detect duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcaprice committed Aug 14, 2024
1 parent 578493b commit 9de74ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@ public List<Assertion> findAssertionsByEmail(String email) {
}

public boolean isDuplicate(Assertion assertion, String salesforceId) {
Assertion normalized = assertionNormalizer.normalize(assertion);
List<Assertion> assertions = assertionRepository.findByEmailAndSalesforceId(assertion.getEmail(), salesforceId);
for (Assertion a : assertions) {
if (duplicates(a, assertion)) {
if (duplicates(a, normalized)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ void testIsDuplicate() {
a.setUrl("something-different");
assertFalse(assertionService.isDuplicate(comparison, DEFAULT_SALESFORCE_ID));


a.setUrl(null);
assertFalse(assertionService.isDuplicate(comparison, DEFAULT_SALESFORCE_ID));

Expand Down Expand Up @@ -1319,6 +1320,7 @@ void testIsDuplicate() {

comparison.setId("not-null"); // id should be ignored
assertTrue(assertionService.isDuplicate(comparison, DEFAULT_SALESFORCE_ID));
verify(assertionNormalizer, Mockito.times(49)).normalize(Mockito.any(Assertion.class)); // check normalization was used
}

@Test
Expand Down Expand Up @@ -1722,10 +1724,10 @@ void testUpdateAssertionsSalesforceId() {
void testUpdateAssertionsSalesforceIdWithFailure() {
List<Assertion> firstPage = getAssertionsForSalesforceId("salesforce-id", 0, AssertionService.REGISTRY_SYNC_BATCH_SIZE);
Mockito.when(assertionRepository.findBySalesforceId(Mockito.eq("salesforce-id"), Mockito.any(Pageable.class))).thenReturn(new PageImpl<Assertion>(firstPage));

// representing updated assertions that need to be rolled back
Mockito.when(assertionRepository.findBySalesforceId(Mockito.eq("new-salesforce-id"), Mockito.any(Pageable.class)))
.thenReturn(new PageImpl<Assertion>(Arrays.asList(new Assertion(), new Assertion(), new Assertion()))).thenReturn(new PageImpl<Assertion>(new ArrayList<>()));
.thenReturn(new PageImpl<Assertion>(Arrays.asList(new Assertion(), new Assertion(), new Assertion()))).thenReturn(new PageImpl<Assertion>(new ArrayList<>()));

// 3 successful updates before error, followed by rollback
Mockito.when(assertionRepository.save(Mockito.any(Assertion.class))).thenReturn(new Assertion()).thenReturn(new Assertion()).thenReturn(new Assertion())
Expand All @@ -1734,8 +1736,8 @@ void testUpdateAssertionsSalesforceIdWithFailure() {
boolean success = assertionService.updateAssertionsSalesforceId("salesforce-id", "new-salesforce-id");
assertThat(success).isFalse();

// 3 updates followed by 1 failure and 3 rollbacks
Mockito.verify(assertionRepository, Mockito.times(7)).save(assertionCaptor.capture());
// 3 updates followed by 1 failure and 3 rollbacks
Mockito.verify(assertionRepository, Mockito.times(7)).save(assertionCaptor.capture());
List<Assertion> saved = assertionCaptor.getAllValues();
assertThat(saved.get(0).getSalesforceId()).isEqualTo("new-salesforce-id");
assertThat(saved.get(1).getSalesforceId()).isEqualTo("new-salesforce-id");
Expand All @@ -1745,7 +1747,7 @@ void testUpdateAssertionsSalesforceIdWithFailure() {
assertThat(saved.get(5).getSalesforceId()).isEqualTo("salesforce-id");
assertThat(saved.get(6).getSalesforceId()).isEqualTo("salesforce-id");
}

private List<MemberAssertionStatusCount> getDummyAssertionStatusCounts() {
List<MemberAssertionStatusCount> counts = new ArrayList<>();
counts.add(new MemberAssertionStatusCount("salesforceId1", "PENDING", 4));
Expand Down

0 comments on commit 9de74ed

Please sign in to comment.