diff --git a/__tests__/boot.ts b/__tests__/boot.ts index a2e29dfcb2..54a11692d5 100644 --- a/__tests__/boot.ts +++ b/__tests__/boot.ts @@ -897,7 +897,7 @@ describe('logged in boot', () => { it('should set last activity in redis if user is part of organization', async () => { await saveFixtures(con, Organization, [ { - id: 'org-1', + id: 'bcc87627-7b19-40b6-a8f4-72dc94e764d5', seats: 1, name: 'Organization 1', subscriptionFlags: { @@ -917,8 +917,8 @@ describe('logged in boot', () => { await saveFixtures(con, ContentPreferenceOrganization, [ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: 'bcc87627-7b19-40b6-a8f4-72dc94e764d5', + organizationId: 'bcc87627-7b19-40b6-a8f4-72dc94e764d5', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { diff --git a/__tests__/cron/expireSuperAgentTrial.ts b/__tests__/cron/expireSuperAgentTrial.ts index 7d33050be4..72d11d54f7 100644 --- a/__tests__/cron/expireSuperAgentTrial.ts +++ b/__tests__/cron/expireSuperAgentTrial.ts @@ -16,9 +16,24 @@ import { remoteConfig } from '../../src/remoteConfig'; let con: DataSource; -const testOrgPrefix = 'esat-'; // expire-super-agent-trial prefix -// UUID base for test opportunity IDs (valid UUID format) -const testOpBase = 'e5a70000-0000-0000-0000-00000000000'; +// Valid UUIDs for test organizations +const testOrgIds = { + expiredWithPlan: 'e5a70001-0000-0000-0000-000000000001', + expiredNoPlan: 'e5a70002-0000-0000-0000-000000000002', + activeTrial: 'e5a70003-0000-0000-0000-000000000003', + noTrial: 'e5a70004-0000-0000-0000-000000000004', +}; + +// Valid UUIDs for test opportunities +const testOpIds = { + trialLive: 'e5a70100-0000-0000-0000-000000000001', + trialReview: 'e5a70100-0000-0000-0000-000000000002', + trialClosed: 'e5a70100-0000-0000-0000-000000000003', + trialDraft: 'e5a70100-0000-0000-0000-000000000004', + paidLive: 'e5a70100-0000-0000-0000-000000000005', + activeTrial: 'e5a70100-0000-0000-0000-000000000006', + noTrialOrg: 'e5a70100-0000-0000-0000-000000000007', +}; beforeAll(async () => { con = await createOrGetConnection(); @@ -32,7 +47,7 @@ beforeEach(async () => { await saveFixtures(con, Organization, [ { - id: `${testOrgPrefix}expired-with-plan`, + id: testOrgIds.expiredWithPlan, name: 'Expired With Plan Org ESAT', recruiterSubscriptionFlags: { isTrialActive: true, @@ -43,7 +58,7 @@ beforeEach(async () => { }, }, { - id: `${testOrgPrefix}expired-no-plan`, + id: testOrgIds.expiredNoPlan, name: 'Expired No Plan Org ESAT', recruiterSubscriptionFlags: { isTrialActive: true, @@ -53,7 +68,7 @@ beforeEach(async () => { }, }, { - id: `${testOrgPrefix}active-trial`, + id: testOrgIds.activeTrial, name: 'Active Trial Org ESAT', recruiterSubscriptionFlags: { isTrialActive: true, @@ -63,7 +78,7 @@ beforeEach(async () => { }, }, { - id: `${testOrgPrefix}no-trial`, + id: testOrgIds.noTrial, name: 'No Trial Org ESAT', recruiterSubscriptionFlags: { status: SubscriptionStatus.Active, @@ -76,12 +91,12 @@ beforeEach(async () => { await saveFixtures(con, OpportunityJob, [ // Trial opportunity for expired org - should have trial features removed { - id: `${testOpBase}1`, + id: testOpIds.trialLive, type: OpportunityType.JOB, state: OpportunityState.LIVE, title: 'Trial Live Op ESAT', tldr: 'Trial live opportunity', - organizationId: `${testOrgPrefix}expired-no-plan`, + organizationId: testOrgIds.expiredNoPlan, flags: { plan: 'pri_seat_123', isTrial: true, @@ -93,12 +108,12 @@ beforeEach(async () => { }, // Trial opportunity in review for expired org - should have trial features removed { - id: `${testOpBase}2`, + id: testOpIds.trialReview, type: OpportunityType.JOB, state: OpportunityState.IN_REVIEW, title: 'Trial Review Op ESAT', tldr: 'Trial in review opportunity', - organizationId: `${testOrgPrefix}expired-no-plan`, + organizationId: testOrgIds.expiredNoPlan, flags: { plan: 'pri_seat_456', isTrial: true, @@ -110,59 +125,58 @@ beforeEach(async () => { }, // Trial opportunity already closed - should not be affected { - id: `${testOpBase}3`, + id: testOpIds.trialClosed, type: OpportunityType.JOB, state: OpportunityState.CLOSED, title: 'Trial Closed Op ESAT', tldr: 'Trial closed opportunity', - organizationId: `${testOrgPrefix}expired-no-plan`, + organizationId: testOrgIds.expiredNoPlan, flags: { plan: 'pri_seat_789', isTrial: true, batchSize: 150 }, }, // Trial opportunity draft - should not be affected { - id: `${testOpBase}4`, + id: testOpIds.trialDraft, type: OpportunityType.JOB, state: OpportunityState.DRAFT, title: 'Trial Draft Op ESAT', tldr: 'Trial draft opportunity', - organizationId: `${testOrgPrefix}expired-no-plan`, + organizationId: testOrgIds.expiredNoPlan, flags: { plan: 'pri_seat_abc', isTrial: true, batchSize: 150 }, }, // Paid opportunity without trial for expired org - should not be affected { - id: `${testOpBase}5`, + id: testOpIds.paidLive, type: OpportunityType.JOB, state: OpportunityState.LIVE, title: 'Paid Live Op ESAT', tldr: 'Paid live opportunity', - organizationId: `${testOrgPrefix}expired-with-plan`, + organizationId: testOrgIds.expiredWithPlan, flags: { plan: 'pri_original_123', batchSize: 200 }, }, // Trial opportunity for active trial org - should not be affected { - id: `${testOpBase}6`, + id: testOpIds.activeTrial, type: OpportunityType.JOB, state: OpportunityState.LIVE, title: 'Active Trial Op ESAT', tldr: 'Active trial opportunity', - organizationId: `${testOrgPrefix}active-trial`, + organizationId: testOrgIds.activeTrial, flags: { plan: 'pri_seat_xyz', isTrial: true, batchSize: 150 }, }, // Opportunity for non-trial org - should not be affected { - id: `${testOpBase}7`, + id: testOpIds.noTrialOrg, type: OpportunityType.JOB, state: OpportunityState.LIVE, title: 'No Trial Org Op ESAT', tldr: 'No trial org opportunity', - organizationId: `${testOrgPrefix}no-trial`, + organizationId: testOrgIds.noTrial, flags: { plan: 'pri_regular_123', batchSize: 100 }, }, ]); }); afterEach(() => { - // @ts-expect-error - resetting to undefined for tests remoteConfig.vars.superAgentTrial = undefined; }); @@ -178,7 +192,7 @@ describe('expireSuperAgentTrial cron', () => { // Verify expired trial with original plan - keeps active status const expiredWithPlan = await con .getRepository(Organization) - .findOneBy({ id: `${testOrgPrefix}expired-with-plan` }); + .findOneBy({ id: testOrgIds.expiredWithPlan }); expect(expiredWithPlan?.recruiterSubscriptionFlags).toMatchObject({ isTrialActive: false, status: SubscriptionStatus.Active, @@ -191,7 +205,7 @@ describe('expireSuperAgentTrial cron', () => { // Verify expired trial without original plan - downgrades to none const expiredNoPlan = await con .getRepository(Organization) - .findOneBy({ id: `${testOrgPrefix}expired-no-plan` }); + .findOneBy({ id: testOrgIds.expiredNoPlan }); expect(expiredNoPlan?.recruiterSubscriptionFlags).toMatchObject({ isTrialActive: false, status: SubscriptionStatus.None, @@ -200,7 +214,7 @@ describe('expireSuperAgentTrial cron', () => { // Verify active trial was not affected const activeTrial = await con .getRepository(Organization) - .findOneBy({ id: `${testOrgPrefix}active-trial` }); + .findOneBy({ id: testOrgIds.activeTrial }); expect(activeTrial?.recruiterSubscriptionFlags).toMatchObject({ isTrialActive: true, status: SubscriptionStatus.Active, @@ -212,7 +226,7 @@ describe('expireSuperAgentTrial cron', () => { // Verify org without trial was not affected const noTrial = await con .getRepository(Organization) - .findOneBy({ id: `${testOrgPrefix}no-trial` }); + .findOneBy({ id: testOrgIds.noTrial }); expect(noTrial?.recruiterSubscriptionFlags).toMatchObject({ status: SubscriptionStatus.Active, }); @@ -227,7 +241,7 @@ describe('expireSuperAgentTrial cron', () => { // Trial LIVE opportunity for expired org - should remain LIVE but have trial features removed // and batchSize reset to default (50) const trialLive = await opportunityRepo.findOneBy({ - id: `${testOpBase}1`, + id: testOpIds.trialLive, }); expect(trialLive?.state).toBe(OpportunityState.LIVE); expect(trialLive?.flags?.plan).toBe('pri_seat_123'); // plan preserved @@ -239,7 +253,7 @@ describe('expireSuperAgentTrial cron', () => { // Trial IN_REVIEW opportunity for expired org - should remain IN_REVIEW but have trial features removed const trialReview = await opportunityRepo.findOneBy({ - id: `${testOpBase}2`, + id: testOpIds.trialReview, }); expect(trialReview?.state).toBe(OpportunityState.IN_REVIEW); expect(trialReview?.flags?.plan).toBe('pri_seat_456'); // plan preserved @@ -248,21 +262,21 @@ describe('expireSuperAgentTrial cron', () => { // Trial CLOSED opportunity - should remain closed and have trial features intact (not affected) const trialClosed = await opportunityRepo.findOneBy({ - id: `${testOpBase}3`, + id: testOpIds.trialClosed, }); expect(trialClosed?.state).toBe(OpportunityState.CLOSED); expect(trialClosed?.flags?.isTrial).toBe(true); // not affected since already closed // Trial DRAFT opportunity - should remain draft and have trial features intact (not affected) const trialDraft = await opportunityRepo.findOneBy({ - id: `${testOpBase}4`, + id: testOpIds.trialDraft, }); expect(trialDraft?.state).toBe(OpportunityState.DRAFT); expect(trialDraft?.flags?.isTrial).toBe(true); // not affected since draft // Paid opportunity without trial for expired org - should remain unchanged const paidLive = await opportunityRepo.findOneBy({ - id: `${testOpBase}5`, + id: testOpIds.paidLive, }); expect(paidLive?.state).toBe(OpportunityState.LIVE); expect(paidLive?.flags?.plan).toBe('pri_original_123'); @@ -270,14 +284,14 @@ describe('expireSuperAgentTrial cron', () => { // Trial opportunity for active trial org - should remain unchanged const activeTrial = await opportunityRepo.findOneBy({ - id: `${testOpBase}6`, + id: testOpIds.activeTrial, }); expect(activeTrial?.state).toBe(OpportunityState.LIVE); expect(activeTrial?.flags?.isTrial).toBe(true); // trial still active // Opportunity for non-trial org - should remain unchanged const noTrialOp = await opportunityRepo.findOneBy({ - id: `${testOpBase}7`, + id: testOpIds.noTrialOrg, }); expect(noTrialOp?.state).toBe(OpportunityState.LIVE); expect(noTrialOp?.flags?.batchSize).toBe(100); @@ -299,19 +313,19 @@ describe('expireSuperAgentTrial cron', () => { await saveFixtures(con, OpportunityUserRecruiter, [ // User 1 is recruiter on trial opportunity for expired org { - opportunityId: `${testOpBase}1`, + opportunityId: testOpIds.trialLive, userId: '1', type: OpportunityUserType.Recruiter, }, // User 2 is recruiter on trial opportunity for active trial org (not affected) { - opportunityId: `${testOpBase}6`, + opportunityId: testOpIds.activeTrial, userId: '2', type: OpportunityUserType.Recruiter, }, // User 3 is recruiter on paid opportunity (not affected) { - opportunityId: `${testOpBase}5`, + opportunityId: testOpIds.paidLive, userId: '3', type: OpportunityUserType.Recruiter, }, diff --git a/__tests__/organizations.ts b/__tests__/organizations.ts index 5bb332a793..3561480f89 100644 --- a/__tests__/organizations.ts +++ b/__tests__/organizations.ts @@ -61,7 +61,7 @@ beforeEach(async () => { await saveFixtures(con, Organization, [ { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', seats: 1, name: 'Organization 1', subscriptionFlags: { @@ -70,7 +70,7 @@ beforeEach(async () => { }, }, { - id: 'org-2', + id: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', seats: 2, name: 'Organization 2', subscriptionFlags: { @@ -79,7 +79,7 @@ beforeEach(async () => { }, }, { - id: 'org-3', + id: '42ce1d83-9ce4-4d97-b175-fd082d95a2c4', seats: 5, name: 'Organization 3', subscriptionFlags: { @@ -128,8 +128,8 @@ describe('query organizations', () => { await con.getRepository(ContentPreferenceOrganization).save({ userId: loggedUser, - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: loggedUser, status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -145,7 +145,7 @@ describe('query organizations', () => { role: 'owner', referralToken: 'ref-token-1', organization: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', name: 'Organization 1', image: null, seats: 1, @@ -184,7 +184,10 @@ describe('query organization', () => { it('should not authorize when not logged-in', () => testQueryErrorCode( client, - { query: QUERY, variables: { id: 'org-1' } }, + { + query: QUERY, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }, 'UNAUTHENTICATED', )); @@ -193,7 +196,10 @@ describe('query organization', () => { testQueryErrorCode( client, - { query: QUERY, variables: { id: 'non-existing' } }, + { + query: QUERY, + variables: { id: '00000000-0000-0000-0000-000000000000' }, + }, 'NOT_FOUND', ); }); @@ -203,7 +209,10 @@ describe('query organization', () => { testQueryErrorCode( client, - { query: QUERY, variables: { id: 'org-1' } }, + { + query: QUERY, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }, 'NOT_FOUND', ); }); @@ -218,8 +227,8 @@ describe('query organization', () => { await con.getRepository(ContentPreferenceOrganization).save({ userId: loggedUser, - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: loggedUser, status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -229,15 +238,15 @@ describe('query organization', () => { }); const { data } = await client.query(QUERY, { - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }); expect(data).toMatchObject({ organization: { role: 'owner', referralToken: 'ref-token-1', - referralUrl: `${process.env.COMMENTS_PREFIX}/join/organization?token=ref-token-1&orgId=org-1`, + referralUrl: `${process.env.COMMENTS_PREFIX}/join/organization?token=ref-token-1&orgId=9a212368-3388-4040-9c59-540f44c7a862`, organization: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', name: 'Organization 1', seats: 1, }, @@ -262,8 +271,8 @@ describe('query organization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: loggedUser, - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: loggedUser, status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -273,8 +282,8 @@ describe('query organization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -284,7 +293,9 @@ describe('query organization', () => { }, ]); - const { data } = await client.query(QUERY, { variables: { id: 'org-1' } }); + const { data } = await client.query(QUERY, { + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }); const { organization } = data.organization as GQLUserOrganization; expect(organization.members).toEqual([ @@ -326,8 +337,8 @@ describe('query organization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, createdAt: now, @@ -338,8 +349,8 @@ describe('query organization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, createdAt: addHours(now, 1), @@ -350,8 +361,8 @@ describe('query organization', () => { }, { userId: '3', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '3', status: ContentPreferenceOrganizationStatus.Plus, createdAt: addHours(now, 2), @@ -362,8 +373,8 @@ describe('query organization', () => { }, { userId: '4', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '4', status: ContentPreferenceOrganizationStatus.Plus, createdAt: now, @@ -377,7 +388,7 @@ describe('query organization', () => { const { data, errors } = await client.query< { organization: GQLUserOrganization }, { id: string } - >(QUERY, { variables: { id: 'org-1' } }); + >(QUERY, { variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' } }); expect(errors).toBeUndefined(); expect( @@ -396,8 +407,8 @@ describe('query organization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -407,8 +418,8 @@ describe('query organization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -418,7 +429,9 @@ describe('query organization', () => { }, ]); - const { data } = await client.query(QUERY, { variables: { id: 'org-1' } }); + const { data } = await client.query(QUERY, { + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }); const { organization } = data.organization as GQLUserOrganization; expect(organization.members[0].lastActive).toBeNull(); }); @@ -434,8 +447,8 @@ describe('query organization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -445,8 +458,8 @@ describe('query organization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -463,7 +476,9 @@ describe('query organization', () => { lastActiveTimestamp.toString(), ); - const { data } = await client.query(QUERY, { variables: { id: 'org-1' } }); + const { data } = await client.query(QUERY, { + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }); const { organization } = data.organization as GQLUserOrganization; expect(organization.members[0].lastActive).toBe( new Date(lastActiveTimestamp).toISOString(), @@ -482,8 +497,8 @@ describe('query organization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -493,8 +508,8 @@ describe('query organization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -504,8 +519,8 @@ describe('query organization', () => { }, { userId: '3', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '3', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -522,7 +537,9 @@ describe('query organization', () => { lastActiveTimestamp.toString(), ); - const { data } = await client.query(QUERY, { variables: { id: 'org-1' } }); + const { data } = await client.query(QUERY, { + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }); const { organization } = data.organization as GQLUserOrganization; // Find by user id for clarity const member2 = organization.members.find((m) => m.user.id === '2'); @@ -563,8 +580,8 @@ describe('mutation updateOrganization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -574,8 +591,8 @@ describe('mutation updateOrganization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -589,7 +606,13 @@ describe('mutation updateOrganization', () => { it('should not authorize when not logged-in', () => testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-1', name: 'New org name' } }, + { + mutation: MUTATION, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + name: 'New org name', + }, + }, 'UNAUTHENTICATED', )); @@ -600,7 +623,10 @@ describe('mutation updateOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'non-existing', name: 'New org name' }, + variables: { + id: '00000000-0000-0000-0000-000000000000', + name: 'New org name', + }, }, 'NOT_FOUND', ); @@ -611,7 +637,13 @@ describe('mutation updateOrganization', () => { testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-2', name: 'New org name' } }, + { + mutation: MUTATION, + variables: { + id: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + name: 'New org name', + }, + }, 'NOT_FOUND', ); }); @@ -621,7 +653,13 @@ describe('mutation updateOrganization', () => { testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-1', name: 'New org name' } }, + { + mutation: MUTATION, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + name: 'New org name', + }, + }, 'FORBIDDEN', ); }); @@ -630,13 +668,16 @@ describe('mutation updateOrganization', () => { loggedUser = '1'; const { data } = await client.mutate(MUTATION, { - variables: { id: 'org-1', name: 'New org name' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + name: 'New org name', + }, }); expect(data).toEqual({ updateOrganization: { organization: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', name: 'New org name', image: null, }, @@ -644,7 +685,7 @@ describe('mutation updateOrganization', () => { }); const updatedOrg = await con.getRepository(Organization).findOneByOrFail({ - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', }); expect(updatedOrg.name).toBe('New org name'); }); @@ -653,7 +694,7 @@ describe('mutation updateOrganization', () => { loggedUser = '1'; const res = await client.mutate(MUTATION, { - variables: { id: 'org-1', name: null }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862', name: null }, }); const errors = res.errors!; @@ -670,7 +711,7 @@ describe('mutation updateOrganization', () => { loggedUser = '1'; const res = await client.mutate(MUTATION, { - variables: { id: 'org-1', name: ' ' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862', name: ' ' }, }); const errors = res.errors!; @@ -717,8 +758,8 @@ describe('mutation joinOrganization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -728,8 +769,8 @@ describe('mutation joinOrganization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -743,7 +784,13 @@ describe('mutation joinOrganization', () => { it('should not authorize when not logged-in', () => testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-1', token: 'ref-token-1' } }, + { + mutation: MUTATION, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: 'ref-token-1', + }, + }, 'UNAUTHENTICATED', )); @@ -754,7 +801,10 @@ describe('mutation joinOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'non-existing', token: 'ref-token-1' }, + variables: { + id: '00000000-0000-0000-0000-000000000000', + token: 'ref-token-1', + }, }, 'FORBIDDEN', 'Invalid invitation token', @@ -768,7 +818,10 @@ describe('mutation joinOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', token: 'non-existing' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: '00000000-0000-0000-0000-000000000000', + }, }, 'FORBIDDEN', 'Invalid invitation token', @@ -782,7 +835,10 @@ describe('mutation joinOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', token: 'ref-token-2' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: 'ref-token-2', + }, }, 'FORBIDDEN', 'The person who invited you does not have permission to invite you to this organization.', @@ -793,13 +849,16 @@ describe('mutation joinOrganization', () => { loggedUser = '3'; const res = await client.mutate(MUTATION, { - variables: { id: 'org-1', token: 'ref-token-1' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: 'ref-token-1', + }, }); expect(res.data).toMatchObject({ joinOrganization: { role: 'member', organization: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', name: 'Organization 1', }, }, @@ -809,18 +868,22 @@ describe('mutation joinOrganization', () => { .getRepository(ContentPreferenceOrganization) .findOneByOrFail({ userId: loggedUser, - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }); expect(contentPreference).not.toBeNull(); - expect(contentPreference.organizationId).toBe('org-1'); + expect(contentPreference.organizationId).toBe( + '9a212368-3388-4040-9c59-540f44c7a862', + ); expect(contentPreference.flags?.role).toBe(OrganizationMemberRole.Member); const user = await con.getRepository(User).findOneByOrFail({ id: loggedUser, }); - expect(user.subscriptionFlags?.organizationId).toBe('org-1'); + expect(user.subscriptionFlags?.organizationId).toBe( + '9a212368-3388-4040-9c59-540f44c7a862', + ); expect(user.subscriptionFlags?.cycle).toBe(SubscriptionCycles.Yearly); }); }); @@ -860,8 +923,8 @@ describe('query getOrganizationByIdAndInviteToken', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -871,8 +934,8 @@ describe('query getOrganizationByIdAndInviteToken', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -890,7 +953,10 @@ describe('query getOrganizationByIdAndInviteToken', () => { client, { query: QUERY, - variables: { id: 'non-existing', token: 'ref-token-1' }, + variables: { + id: '00000000-0000-0000-0000-000000000000', + token: 'ref-token-1', + }, }, 'FORBIDDEN', 'Invalid invitation token', @@ -904,7 +970,10 @@ describe('query getOrganizationByIdAndInviteToken', () => { client, { query: QUERY, - variables: { id: 'org-1', token: 'ref-token-2' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: 'ref-token-2', + }, }, 'FORBIDDEN', 'The person who invited you does not have permission to invite you to this organization.', @@ -915,7 +984,10 @@ describe('query getOrganizationByIdAndInviteToken', () => { loggedUser = '3'; const res = await client.query(QUERY, { - variables: { id: 'org-1', token: 'ref-token-1' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: 'ref-token-1', + }, }); expect(res.data).toMatchObject({ getOrganizationByIdAndInviteToken: { @@ -924,7 +996,7 @@ describe('query getOrganizationByIdAndInviteToken', () => { name: 'Ido', }, organization: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', name: 'Organization 1', }, }, @@ -933,7 +1005,10 @@ describe('query getOrganizationByIdAndInviteToken', () => { it('should return organization and user who invited when not logged in', async () => { const res = await client.query(QUERY, { - variables: { id: 'org-1', token: 'ref-token-1' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + token: 'ref-token-1', + }, }); expect(res.data).toMatchObject({ getOrganizationByIdAndInviteToken: { @@ -942,7 +1017,7 @@ describe('query getOrganizationByIdAndInviteToken', () => { name: 'Ido', }, organization: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', name: 'Organization 1', }, }, @@ -991,8 +1066,8 @@ describe('mutation leaveOrganization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1002,8 +1077,8 @@ describe('mutation leaveOrganization', () => { }, { userId: 'org-rem-2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: 'org-rem-2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1017,7 +1092,10 @@ describe('mutation leaveOrganization', () => { it('should not authorize when not logged-in', () => testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-1' } }, + { + mutation: MUTATION, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }, 'UNAUTHENTICATED', )); @@ -1028,7 +1106,7 @@ describe('mutation leaveOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }, 'NOT_FOUND', ); @@ -1041,7 +1119,7 @@ describe('mutation leaveOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }, 'FORBIDDEN', "Access denied! Owner can't be removed", @@ -1057,21 +1135,21 @@ describe('mutation leaveOrganization', () => { }, { subscriptionFlags: updateSubscriptionFlags({ - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', cycle: 'yearly', }), }, ); await client.mutate(MUTATION, { - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }); const contentPreference = await con .getRepository(ContentPreferenceOrganization) .findOneBy({ userId: loggedUser, - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }); expect(contentPreference).toBeNull(); @@ -1100,14 +1178,14 @@ describe('mutation leaveOrganization', () => { ); await client.mutate(MUTATION, { - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }); const contentPreference = await con .getRepository(ContentPreferenceOrganization) .findOneBy({ userId: loggedUser, - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }); expect(contentPreference).toBeNull(); @@ -1150,8 +1228,8 @@ describe('mutation deleteOrganization', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1161,8 +1239,8 @@ describe('mutation deleteOrganization', () => { }, { userId: '1', - referenceId: 'org-2', - organizationId: 'org-2', + referenceId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + organizationId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1172,8 +1250,8 @@ describe('mutation deleteOrganization', () => { }, { userId: '1', - referenceId: 'org-3', - organizationId: 'org-3', + referenceId: '42ce1d83-9ce4-4d97-b175-fd082d95a2c4', + organizationId: '42ce1d83-9ce4-4d97-b175-fd082d95a2c4', feedId: '1', status: ContentPreferenceOrganizationStatus.Free, flags: { @@ -1183,8 +1261,8 @@ describe('mutation deleteOrganization', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1198,7 +1276,10 @@ describe('mutation deleteOrganization', () => { it('should not authorize when not logged-in', () => testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-1' } }, + { + mutation: MUTATION, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + }, 'UNAUTHENTICATED', )); @@ -1209,7 +1290,7 @@ describe('mutation deleteOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }, 'NOT_FOUND', ); @@ -1222,7 +1303,7 @@ describe('mutation deleteOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }, 'FORBIDDEN', 'Access denied! You need to be a owner or higher to perform this action.', @@ -1236,7 +1317,7 @@ describe('mutation deleteOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862' }, }, 'FORBIDDEN', 'Cannot delete organization with an active subscription. Please cancel the subscription first.', @@ -1250,7 +1331,7 @@ describe('mutation deleteOrganization', () => { client, { mutation: MUTATION, - variables: { id: 'org-2' }, + variables: { id: '5d7a9ee0-a095-44df-8a2c-6915af60ece2' }, }, 'FORBIDDEN', 'Cannot delete organization with Plus members. Please remove all Plus members first.', @@ -1261,7 +1342,7 @@ describe('mutation deleteOrganization', () => { loggedUser = '1'; const { data, errors } = await client.mutate(MUTATION, { - variables: { id: 'org-3' }, + variables: { id: '42ce1d83-9ce4-4d97-b175-fd082d95a2c4' }, }); expect(errors).toBeUndefined(); @@ -1272,7 +1353,7 @@ describe('mutation deleteOrganization', () => { }); const org = await con.getRepository(Organization).findOneBy({ - id: 'org-3', + id: '42ce1d83-9ce4-4d97-b175-fd082d95a2c4', }); expect(org).toBeNull(); @@ -1280,7 +1361,7 @@ describe('mutation deleteOrganization', () => { .getRepository(ContentPreferenceOrganization) .findOneBy({ userId: loggedUser, - organizationId: 'org-3', + organizationId: '42ce1d83-9ce4-4d97-b175-fd082d95a2c4', }); expect(contentPreference).toBeNull(); }); @@ -1322,8 +1403,8 @@ describe('mutation removeOrganizationMember', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1333,8 +1414,8 @@ describe('mutation removeOrganizationMember', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1344,8 +1425,8 @@ describe('mutation removeOrganizationMember', () => { }, { userId: '3', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '3', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1359,7 +1440,13 @@ describe('mutation removeOrganizationMember', () => { it('should not authorize when not logged-in', () => testMutationErrorCode( client, - { mutation: MUTATION, variables: { id: 'org-1', memberId: '2' } }, + { + mutation: MUTATION, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + }, + }, 'UNAUTHENTICATED', )); @@ -1370,7 +1457,10 @@ describe('mutation removeOrganizationMember', () => { client, { mutation: MUTATION, - variables: { id: 'org-2', memberId: '2' }, + variables: { + id: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + memberId: '2', + }, }, 'NOT_FOUND', ); @@ -1383,7 +1473,10 @@ describe('mutation removeOrganizationMember', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '2' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + }, }, 'FORBIDDEN', 'Access denied! You need to be a admin or higher to perform this action.', @@ -1397,7 +1490,10 @@ describe('mutation removeOrganizationMember', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '1' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '1', + }, }, 'FORBIDDEN', 'You cannot remove yourself from the organization.', @@ -1411,7 +1507,10 @@ describe('mutation removeOrganizationMember', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '1' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '1', + }, }, 'FORBIDDEN', 'You cannot remove the owner of the organization.', @@ -1423,7 +1522,7 @@ describe('mutation removeOrganizationMember', () => { await con.getRepository(User).update('3', { subscriptionFlags: { - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }, }); @@ -1433,7 +1532,7 @@ describe('mutation removeOrganizationMember', () => { }, { id: string; memberId: string } >(MUTATION, { - variables: { id: 'org-1', memberId: '3' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862', memberId: '3' }, }); expect(errors).toBeUndefined(); @@ -1489,8 +1588,8 @@ describe('mutation updateOrganizationMemberRole', () => { await saveFixtures(con, ContentPreferenceOrganization, [ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1500,8 +1599,8 @@ describe('mutation updateOrganizationMemberRole', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1511,8 +1610,8 @@ describe('mutation updateOrganizationMemberRole', () => { }, { userId: '3', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '3', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1522,8 +1621,8 @@ describe('mutation updateOrganizationMemberRole', () => { }, { userId: '4', - referenceId: 'org-2', - organizationId: 'org-2', + referenceId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + organizationId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', feedId: '4', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1539,7 +1638,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '2', role: 'admin' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + role: 'admin', + }, }, 'UNAUTHENTICATED', )); @@ -1551,7 +1654,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-2', memberId: '2', role: 'admin' }, + variables: { + id: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + memberId: '2', + role: 'admin', + }, }, 'NOT_FOUND', ); @@ -1564,7 +1671,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '4', role: 'admin' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '4', + role: 'admin', + }, }, 'NOT_FOUND', ); @@ -1577,7 +1688,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '2', role: 'admin' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + role: 'admin', + }, }, 'FORBIDDEN', 'Access denied! You need to be a admin or higher to perform this action.', @@ -1591,7 +1706,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '1', role: 'admin' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '1', + role: 'admin', + }, }, 'FORBIDDEN', 'You cannot change your own role in the organization.', @@ -1605,7 +1724,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '1', role: 'admin' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '1', + role: 'admin', + }, }, 'FORBIDDEN', 'You cannot change the role of the owner of the organization.', @@ -1619,7 +1742,11 @@ describe('mutation updateOrganizationMemberRole', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '3', role: 'owner' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '3', + role: 'owner', + }, }, 'FORBIDDEN', 'You cannot assign the owner role to a member at this time.', @@ -1633,7 +1760,11 @@ describe('mutation updateOrganizationMemberRole', () => { { updateOrganizationMemberRole: GQLUserOrganization }, { id: string; memberId: string; role: string } >(MUTATION, { - variables: { id: 'org-1', memberId: '3', role: 'admin' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '3', + role: 'admin', + }, }); expect(errors).toBeUndefined(); @@ -1662,7 +1793,11 @@ describe('mutation updateOrganizationMemberRole', () => { { updateOrganizationMemberRole: GQLUserOrganization }, { id: string; memberId: string; role: string } >(MUTATION, { - variables: { id: 'org-1', memberId: '2', role: 'member' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + role: 'member', + }, }); expect(errors).toBeUndefined(); @@ -1728,8 +1863,8 @@ describe('mutation toggleOrganizationMemberSeat', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1739,8 +1874,8 @@ describe('mutation toggleOrganizationMemberSeat', () => { }, { userId: '2', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '2', status: ContentPreferenceOrganizationStatus.Free, flags: { @@ -1750,8 +1885,8 @@ describe('mutation toggleOrganizationMemberSeat', () => { }, { userId: '3', - referenceId: 'org-1', - organizationId: 'org-1', + referenceId: '9a212368-3388-4040-9c59-540f44c7a862', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', feedId: '3', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1761,8 +1896,8 @@ describe('mutation toggleOrganizationMemberSeat', () => { }, { userId: '4', - referenceId: 'org-2', - organizationId: 'org-2', + referenceId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + organizationId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', feedId: '4', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -1778,7 +1913,10 @@ describe('mutation toggleOrganizationMemberSeat', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '2' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + }, }, 'UNAUTHENTICATED', )); @@ -1790,7 +1928,10 @@ describe('mutation toggleOrganizationMemberSeat', () => { client, { mutation: MUTATION, - variables: { id: 'org-2', memberId: '2' }, + variables: { + id: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', + memberId: '2', + }, }, 'NOT_FOUND', ); @@ -1803,7 +1944,10 @@ describe('mutation toggleOrganizationMemberSeat', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '4' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '4', + }, }, 'NOT_FOUND', ); @@ -1816,7 +1960,10 @@ describe('mutation toggleOrganizationMemberSeat', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '1' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '1', + }, }, 'FORBIDDEN', 'Access denied! You need to be a admin or higher to perform this action.', @@ -1828,7 +1975,7 @@ describe('mutation toggleOrganizationMemberSeat', () => { await con.getRepository(User).update('2', { subscriptionFlags: updateSubscriptionFlags({ - organizationId: 'org-2', + organizationId: '5d7a9ee0-a095-44df-8a2c-6915af60ece2', cycle: 'yearly', }), }); @@ -1837,7 +1984,10 @@ describe('mutation toggleOrganizationMemberSeat', () => { client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '2' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + }, }, 'FORBIDDEN', 'You cannot toggle the seat of a member who has a Plus subscription from outside the organization.', @@ -1847,15 +1997,20 @@ describe('mutation toggleOrganizationMemberSeat', () => { it('should return forbidden when trying to assign seat when no seats are available', async () => { loggedUser = '1'; - await con.getRepository(Organization).update('org-1', { - seats: 1, - }); + await con + .getRepository(Organization) + .update('9a212368-3388-4040-9c59-540f44c7a862', { + seats: 1, + }); await testMutationErrorCode( client, { mutation: MUTATION, - variables: { id: 'org-1', memberId: '2' }, + variables: { + id: '9a212368-3388-4040-9c59-540f44c7a862', + memberId: '2', + }, }, 'FORBIDDEN', 'You cannot assign a seat to a member when the organization has reached its maximum number of seats.', @@ -1865,13 +2020,15 @@ describe('mutation toggleOrganizationMemberSeat', () => { it('should assign seat to member when seats are available', async () => { loggedUser = '1'; - await con.getRepository(Organization).update('org-1', { - seats: 5, - }); + await con + .getRepository(Organization) + .update('9a212368-3388-4040-9c59-540f44c7a862', { + seats: 5, + }); await con.getRepository(User).update('3', { subscriptionFlags: updateSubscriptionFlags({ - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', cycle: 'yearly', }), }); @@ -1880,7 +2037,7 @@ describe('mutation toggleOrganizationMemberSeat', () => { { toggleOrganizationMemberSeat: GQLUserOrganization }, { id: string; memberId: string } >(MUTATION, { - variables: { id: 'org-1', memberId: '2' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862', memberId: '2' }, }); expect(errors).toBeUndefined(); @@ -1912,13 +2069,15 @@ describe('mutation toggleOrganizationMemberSeat', () => { it('should remove seat from member when seats are available', async () => { loggedUser = '1'; - await con.getRepository(Organization).update('org-1', { - seats: 5, - }); + await con + .getRepository(Organization) + .update('9a212368-3388-4040-9c59-540f44c7a862', { + seats: 5, + }); await con.getRepository(User).update('3', { subscriptionFlags: updateSubscriptionFlags({ - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', cycle: 'yearly', }), }); @@ -1927,11 +2086,9 @@ describe('mutation toggleOrganizationMemberSeat', () => { { toggleOrganizationMemberSeat: GQLUserOrganization }, { id: string; memberId: string } >(MUTATION, { - variables: { id: 'org-1', memberId: '3' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862', memberId: '3' }, }); - console.log(JSON.stringify(data.toggleOrganizationMemberSeat, null, 2)); - expect(errors).toBeUndefined(); expect(data.toggleOrganizationMemberSeat.organization.activeSeats).toEqual( 1, @@ -1961,9 +2118,11 @@ describe('mutation toggleOrganizationMemberSeat', () => { it('should assign seat to self when not a seat user', async () => { loggedUser = '1'; - await con.getRepository(Organization).update('org-1', { - seats: 5, - }); + await con + .getRepository(Organization) + .update('9a212368-3388-4040-9c59-540f44c7a862', { + seats: 5, + }); await con.getRepository(User).update( { @@ -1971,7 +2130,7 @@ describe('mutation toggleOrganizationMemberSeat', () => { }, { subscriptionFlags: updateSubscriptionFlags({ - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', cycle: 'yearly', }), }, @@ -1981,7 +2140,7 @@ describe('mutation toggleOrganizationMemberSeat', () => { { toggleOrganizationMemberSeat: GQLUserOrganization }, { id: string; memberId: string } >(MUTATION, { - variables: { id: 'org-1', memberId: '1' }, + variables: { id: '9a212368-3388-4040-9c59-540f44c7a862', memberId: '1' }, }); expect(errors).toBeUndefined(); @@ -2052,13 +2211,13 @@ describe('mutation updateRecruiterOrganization', () => { }, ]); - // Create an opportunity linked to org-1 + // Create an opportunity linked to 9a212368-3388-4040-9c59-540f44c7a862 await con.getRepository(OpportunityJob).save({ id: oppId, state: OpportunityState.DRAFT, title: 'Test Opportunity', tldr: 'Test', - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }); // Make user 1 a recruiter for opp-1 @@ -2077,7 +2236,7 @@ describe('mutation updateRecruiterOrganization', () => { { mutation: MUTATION, variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', payload: { name: 'New Name' }, }, }, @@ -2093,7 +2252,7 @@ describe('mutation updateRecruiterOrganization', () => { { mutation: MUTATION, variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', payload: { name: 'Unauthorized Update' }, }, }, @@ -2107,7 +2266,7 @@ describe('mutation updateRecruiterOrganization', () => { const res = await client.mutate(MUTATION, { variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', payload: { name: 'Updated Corp', website: 'https://updated.dev', @@ -2141,7 +2300,7 @@ describe('mutation updateRecruiterOrganization', () => { // Verify the organization was updated in database const organization = await con .getRepository(Organization) - .findOneBy({ id: 'org-1' }); + .findOneBy({ id: '9a212368-3388-4040-9c59-540f44c7a862' }); expect(organization).toMatchObject({ name: 'Updated Corp', @@ -2158,10 +2317,10 @@ describe('mutation updateRecruiterOrganization', () => { it('should not allow duplicate organization names', async () => { loggedUser = '1'; - // Try to rename org-1 to the same name as org-2 + // Try to rename 9a212368-3388-4040-9c59-540f44c7a862 to the same name as org-2 const res = await client.mutate(MUTATION, { variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', payload: { name: 'Organization 2', // Duplicate name }, @@ -2180,7 +2339,7 @@ describe('mutation updateRecruiterOrganization', () => { // Set initial values await con.getRepository(Organization).update( - { id: 'org-1' }, + { id: '9a212368-3388-4040-9c59-540f44c7a862' }, { website: 'https://initial.dev', description: 'Initial description', @@ -2189,7 +2348,7 @@ describe('mutation updateRecruiterOrganization', () => { const res = await client.mutate(MUTATION, { variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', payload: { website: 'https://updated.dev', // description not provided - should remain unchanged @@ -2219,13 +2378,13 @@ describe('mutation clearRecruiterOrganizationImage', () => { const oppId = '550e8400-e29b-41d4-a716-446655440002'; beforeEach(async () => { - // Create an opportunity linked to org-1 + // Create an opportunity linked to 9a212368-3388-4040-9c59-540f44c7a862 await con.getRepository(OpportunityJob).save({ id: oppId, state: OpportunityState.DRAFT, title: 'Test Opportunity', tldr: 'Test', - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }); // Make user 1 a recruiter for opp-1 @@ -2244,7 +2403,7 @@ describe('mutation clearRecruiterOrganizationImage', () => { { mutation: MUTATION, variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', }, }, 'UNAUTHENTICATED', @@ -2259,7 +2418,7 @@ describe('mutation clearRecruiterOrganizationImage', () => { { mutation: MUTATION, variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', }, }, 'FORBIDDEN', @@ -2288,18 +2447,21 @@ describe('mutation clearRecruiterOrganizationImage', () => { // First set an image on the organization await con .getRepository(Organization) - .update({ id: 'org-1' }, { image: 'https://example.com/old-image.png' }); + .update( + { id: '9a212368-3388-4040-9c59-540f44c7a862' }, + { image: 'https://example.com/old-image.png' }, + ); // Verify image is set let organization = await con .getRepository(Organization) - .findOneBy({ id: 'org-1' }); + .findOneBy({ id: '9a212368-3388-4040-9c59-540f44c7a862' }); expect(organization?.image).toBe('https://example.com/old-image.png'); // Clear the image using organization ID const res = await client.mutate(MUTATION, { variables: { - id: 'org-1', + id: '9a212368-3388-4040-9c59-540f44c7a862', }, }); @@ -2309,7 +2471,7 @@ describe('mutation clearRecruiterOrganizationImage', () => { // Verify image was cleared in database organization = await con .getRepository(Organization) - .findOneBy({ id: 'org-1' }); + .findOneBy({ id: '9a212368-3388-4040-9c59-540f44c7a862' }); expect(organization?.image).toBeNull(); }); }); @@ -2334,7 +2496,7 @@ describe('mutation createOrganizationForOpportunity', () => { state: OpportunityState.DRAFT, title: 'Test Opportunity With Org', tldr: 'Test', - organizationId: 'org-1', + organizationId: '9a212368-3388-4040-9c59-540f44c7a862', }); // Create an opportunity without an organization diff --git a/__tests__/private.ts b/__tests__/private.ts index 74388041b2..da2d36cf0f 100644 --- a/__tests__/private.ts +++ b/__tests__/private.ts @@ -1213,7 +1213,7 @@ describe('POST /p/newOpportunity', () => { beforeEach(async () => { await saveFixtures(con, Organization, [ { - id: 'org-1', + id: '14e9a766-1d22-4b90-8929-7876e315c06a', seats: 1, name: 'Organization 1', subscriptionFlags: { @@ -1253,7 +1253,7 @@ describe('POST /p/newOpportunity', () => { const opportunityData = { title: 'Senior Software Engineer', tldr: 'Join our team to build amazing products', - organizationId: 'org-1', + organizationId: '14e9a766-1d22-4b90-8929-7876e315c06a', keywords: [ { keyword: 'javascript' }, { keyword: 'typescript' }, @@ -1294,7 +1294,9 @@ describe('POST /p/newOpportunity', () => { expect(opportunity?.tldr).toEqual( 'Join our team to build amazing products', ); - expect(opportunity?.organizationId).toEqual('org-1'); + expect(opportunity?.organizationId).toEqual( + '14e9a766-1d22-4b90-8929-7876e315c06a', + ); expect(opportunity?.state).toEqual(1); expect(opportunity?.type).toEqual(1); @@ -1332,7 +1334,7 @@ describe('POST /p/newOpportunity', () => { const opportunityData = { title: 'Backend Engineer', tldr: 'Work on distributed systems', - organizationId: 'org-1', + organizationId: '14e9a766-1d22-4b90-8929-7876e315c06a', keywords: [{ keyword: 'golang' }, { keyword: 'kubernetes' }], meta: { employmentType: 1, diff --git a/__tests__/workers/cdc/primary.ts b/__tests__/workers/cdc/primary.ts index b957795163..9424ab589b 100644 --- a/__tests__/workers/cdc/primary.ts +++ b/__tests__/workers/cdc/primary.ts @@ -6627,7 +6627,7 @@ describe('opportunity', () => { content: [], meta: {}, state: OpportunityState.DRAFT, - organizationId: 'org-1', + organizationId: 'b76a7a19-e9c6-4651-8c2a-a51c33219793', }, op: 'c', table: 'opportunity', @@ -6651,7 +6651,7 @@ describe('opportunity', () => { content: [], meta: {}, state: OpportunityState.LIVE, - organizationId: 'org-1', + organizationId: 'b76a7a19-e9c6-4651-8c2a-a51c33219793', }, op: 'c', table: 'opportunity', @@ -6675,7 +6675,7 @@ describe('opportunity', () => { content: [], meta: {}, state: OpportunityState.LIVE, - organizationId: 'org-1', + organizationId: 'b76a7a19-e9c6-4651-8c2a-a51c33219793', }, op: 'u', table: 'opportunity', @@ -6708,7 +6708,7 @@ describe('opportunity', () => { content: [], meta: {}, state: OpportunityState.DRAFT, - organizationId: 'org-1', + organizationId: 'b76a7a19-e9c6-4651-8c2a-a51c33219793', }, op: 'u', table: 'opportunity', @@ -6732,7 +6732,7 @@ describe('opportunity', () => { content: [], meta: {}, state: OpportunityState.LIVE, - organizationId: 'org-1', + organizationId: 'b76a7a19-e9c6-4651-8c2a-a51c33219793', }, op: 'u', table: 'opportunity', @@ -6770,7 +6770,7 @@ describe('opportunity', () => { content: [], meta: {}, state: OpportunityState.DRAFT, - organizationId: 'org-1', + organizationId: 'b76a7a19-e9c6-4651-8c2a-a51c33219793', }, op: 'u', table: 'opportunity', diff --git a/__tests__/workers/notifications/recruiterExternalPaymentNotification.ts b/__tests__/workers/notifications/recruiterExternalPaymentNotification.ts index 64db9b285f..437f7fad2a 100644 --- a/__tests__/workers/notifications/recruiterExternalPaymentNotification.ts +++ b/__tests__/workers/notifications/recruiterExternalPaymentNotification.ts @@ -34,7 +34,7 @@ describe('recruiterExternalPaymentNotification worker', () => { it('should send notification to all recruiters when external payment is made', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org-ext-pay-1', + id: '98176fb1-34cc-43a5-8924-9fdc7106e615', name: 'Test Organization', }); @@ -98,7 +98,7 @@ describe('recruiterExternalPaymentNotification worker', () => { it('should return empty array when no recruiters found', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org-ext-pay-2', + id: '541d282c-d445-4b65-8cfb-1472b415df6d', name: 'Another Organization', }); diff --git a/__tests__/workers/notifications/recruiterNewCandidateNotification.ts b/__tests__/workers/notifications/recruiterNewCandidateNotification.ts index b36872afa7..18a8c43a4c 100644 --- a/__tests__/workers/notifications/recruiterNewCandidateNotification.ts +++ b/__tests__/workers/notifications/recruiterNewCandidateNotification.ts @@ -35,7 +35,7 @@ describe('recruiterNewCandidateNotification worker', () => { it('should send notification to all recruiters when candidate accepts', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org123', + id: 'ea674f55-ab85-458c-9335-ad29d42fde1e', name: 'Test Organization', }); @@ -104,7 +104,7 @@ describe('recruiterNewCandidateNotification worker', () => { it('should return empty array when no recruiters found', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org456', + id: '63197362-8a95-455e-ab32-8b2205ca5f90', name: 'Another Organization', }); diff --git a/__tests__/workers/notifications/recruiterOpportunityLiveNotification.ts b/__tests__/workers/notifications/recruiterOpportunityLiveNotification.ts index e7d317068b..7ade79d3f8 100644 --- a/__tests__/workers/notifications/recruiterOpportunityLiveNotification.ts +++ b/__tests__/workers/notifications/recruiterOpportunityLiveNotification.ts @@ -34,7 +34,7 @@ describe('recruiterOpportunityLiveNotification worker', () => { it('should send notification to all recruiters when opportunity goes live', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org123', + id: 'fa7a93b2-52d2-47bc-b97c-b479f9cf4ff9', name: 'Test Organization', }); @@ -101,7 +101,7 @@ describe('recruiterOpportunityLiveNotification worker', () => { it('should return empty array when no recruiters found', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org456', + id: '91e23aba-5940-4b9e-a857-0f2dfbeedc5c', name: 'Another Organization', }); diff --git a/__tests__/workers/notifications/warmIntroNotification.ts b/__tests__/workers/notifications/warmIntroNotification.ts index 67070c38a3..23d9de7d52 100644 --- a/__tests__/workers/notifications/warmIntroNotification.ts +++ b/__tests__/workers/notifications/warmIntroNotification.ts @@ -42,7 +42,7 @@ describe('warmIntroNotification worker', () => { it('should send notification with all required fields', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org123', + id: 'e34d0a84-89ea-4ba3-ba6e-1b8fe9ac952f', name: 'Test Organization', image: 'https://example.com/org.png', }); @@ -102,7 +102,7 @@ describe('warmIntroNotification worker', () => { ); expect(context.organization).toEqual( expect.objectContaining({ - id: 'org123', + id: 'e34d0a84-89ea-4ba3-ba6e-1b8fe9ac952f', name: 'Test Organization', image: 'https://example.com/org.png', }), @@ -111,7 +111,7 @@ describe('warmIntroNotification worker', () => { it('should handle missing recruiter gracefully', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org456', + id: '0672bc0f-93c0-43a0-ad8a-ca6ba89428d4', name: 'Another Organization', image: 'https://example.com/another-org.png', }); @@ -151,7 +151,7 @@ describe('warmIntroNotification worker', () => { expect(context.recruiter).toBeUndefined(); expect(context.organization).toEqual( expect.objectContaining({ - id: 'org456', + id: '0672bc0f-93c0-43a0-ad8a-ca6ba89428d4', name: 'Another Organization', }), ); @@ -187,7 +187,7 @@ describe('warmIntroNotification worker', () => { it('should handle missing optional description', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org789', + id: 'c6d40f37-af7e-43ba-af90-9f31d6645037', name: 'Test Org', }); @@ -226,7 +226,7 @@ describe('warmIntroNotification worker', () => { it('should convert markdown description to HTML in applicationRank', async () => { const organization = await con.getRepository(Organization).save({ - id: 'org999', + id: '439c472a-b339-4d47-8a75-6f8669c56d27', name: 'Test Company', }); diff --git a/__tests__/workers/organization/organizationUserLeft.ts b/__tests__/workers/organization/organizationUserLeft.ts index 5ac288a9d0..904689be12 100644 --- a/__tests__/workers/organization/organizationUserLeft.ts +++ b/__tests__/workers/organization/organizationUserLeft.ts @@ -38,7 +38,7 @@ describe('organizationUserLeft worker', () => { await saveFixtures(con, Organization, [ { - id: 'our-org-1', + id: '1cf163f2-8099-41c7-841a-8aaace2513be', seats: 1, name: 'Organization 1', subscriptionFlags: { @@ -47,7 +47,7 @@ describe('organizationUserLeft worker', () => { }, }, { - id: 'our-org-2', + id: 'c1226c42-fa24-4007-a990-91af8dab75a0', seats: 1, name: 'Organization 2', subscriptionFlags: { @@ -71,8 +71,8 @@ describe('organizationUserLeft worker', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'our-org-1', - organizationId: 'our-org-1', + referenceId: '1cf163f2-8099-41c7-841a-8aaace2513be', + organizationId: '1cf163f2-8099-41c7-841a-8aaace2513be', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -82,8 +82,8 @@ describe('organizationUserLeft worker', () => { }, { userId: '2', - referenceId: 'our-org-1', - organizationId: 'our-org-1', + referenceId: '1cf163f2-8099-41c7-841a-8aaace2513be', + organizationId: '1cf163f2-8099-41c7-841a-8aaace2513be', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -93,8 +93,8 @@ describe('organizationUserLeft worker', () => { }, { userId: '2', - referenceId: 'our-org-2', - organizationId: 'our-org-2', + referenceId: 'c1226c42-fa24-4007-a990-91af8dab75a0', + organizationId: 'c1226c42-fa24-4007-a990-91af8dab75a0', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -134,7 +134,7 @@ describe('organizationUserLeft worker', () => { const warnSpy = jest.spyOn(logger, 'error'); await expectSuccessfulTypedBackground(worker, { - organizationId: 'our-org-1', + organizationId: '1cf163f2-8099-41c7-841a-8aaace2513be', memberId: '87b79108-d258-42d2-b38a-4a02974746cc', }); @@ -151,14 +151,14 @@ describe('organizationUserLeft worker', () => { const warnSpy = jest.spyOn(logger, 'error'); await expectSuccessfulTypedBackground(worker, { - organizationId: 'our-org-2', + organizationId: 'c1226c42-fa24-4007-a990-91af8dab75a0', memberId: '2', }); expect(sendEmail).not.toHaveBeenCalled(); expect(warnSpy).toHaveBeenCalledWith( { - organizationId: 'our-org-2', + organizationId: 'c1226c42-fa24-4007-a990-91af8dab75a0', userId: '2', }, 'No owner found for organization', @@ -169,7 +169,7 @@ describe('organizationUserLeft worker', () => { const user = usersFixture[0]; await expectSuccessfulTypedBackground(worker, { - organizationId: 'our-org-1', + organizationId: '1cf163f2-8099-41c7-841a-8aaace2513be', memberId: '1', }); @@ -181,7 +181,9 @@ describe('organizationUserLeft worker', () => { message_data: { organization: { name: 'Organization 1', - href: getOrganizationPermalink({ id: 'our-org-1' }), + href: getOrganizationPermalink({ + id: '1cf163f2-8099-41c7-841a-8aaace2513be', + }), }, member: { name: user.name, diff --git a/__tests__/workers/organization/organizationUserRemoved.ts b/__tests__/workers/organization/organizationUserRemoved.ts index 1c509c61ca..326201f68f 100644 --- a/__tests__/workers/organization/organizationUserRemoved.ts +++ b/__tests__/workers/organization/organizationUserRemoved.ts @@ -37,7 +37,7 @@ describe('organizationUserRemoved worker', () => { await saveFixtures(con, Organization, [ { - id: 'our-org-1', + id: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', seats: 1, name: 'Organization 1', subscriptionFlags: { @@ -46,7 +46,7 @@ describe('organizationUserRemoved worker', () => { }, }, { - id: 'our-org-2', + id: '2b243220-ca5a-44c5-957e-47743243e995', seats: 1, name: 'Organization 2', subscriptionFlags: { @@ -70,8 +70,8 @@ describe('organizationUserRemoved worker', () => { await con.getRepository(ContentPreferenceOrganization).save([ { userId: '1', - referenceId: 'our-org-1', - organizationId: 'our-org-1', + referenceId: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', + organizationId: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', feedId: '1', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -81,8 +81,8 @@ describe('organizationUserRemoved worker', () => { }, { userId: '2', - referenceId: 'our-org-1', - organizationId: 'our-org-1', + referenceId: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', + organizationId: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -92,8 +92,8 @@ describe('organizationUserRemoved worker', () => { }, { userId: '2', - referenceId: 'our-org-2', - organizationId: 'our-org-2', + referenceId: '2b243220-ca5a-44c5-957e-47743243e995', + organizationId: '2b243220-ca5a-44c5-957e-47743243e995', feedId: '2', status: ContentPreferenceOrganizationStatus.Plus, flags: { @@ -133,7 +133,7 @@ describe('organizationUserRemoved worker', () => { const warnSpy = jest.spyOn(logger, 'error'); await expectSuccessfulTypedBackground(worker, { - organizationId: 'our-org-1', + organizationId: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', memberId: '87b79108-d258-42d2-b38a-4a02974746cc', }); @@ -150,7 +150,7 @@ describe('organizationUserRemoved worker', () => { const user = usersFixture[0]; await expectSuccessfulTypedBackground(worker, { - organizationId: 'our-org-1', + organizationId: '8d02f0a0-6c44-40e9-9c40-80bc8e8cc2e8', memberId: '1', }); diff --git a/src/entity/Organization.ts b/src/entity/Organization.ts index 65369050c7..fe3039729a 100644 --- a/src/entity/Organization.ts +++ b/src/entity/Organization.ts @@ -7,7 +7,7 @@ import { JoinColumn, ManyToOne, OneToMany, - PrimaryColumn, + PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm'; import type { ContentPreferenceOrganization } from './contentPreference/ContentPreferenceOrganization'; @@ -25,10 +25,8 @@ export type OrganizationLink = z.infer; @Index('IDX_organization_subflags_subscriptionid', { synchronize: false }) @Index('IDX_organization_trial_expires_at', { synchronize: false }) export class Organization { - @PrimaryColumn({ - type: 'text', + @PrimaryGeneratedColumn('uuid', { primaryKeyConstraintName: 'PK_organization_organization_id', - default: () => 'uuid_generate_v4()', }) id: string; diff --git a/src/entity/contentPreference/ContentPreferenceOrganization.ts b/src/entity/contentPreference/ContentPreferenceOrganization.ts index 574b297f96..7bcc857f77 100644 --- a/src/entity/contentPreference/ContentPreferenceOrganization.ts +++ b/src/entity/contentPreference/ContentPreferenceOrganization.ts @@ -16,7 +16,7 @@ export type ContentPreferenceOrganizationFlags = Partial<{ @ChildEntity(ContentPreferenceType.Organization) export class ContentPreferenceOrganization extends ContentPreference { - @Column({ type: 'text', default: null }) + @Column({ type: 'uuid', default: null }) @Index('IDX_content_preference_organization_id') organizationId: string; diff --git a/src/entity/opportunities/OpportunityJob.ts b/src/entity/opportunities/OpportunityJob.ts index a253cedd08..59bced3ac2 100644 --- a/src/entity/opportunities/OpportunityJob.ts +++ b/src/entity/opportunities/OpportunityJob.ts @@ -5,7 +5,7 @@ import type { Organization } from '../Organization'; @ChildEntity(OpportunityType.JOB) export class OpportunityJob extends Opportunity { - @Column({ type: 'text', nullable: true }) + @Column({ type: 'uuid', nullable: true }) @Index('IDX_opportunity_organization_id') organizationId: string | null; diff --git a/src/migration/1761823015246-OrganizationIdUUID.ts b/src/migration/1761823015246-OrganizationIdUUID.ts new file mode 100644 index 0000000000..c2c8a1c953 --- /dev/null +++ b/src/migration/1761823015246-OrganizationIdUUID.ts @@ -0,0 +1,93 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class OrganizationIdUUID1761823015246 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(/* sql */ ` + ALTER TABLE "content_preference" + DROP CONSTRAINT "FK_content_preference_organization_id" + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "opportunity" + DROP CONSTRAINT "FK_opportunity_organization_id" + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "organization" + ALTER COLUMN "id" TYPE uuid USING "id"::uuid + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "opportunity" + ALTER COLUMN "organizationId" TYPE uuid USING "organizationId"::uuid + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "content_preference" + ALTER COLUMN "organizationId" TYPE uuid USING "organizationId"::uuid + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "opportunity" + ADD CONSTRAINT "FK_opportunity_organization_id" + FOREIGN KEY ("organizationId") + REFERENCES "organization"("id") + ON DELETE CASCADE + ON UPDATE NO ACTION + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "content_preference" + ADD CONSTRAINT "FK_content_preference_organization_id" + FOREIGN KEY ("organizationId") + REFERENCES "organization"("id") + ON DELETE CASCADE + ON UPDATE NO ACTION + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(/* sql */ ` + ALTER TABLE "content_preference" + DROP CONSTRAINT "FK_content_preference_organization_id" + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "opportunity" + DROP CONSTRAINT "FK_opportunity_organization_id" + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "organization" + ALTER COLUMN "id" TYPE text USING "id"::text + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "opportunity" + ALTER COLUMN "organizationId" TYPE text USING "organizationId"::text + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "content_preference" + ALTER COLUMN "organizationId" TYPE text USING "organizationId"::text + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "opportunity" + ADD CONSTRAINT "FK_opportunity_organization_id" + FOREIGN KEY ("organizationId") + REFERENCES "organization"("id") + ON DELETE CASCADE + ON UPDATE NO ACTION + `); + + await queryRunner.query(/* sql */ ` + ALTER TABLE "content_preference" + ADD CONSTRAINT "FK_content_preference_organization_id" + FOREIGN KEY ("organizationId") + REFERENCES "organization"("id") + ON DELETE CASCADE + ON UPDATE NO ACTION + `); + } +}