jiraCloud/test/requestTypeFields.test.js
jmcqueen 781b238a5b Simplify approval card workflow fields and format times in Eastern.
Remove moved-by and from-status, rename to-status to Status, and show Created/Updated in America/New_York with EDT/EST.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 13:24:18 -04:00

95 lines
3.5 KiB
JavaScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import {
buildDetailLinesForRequestType,
formatEasternDateTime,
formatFieldValue,
getDisplayFieldsForRequestType,
} from '../lib/requestTypeFields.js';
const sampleTicket = {
transition: {
transitionName: 'Manager Approval',
from_status: 'New Request',
to_status: 'Pending Approval',
},
user: { displayName: 'Automation for Jira' },
issue: {
fields: {
priority: { value: 'Medium' },
reporter: { displayName: 'Savannah Davis' },
customfield_10346: 'Davis',
customfield_10314: 'Savannah',
customfield_10318: 'Analyst',
customfield_10310: { value: 'Full Time' },
customfield_10353: [{ label: 'IT Operations' }],
summary: 'Application Access for Savannah Davis',
},
},
};
describe('getDisplayFieldsForRequestType', () => {
it('returns fields for Application Access including common and groups', () => {
const fields = getDisplayFieldsForRequestType('209');
const labels = fields.map(f => f.label);
assert.ok(!labels.includes('Reporter'));
assert.ok(labels.includes('First name'));
assert.ok(labels.includes('IT'));
});
it('returns change management fields for request type 177', () => {
const fields = getDisplayFieldsForRequestType('177');
const labels = fields.map(f => f.label);
assert.ok(labels.includes('Rollback plan'));
assert.ok(labels.includes('Implementation date'));
});
it('uses summaryOnly for legacy single-field forms', () => {
const fields = getDisplayFieldsForRequestType('211');
const labels = fields.map(f => f.label);
assert.ok(labels.includes('Description'));
assert.ok(!labels.includes('Summary'));
assert.ok(!labels.includes('First name'));
});
it('returns Service Request fields for request type 194', () => {
const fields = getDisplayFieldsForRequestType('194');
const labels = fields.map(f => f.label);
assert.ok(labels.includes('Department'));
assert.ok(labels.includes('Reason for request'));
assert.ok(!labels.includes('First name'));
});
});
describe('formatFieldValue', () => {
it('formats option and user values', () => {
assert.equal(formatFieldValue({ value: 'High' }, 'option'), 'High');
assert.equal(formatFieldValue({ displayName: 'Jane Doe' }, 'user'), 'Jane Doe');
});
it('formats cmdb arrays', () => {
assert.equal(
formatFieldValue([{ label: 'Store 123' }, { label: 'Store 456' }], 'cmdb'),
'Store 123, Store 456'
);
});
it('formats datetimes in Eastern time', () => {
const formatted = formatFieldValue('2026-07-28T20:33:16.000Z', 'datetime');
assert.match(formatted, /EDT|EST/);
assert.match(formatted, /7\/28\/2026/);
assert.doesNotMatch(formatted, /20:33:16/);
});
});
describe('buildDetailLinesForRequestType', () => {
it('builds populated lines from webhook payload', () => {
const lines = buildDetailLinesForRequestType(sampleTicket, '209');
const byLabel = Object.fromEntries(lines.map(line => [line.label, line.value]));
assert.equal(byLabel['Approval step'], 'Manager Approval');
assert.equal(byLabel['First name'], 'Savannah');
assert.equal(byLabel['Position/Title'], 'Analyst');
assert.equal(byLabel.Department, 'IT Operations');
});
});