-
Notifications
You must be signed in to change notification settings - Fork 284
[Hubspot] Add de duplication for assosiations #3336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { mergeAndDeduplicateById, validate, ensureValidTimestamps } from '../functions/validation-functions' | ||
import { | ||
mergeAndDeduplicateById, | ||
validate, | ||
ensureValidTimestamps, | ||
deDuplicateAssociations | ||
} from '../functions/validation-functions' | ||
import { Payload } from '../generated-types' | ||
|
||
const payload: Payload = { | ||
|
@@ -228,3 +233,80 @@ describe('ensureValidTimestamps', () => { | |
expect(ts).not.toBeNaN() | ||
}) | ||
}) | ||
|
||
describe('deDuplicateAssociations', () => { | ||
const createAssociationPayload = (id: string) => ({ | ||
object_details: { | ||
object_type: 'contact', | ||
id_field_name: 'email', | ||
id_field_value: id, | ||
from_record_id: 'from-123' | ||
}, | ||
association_details: { | ||
association_label: 'HUBSPOT_DEFINED:primary' | ||
} | ||
}) | ||
|
||
it('returns empty array when association groups is empty', () => { | ||
expect(deDuplicateAssociations([])).toEqual([]) | ||
}) | ||
|
||
it('returns the same array when associations are unique within groups', () => { | ||
const associationGroup1 = [createAssociationPayload('[email protected]'), createAssociationPayload('[email protected]')] | ||
const associationGroup2 = [createAssociationPayload('[email protected]'), createAssociationPayload('[email protected]')] | ||
|
||
const result = deDuplicateAssociations([associationGroup1, associationGroup2]) | ||
expect(result).toHaveLength(2) | ||
expect(result[0]).toHaveLength(2) | ||
expect(result[1]).toHaveLength(2) | ||
}) | ||
|
||
it('removes duplicate associations within each group', () => { | ||
const assocPayload = createAssociationPayload('[email protected]') | ||
const duplicateGroup = [assocPayload, { ...assocPayload }, { ...assocPayload }] | ||
|
||
const result = deDuplicateAssociations([duplicateGroup]) | ||
expect(result).toHaveLength(1) | ||
expect(result[0]).toHaveLength(1) | ||
expect(result[0][0]).toEqual(assocPayload) | ||
}) | ||
|
||
it('keeps the last occurrence of a duplicate association within a group', () => { | ||
const assoc1 = createAssociationPayload('[email protected]') | ||
const assoc2 = { | ||
...createAssociationPayload('[email protected]'), | ||
object_details: { | ||
...createAssociationPayload('[email protected]').object_details, | ||
extra: 'last' | ||
} | ||
} | ||
|
||
const associationGroup = [assoc1, assoc2] | ||
|
||
const result = deDuplicateAssociations([associationGroup]) | ||
expect(result).toHaveLength(1) | ||
expect(result[0]).toHaveLength(1) | ||
expect(result[0][0]).toEqual(assoc2) | ||
}) | ||
|
||
it('handles multiple groups with different duplicates', () => { | ||
const group1 = [ | ||
createAssociationPayload('[email protected]'), | ||
createAssociationPayload('[email protected]') // duplicate | ||
] | ||
|
||
const group2 = [ | ||
createAssociationPayload('[email protected]'), | ||
createAssociationPayload('[email protected]'), | ||
createAssociationPayload('[email protected]') // duplicate | ||
] | ||
|
||
const result = deDuplicateAssociations([group1, group2]) | ||
expect(result).toHaveLength(2) | ||
expect(result[0]).toHaveLength(1) // deduped to 1 | ||
expect(result[0][0].object_details).toBe(group1[1].object_details) | ||
expect(result[1]).toHaveLength(2) // deduped to 2 | ||
expect(result[1][0].object_details).toBe(group2[0].object_details) | ||
expect(result[1][1].object_details).toBe(group2[2].object_details) | ||
}) | ||
}) |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.