-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement/prevent creation of duplicate member suggestions (#2022)
- Loading branch information
Showing
13 changed files
with
157 additions
and
194 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
backend/src/database/migrations/U1704395824__memberMergeSuggestionsLastGeneratedAt.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alter table "tenants" drop column "memberMergeSuggestionsLastGeneratedAt"; |
2 changes: 2 additions & 0 deletions
2
backend/src/database/migrations/V1704395824__memberMergeSuggestionsLastGeneratedAt.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table "tenants" | ||
add column "memberMergeSuggestionsLastGeneratedAt" timestamp with time zone null; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,97 +24,6 @@ describe('TenantService tests', () => { | |
await SequelizeTestUtils.closeConnection(db) | ||
}) | ||
|
||
describe('findMembersToMerge', () => { | ||
it('Should show the same merge suggestion once, with reverse order', async () => { | ||
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(db) | ||
const memberService = new MemberService(mockIServiceOptions) | ||
const tenantService = new TenantService(mockIServiceOptions) | ||
|
||
const memberToCreate1 = { | ||
username: { | ||
[PlatformType.SLACK]: { | ||
username: 'member 1', | ||
integrationId: generateUUIDv1(), | ||
}, | ||
}, | ||
platform: PlatformType.SLACK, | ||
email: '[email protected]', | ||
joinedAt: '2020-05-27T15:13:30Z', | ||
} | ||
|
||
const memberToCreate2 = { | ||
username: { | ||
[PlatformType.DISCORD]: { | ||
username: 'member 2', | ||
integrationId: generateUUIDv1(), | ||
}, | ||
}, | ||
platform: PlatformType.DISCORD, | ||
email: '[email protected]', | ||
joinedAt: '2020-05-26T15:13:30Z', | ||
} | ||
|
||
const memberToCreate3 = { | ||
username: { | ||
[PlatformType.GITHUB]: { | ||
username: 'member 3', | ||
integrationId: generateUUIDv1(), | ||
}, | ||
}, | ||
platform: PlatformType.GITHUB, | ||
email: '[email protected]', | ||
joinedAt: '2020-05-25T15:13:30Z', | ||
} | ||
|
||
const memberToCreate4 = { | ||
username: { | ||
[PlatformType.TWITTER]: { | ||
username: 'member 4', | ||
integrationId: generateUUIDv1(), | ||
}, | ||
}, | ||
platform: PlatformType.TWITTER, | ||
email: '[email protected]', | ||
joinedAt: '2020-05-24T15:13:30Z', | ||
} | ||
|
||
const member1 = await memberService.upsert(memberToCreate1) | ||
let member2 = await memberService.upsert(memberToCreate2) | ||
const member3 = await memberService.upsert(memberToCreate3) | ||
let member4 = await memberService.upsert(memberToCreate4) | ||
|
||
await memberService.addToMerge([{ members: [member1.id, member2.id], similarity: 1 }]) | ||
await memberService.addToMerge([{ members: [member3.id, member4.id], similarity: 0.5 }]) | ||
|
||
member2 = await memberService.findById(member2.id) | ||
member4 = await memberService.findById(member4.id) | ||
|
||
const memberToMergeSuggestions = await tenantService.findMembersToMerge({}) | ||
|
||
// In the DB there should be: | ||
// - Member 1 should have member 2 in toMerge | ||
// - Member 3 should have member 4 in toMerge | ||
// - Member 4 should have member 3 in toMerge | ||
// - We should get these 4 combinations | ||
// But this function should not return duplicates, so we should get | ||
// only two pairs: [m2, m1] and [m4, m3] | ||
|
||
expect(memberToMergeSuggestions.count).toEqual(1) | ||
|
||
expect( | ||
memberToMergeSuggestions.rows[0].members | ||
.sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1)) | ||
.map((m) => m.id), | ||
).toStrictEqual([member1.id, member2.id]) | ||
|
||
expect( | ||
memberToMergeSuggestions.rows[1].members | ||
.sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1)) | ||
.map((m) => m.id), | ||
).toStrictEqual([member3.id, member4.id]) | ||
}) | ||
}) | ||
|
||
describe('_findAndCountAllForEveryUser method', () => { | ||
it('Should succesfully find all tenants without filtering by currentUser', async () => { | ||
let tenants = await TenantService._findAndCountAllForEveryUser({ filter: {} }) | ||
|
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
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
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
Oops, something went wrong.