Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/apps/engagements/src/lib/utils/terms.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
})
})
22 changes: 18 additions & 4 deletions src/apps/engagements/src/lib/utils/terms.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/config/environments/prod.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(
'NDA_DOCUSIGN_TEMPLATE_ID',
'8b101e82-87c0-42c9-8440-d922749c4076',
'00c3be8d-4b81-4dc3-a888-d6f07e69c70f',
)

export const VANILLA_FORUM = {
Expand Down
Loading