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
13 changes: 8 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,22 @@ function displayIssueDetails(issue) {
// Build JQL query from options
function buildJQL(options) {
const conditions = [];

if (options.project) {
conditions.push(`project = "${options.project}"`);
}

if (options.assignee) {
conditions.push(`assignee = "${options.assignee}"`);
const assigneeValue = options.assignee === 'currentUser'
? 'currentUser()'
: `"${options.assignee}"`;
conditions.push(`assignee = ${assigneeValue}`);
}

if (options.status) {
conditions.push(`status = "${options.status}"`);
}

return conditions.length > 0 ? conditions.join(' AND ') : 'ORDER BY updated DESC';
}

Expand Down
52 changes: 50 additions & 2 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,64 @@ describe('Utils', () => {
];

const table = Utils.createIssuesTable(mockIssues);

expect(table).toBeDefined();
expect(typeof table.toString).toBe('function');
});

it('should handle empty issues array', () => {
const table = Utils.createIssuesTable([]);

expect(table).toBeDefined();
expect(typeof table.toString).toBe('function');
});
});

describe('buildJQL', () => {
it('should build JQL with project filter', () => {
const options = { project: 'TEST' };
const jql = Utils.buildJQL(options);

expect(jql).toBe('project = "TEST"');
});

it('should build JQL with currentUser assignee', () => {
const options = { assignee: 'currentUser' };
const jql = Utils.buildJQL(options);

expect(jql).toBe('assignee = currentUser()');
});

it('should build JQL with specific user assignee', () => {
const options = { assignee: 'john.doe' };
const jql = Utils.buildJQL(options);

expect(jql).toBe('assignee = "john.doe"');
});

it('should build JQL with status filter', () => {
const options = { status: 'In Progress' };
const jql = Utils.buildJQL(options);

expect(jql).toBe('status = "In Progress"');
});

it('should build JQL with multiple filters', () => {
const options = {
project: 'TEST',
assignee: 'currentUser',
status: 'Open'
};
const jql = Utils.buildJQL(options);

expect(jql).toBe('project = "TEST" AND assignee = currentUser() AND status = "Open"');
});

it('should return default ORDER BY when no filters', () => {
const options = {};
const jql = Utils.buildJQL(options);

expect(jql).toBe('ORDER BY updated DESC');
});
});
});