Drive approval card details from requestTypeFields.json, fix Service Request type 382→194, and add discovery tooling plus tests. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
3.2 KiB
JavaScript
86 lines
3.2 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
buildDetailLinesForRequestType,
|
|
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('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'
|
|
);
|
|
});
|
|
});
|
|
|
|
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');
|
|
});
|
|
});
|