Skip to content

Commit b15d1ee

Browse files
committed
test: update tests with new scenarios
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 4a31925 commit b15d1ee

1 file changed

Lines changed: 129 additions & 14 deletions

File tree

  • services/libs/data-access-layer/src/member-organization-affiliation

services/libs/data-access-layer/src/member-organization-affiliation/index.test.ts

Lines changed: 129 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ describe('prepareMemberOrganizationAffiliationTimeline', () => {
588588
const [company, university] = await createOrganizations(
589589
qx,
590590
withOrganizationDefaults([
591-
{ displayName: 'Acme Corp' },
592-
{ displayName: 'Sharda University' },
591+
{ displayName: 'Intel Corporation' },
592+
{ displayName: 'New York University' },
593593
]),
594594
)
595595
const [member] = await createMembers(qx, withMemberDefaults([{}]))
@@ -598,42 +598,49 @@ describe('prepareMemberOrganizationAffiliationTimeline', () => {
598598
{
599599
organizationId: company.id,
600600
platform: 'integration',
601-
value: 'acme.com',
601+
value: 'intel.com',
602602
type: OrganizationIdentityType.PRIMARY_DOMAIN,
603603
verified: true,
604604
},
605605
{
606606
organizationId: university.id,
607607
platform: 'integration',
608-
value: 'sharda.edu',
608+
value: 'nyu.edu',
609609
type: OrganizationIdentityType.PRIMARY_DOMAIN,
610610
verified: true,
611611
},
612612
])
613613

614+
// Same source; university stint is longer. Without company-over-uni, longest-range
615+
// (and equal source rank) would pick the university for the overlap.
614616
await createMemberOrganizations(qx, [
615617
{
616618
memberId: member.id,
617-
organizationId: company.id,
619+
organizationId: university.id,
618620
dateStart: '2021-01-01T00:00:00.000Z',
619621
dateEnd: '2022-01-01T00:00:00.000Z',
620-
title: 'Engineer',
621-
source: OrganizationSource.UI,
622+
title: 'Student Researcher',
623+
source: OrganizationSource.ENRICHMENT_CRUSTDATA,
622624
},
623625
{
624626
memberId: member.id,
625-
organizationId: university.id,
627+
organizationId: company.id,
626628
dateStart: '2021-06-01T00:00:00.000Z',
627-
dateEnd: '2022-03-01T00:00:00.000Z',
628-
title: 'Student Researcher',
629+
dateEnd: '2021-09-01T00:00:00.000Z',
630+
title: 'Engineer',
629631
source: OrganizationSource.ENRICHMENT_CRUSTDATA,
630632
},
631633
])
632634

633635
const timeline = await prepareMemberOrganizationAffiliationTimeline(qx, member.id)
634636
const base = baseItems(timeline)
635637

636-
// Company wins the overlap, so university must not open a range at its own dateStart.
638+
expect(
639+
base.some(
640+
(item) =>
641+
item.organizationId === company.id && item.dateStart === '2021-06-01T00:00:00.000Z',
642+
),
643+
).toBe(true)
637644
expect(
638645
base.some(
639646
(item) =>
@@ -643,11 +650,9 @@ describe('prepareMemberOrganizationAffiliationTimeline', () => {
643650
expect(
644651
base.some(
645652
(item) =>
646-
item.organizationId === company.id && item.dateStart === '2021-01-01T00:00:00.000Z',
653+
item.organizationId === university.id && item.dateStart === '2021-01-01T00:00:00.000Z',
647654
),
648655
).toBe(true)
649-
// University-only tail after the company ends is fine.
650-
expect(base.some((item) => item.organizationId === university.id)).toBe(true)
651656
})
652657

653658
test('verified primary-domain yields an email timeline item', async ({ qx }) => {
@@ -824,6 +829,8 @@ describe('refreshMemberOrganizationAffiliations', () => {
824829
withOrganizationDefaults([{ displayName: 'Red Hat' }, { displayName: 'Previous Employer' }]),
825830
)
826831
const { member, identities } = await createMemberWithIdentity(qx, {
832+
platform: PlatformType.GITHUB,
833+
type: MemberIdentityType.EMAIL,
827834
value: 'dev@redhat.com',
828835
})
829836
const { kubernetes } = await createLeafSegments(qx)
@@ -872,4 +879,112 @@ describe('refreshMemberOrganizationAffiliations', () => {
872879
expect(await countByOrg(qx, member.id, kubernetes.id, emailOrg.id)).toBe(seeded.length)
873880
expect(await countByOrg(qx, member.id, kubernetes.id, datedOrg.id)).toBe(0)
874881
})
882+
883+
test('during company/university overlap, non-email follows company while email domains keep their orgs', async ({
884+
qx,
885+
}) => {
886+
const [company, university] = await createOrganizations(
887+
qx,
888+
withOrganizationDefaults([
889+
{ displayName: 'Intel Corporation' },
890+
{ displayName: 'New York University' },
891+
]),
892+
)
893+
const [member] = await createMembers(qx, withMemberDefaults([{}]))
894+
const { kubernetes } = await createLeafSegments(qx)
895+
896+
const [githubIdentity, uniEmailIdentity, companyEmailIdentity] = await createMemberIdentities(
897+
qx,
898+
withMemberIdentityDefaults([
899+
{
900+
memberId: member.id,
901+
platform: PlatformType.GITHUB,
902+
type: MemberIdentityType.USERNAME,
903+
value: 'student-dev',
904+
},
905+
{
906+
memberId: member.id,
907+
platform: PlatformType.GITHUB,
908+
type: MemberIdentityType.EMAIL,
909+
value: 'student@nyu.edu',
910+
},
911+
{
912+
memberId: member.id,
913+
platform: PlatformType.GITHUB,
914+
type: MemberIdentityType.EMAIL,
915+
value: 'eng@intel.com',
916+
},
917+
]),
918+
)
919+
920+
await createOrganizationIdentities(qx, [
921+
{
922+
organizationId: company.id,
923+
platform: 'integration',
924+
value: 'intel.com',
925+
type: OrganizationIdentityType.PRIMARY_DOMAIN,
926+
verified: true,
927+
},
928+
{
929+
organizationId: university.id,
930+
platform: 'integration',
931+
value: 'nyu.edu',
932+
type: OrganizationIdentityType.PRIMARY_DOMAIN,
933+
verified: true,
934+
},
935+
])
936+
937+
await createMemberOrganizations(qx, [
938+
{
939+
memberId: member.id,
940+
organizationId: university.id,
941+
dateStart: '2021-01-01T00:00:00.000Z',
942+
dateEnd: '2022-01-01T00:00:00.000Z',
943+
title: 'Student Researcher',
944+
source: OrganizationSource.ENRICHMENT_CRUSTDATA,
945+
},
946+
{
947+
memberId: member.id,
948+
organizationId: company.id,
949+
dateStart: '2021-06-01T00:00:00.000Z',
950+
dateEnd: '2021-09-01T00:00:00.000Z',
951+
title: 'Engineer',
952+
source: OrganizationSource.ENRICHMENT_CRUSTDATA,
953+
},
954+
])
955+
956+
const overlap = {
957+
from: '2021-07-01T00:00:00.000Z',
958+
to: '2021-07-15T00:00:00.000Z',
959+
} as const
960+
961+
await createActivityRelations(qx, [
962+
...generateActivityRelations({
963+
memberId: member.id,
964+
segmentId: kubernetes.id,
965+
identities: [githubIdentity],
966+
count: 10,
967+
timestamp: overlap,
968+
}),
969+
...generateActivityRelations({
970+
memberId: member.id,
971+
segmentId: kubernetes.id,
972+
identities: [uniEmailIdentity],
973+
count: 8,
974+
timestamp: overlap,
975+
}),
976+
...generateActivityRelations({
977+
memberId: member.id,
978+
segmentId: kubernetes.id,
979+
identities: [companyEmailIdentity],
980+
count: 6,
981+
timestamp: overlap,
982+
}),
983+
])
984+
985+
await refreshMemberOrganizationAffiliations(qx, member.id)
986+
987+
expect(await countByOrg(qx, member.id, kubernetes.id, company.id)).toBe(16) // 10 GH + 6 @intel.com
988+
expect(await countByOrg(qx, member.id, kubernetes.id, university.id)).toBe(8) // @nyu.edu
989+
})
875990
})

0 commit comments

Comments
 (0)