|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * [ADR-0162 Execution item 7] The lead of the refusal at an approval's first |
| 5 | + * request says the object closes on its approval field only where a gap is |
| 6 | + * about that field. The host's gap (`no_job_service`) and a flow that could |
| 7 | + * not be read (`unreadable_flow`) are raised on an object that declares |
| 8 | + * `closedStates` on any field, so where they are the only gaps the lead says |
| 9 | + * what is true in every case: the approval can act on an object that declares |
| 10 | + * `closedStates`. |
| 11 | + * |
| 12 | + * The expected sentences are read from the catalog, not written out here: what |
| 13 | + * these tests hold is WHICH lead is chosen, and in which pack; the wording is |
| 14 | + * the catalog's, and `approval-notification-keyed-text.integration.test.ts` holds every locale |
| 15 | + * to the same ids and holes. |
| 16 | + */ |
| 17 | + |
| 18 | +import { describe, expect, it } from 'vitest'; |
| 19 | +import { interpolate } from './approval-notification-text.js'; |
| 20 | +import type { OpeningGap } from './approval-opening-check.js'; |
| 21 | +import { openingRefusalText } from './approval-opening-refusal.js'; |
| 22 | +import { approvalMessages } from './translations/messages.js'; |
| 23 | + |
| 24 | +const subject = { object: 'crm_deal', record: 'd1' }; |
| 25 | +type Locale = keyof typeof approvalMessages; |
| 26 | +const fieldLead = (locale: Locale) => interpolate(approvalMessages[locale].approvalOpeningRefusedLead, subject); |
| 27 | +const neutralLead = (locale: Locale) => interpolate(approvalMessages[locale].approvalOpeningRefusedClosedStatesLead, subject); |
| 28 | +const sentence = (gap: OpeningGap, id: 'approvalOpeningNoJobService' | 'approvalOpeningUnreadableFlow') => { |
| 29 | + const { kind: _kind, ...params } = gap; |
| 30 | + return interpolate(approvalMessages.en[id], params as Record<string, string>); |
| 31 | +}; |
| 32 | + |
| 33 | +const host: OpeningGap = { kind: 'no_job_service', object: 'crm_deal' }; |
| 34 | +const unreadable: OpeningGap = { kind: 'unreadable_flow', flow: 'deal_sub' }; |
| 35 | +const pause: OpeningGap = { kind: 'pause_between_steps', flow: 'deal_flow', node: 'hold', type: 'wait', object: 'crm_deal' }; |
| 36 | + |
| 37 | +describe('the opening refusal: its lead', () => { |
| 38 | + it('the two leads are two sentences, in every pack', () => { |
| 39 | + for (const locale of Object.keys(approvalMessages) as Locale[]) { |
| 40 | + expect(neutralLead(locale), locale).not.toBe(fieldLead(locale)); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + it('does not say the object closes on its approval field where the host\'s gap is the only one', () => { |
| 45 | + const text = openingRefusalText([host], subject, 'en'); |
| 46 | + expect(text).toBe(`${neutralLead('en')} ${sentence(host, 'approvalOpeningNoJobService')}`); |
| 47 | + }); |
| 48 | + |
| 49 | + it('does not say it where a flow that could not be read is the only gap', () => { |
| 50 | + const text = openingRefusalText([unreadable], subject, 'en'); |
| 51 | + expect(text).toBe(`${neutralLead('en')} ${sentence(unreadable, 'approvalOpeningUnreadableFlow')}`); |
| 52 | + }); |
| 53 | + |
| 54 | + it('does not say it where the host\'s gap and an unreadable flow are the only gaps', () => { |
| 55 | + const text = openingRefusalText([unreadable, host], subject, 'en'); |
| 56 | + expect(text.startsWith(`${neutralLead('en')} `)).toBe(true); |
| 57 | + expect(text).not.toContain(fieldLead('en')); |
| 58 | + }); |
| 59 | + |
| 60 | + it('says it where a gap is about the field, alone or beside the host\'s', () => { |
| 61 | + expect(openingRefusalText([pause], subject, 'en').startsWith(`${fieldLead('en')} `)).toBe(true); |
| 62 | + expect(openingRefusalText([pause, host], subject, 'en').startsWith(`${fieldLead('en')} `)).toBe(true); |
| 63 | + expect(openingRefusalText([host, pause], subject, 'en').startsWith(`${fieldLead('en')} `)).toBe(true); |
| 64 | + }); |
| 65 | + |
| 66 | + it('words the lead that says nothing about the field in the run\'s locale', () => { |
| 67 | + const text = openingRefusalText([host], subject, 'zh-CN'); |
| 68 | + expect(text.startsWith(`${neutralLead('zh-CN')} `)).toBe(true); |
| 69 | + expect(text).not.toContain(fieldLead('zh-CN')); |
| 70 | + expect(neutralLead('zh-CN')).not.toBe(neutralLead('en')); |
| 71 | + }); |
| 72 | +}); |
0 commit comments