diff --git a/src/apps/engagements/src/lib/utils/terms.utils.spec.ts b/src/apps/engagements/src/lib/utils/terms.utils.spec.ts index a8c36079b..d92815f62 100644 --- a/src/apps/engagements/src/lib/utils/terms.utils.spec.ts +++ b/src/apps/engagements/src/lib/utils/terms.utils.spec.ts @@ -37,9 +37,18 @@ describe('engagement terms utils', () => { }) }) - it('prefers the configured DocuSign template for NDA terms', () => { + it('prefers the Terms API DocuSign template for NDA terms', () => { expect(resolveDocuSignTemplateId({ - docusignTemplateId: 'old-template-id', + agreeabilityType: 'DocuSignable', + docusignTemplateId: 'terms-api-template-id', + title: 'Topcoder Member Non-Disclosure Agreement v3.0', + }, NEW_NDA_TEMPLATE_ID)) + .toBe('terms-api-template-id') + }) + + it('falls back to the configured DocuSign template for DocuSign-backed NDA terms', () => { + expect(resolveDocuSignTemplateId({ + agreeabilityType: 'Docusign-template', title: 'Topcoder Member Non-Disclosure Agreement v3.0', }, NEW_NDA_TEMPLATE_ID)) .toBe(NEW_NDA_TEMPLATE_ID) @@ -52,4 +61,12 @@ describe('engagement terms utils', () => { }, NEW_NDA_TEMPLATE_ID)) .toBe('assignment-template-id') }) + + it('does not use the configured DocuSign template for electronically agreeable NDA terms', () => { + expect(resolveDocuSignTemplateId({ + agreeabilityType: 'Electronically-agreeable', + title: 'Topcoder Member Non-Disclosure Agreement v3.0', + }, NEW_NDA_TEMPLATE_ID)) + .toBeUndefined() + }) }) diff --git a/src/apps/engagements/src/lib/utils/terms.utils.ts b/src/apps/engagements/src/lib/utils/terms.utils.ts index 499ac3d36..3edad862a 100644 --- a/src/apps/engagements/src/lib/utils/terms.utils.ts +++ b/src/apps/engagements/src/lib/utils/terms.utils.ts @@ -4,10 +4,12 @@ export type ResolvedTermsConfig = { } type TermsTemplateDetails = { + agreeabilityType?: string docusignTemplateId?: string | number title?: string } +const DOCUSIGN_AGREEABILITY_PATTERN = /docusign/i const NDA_TITLE_PATTERN = /\bnda\b|non[-\s]?disclosure/i /** @@ -117,18 +119,30 @@ export const isNdaTerm = (term?: TermsTemplateDetails): boolean => ( * Resolves the DocuSign template id for a terms record. * * @param term - Terms API details or search result payload. - * @param configuredNdaTemplateId - Preferred DocuSign template id for NDA terms. - * @returns The configured NDA template id for NDA terms, otherwise the Terms API template id. + * @param configuredNdaTemplateId - Fallback DocuSign template id for DocuSign-backed + * NDA terms missing one from the API. + * @returns The Terms API DocuSign template id, or the configured fallback for DocuSign-backed NDA terms. */ export const resolveDocuSignTemplateId = ( term?: TermsTemplateDetails, configuredNdaTemplateId?: string, ): string | number | undefined => { + const termTemplateId = typeof term?.docusignTemplateId === 'string' + ? term.docusignTemplateId.trim() + : term?.docusignTemplateId + + if (termTemplateId) { + return termTemplateId + } + const normalizedConfiguredNdaTemplateId = configuredNdaTemplateId?.trim() + const isDocuSignBackedTerm = DOCUSIGN_AGREEABILITY_PATTERN.test( + term?.agreeabilityType ?? '', + ) - if (normalizedConfiguredNdaTemplateId && isNdaTerm(term)) { + if (normalizedConfiguredNdaTemplateId && isNdaTerm(term) && isDocuSignBackedTerm) { return normalizedConfiguredNdaTemplateId } - return term?.docusignTemplateId + return undefined } diff --git a/src/config/environments/prod.env.ts b/src/config/environments/prod.env.ts index 5127275df..a77197a19 100644 --- a/src/config/environments/prod.env.ts +++ b/src/config/environments/prod.env.ts @@ -7,7 +7,7 @@ export const TERMS_URL = 'https://www.topcoder.com/challenges/terms/detail/564a9 export const NDA_TERMS_URL = 'https://www.topcoder.com/challenges/terms/detail/c41e90e5-4d0e-4811-bd09-38ff72674490' export const NDA_DOCUSIGN_TEMPLATE_ID = getReactEnv( 'NDA_DOCUSIGN_TEMPLATE_ID', - '8b101e82-87c0-42c9-8440-d922749c4076', + '00c3be8d-4b81-4dc3-a888-d6f07e69c70f', ) export const VANILLA_FORUM = {