Skip to content

Set Content-Type in issueBulkOperations.submitBulkTransition to work around api issue #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"library"
],
"scripts": {
"build": "tsc",
"build": "npm run build:src && npm run build:tests",
"build:src": "tsc --project tsconfig.json",
"build:tests": "tsc --project tests/tsconfig.json",
"prettier": "prettier --write src",
"lint": "npm run lint:tests && npm run lint:examples && npm run lint:src:agile && npm run lint:src:clients && npm run lint:src:services && npm run lint:src:version2 && npm run lint:src:version3 && npm run lint:src:files",
"lint:tests": "npm run lint:base -- tests",
Expand Down
3 changes: 3 additions & 0 deletions src/version3/issueBulkOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ export class IssueBulkOperations {
endingBefore: parameters.endingBefore,
startingAfter: parameters.startingAfter,
},
headers: {
'Content-Type': 'application/json',
},
};

return this.client.sendRequest(config, callback);
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from '@tests/constants';
export * as Utils from '@tests/utils';
export * from '@tests/integration/constants';
export * as Utils from '@tests/integration/utils';
8 changes: 7 additions & 1 deletion tests/integration/utils/createSoftwareProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export const createSoftwareProject = async () => {
const client = getVersion2Client();
const currentUser = await client.myself.getCurrentUser();

if (!currentUser.accountId) throw new Error("Couldn't get the current user's account ID", { cause: { currentUser } });
if (!currentUser.accountId) {
throw new Error(
"Couldn't get the current user's account ID",
// @ts-expect-error -- Requires to use lib ES2022+ in tsconfig to use "cause"
{ cause: { currentUser } },
);
}

return client.projects
.createProject({
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/version2/issueComments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.sequential('should update comment', async ({ expect }) => {

const updatedComment = await client.issueComments.updateComment({
issueIdOrKey: issue.key,
id: comment.id,
id: comment.id!,
comment: 'updated comment',
});

Expand Down
75 changes: 75 additions & 0 deletions tests/integration/version3/issueBulkOperations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { afterAll, beforeAll, test } from 'vitest';
import { Constants } from '@tests/integration/constants';
import { cleanupEnvironment, getVersion3Client, prepareEnvironment } from '@tests/integration/utils';
import { CreatedIssue } from '@jirajs/version3/models';

const client = getVersion3Client();
let createdIssues: CreatedIssue[] = [];

beforeAll(async () => {
await prepareEnvironment();
});

afterAll(async () => {
await cleanupEnvironment();
});

test.sequential('should create test issues', async ({ expect }) => {
function createIssue(num: number) {
return client.issues.createIssue({
fields: {
summary: `${Constants.testIssueSummary} ${num}`,
issuetype: { name: 'Task' },
project: { key: Constants.testProjectKey },
description: {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
text: `${Constants.testIssueDescription} ${num}`,
type: 'text',
},
],
},
],
},
},
});
}

createdIssues = await Promise.all([createIssue(1), createIssue(2)]);

expect(createdIssues).toHaveLength(2);
expect(createdIssues[0].key).toContain(Constants.testProjectKey);
expect(createdIssues[1].key).toContain(Constants.testProjectKey);
});

test.sequential('should get available transitions for multiple issues', async ({ expect }) => {
const result = await client.issueBulkOperations.getAvailableTransitions({
issueIdsOrKeys: createdIssues.map(issue => issue.key),
});

expect(result).toBeDefined();
expect(result.availableTransitions).toBeDefined();
expect(Array.isArray(result.availableTransitions)).toBeTruthy();

if (result.availableTransitions && result.availableTransitions.length > 0) {
const firstWorkflow = result.availableTransitions[0];

expect(Array.isArray(firstWorkflow.transitions)).toBeTruthy();
expect(Array.isArray(firstWorkflow.issues)).toBeTruthy();
expect(typeof firstWorkflow.isTransitionsFiltered).toBe('boolean');
}
});

test.sequential('should cleanup test issues', async ({ expect }) => {
const result = await client.issueBulkOperations.submitBulkDelete({
selectedIssueIdsOrKeys: createdIssues.map(issue => issue.key),
});

expect(result).toBeDefined();
expect(result.taskId).toBeDefined();
});
15 changes: 15 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./out",
"noEmit": true,
"paths": {
"@jirajs": ["../src"],
"@jirajs/*": ["../src/*"],
"@tests": ["."],
"@tests/*": ["*"]
}
},
"include": ["integration", "unit"]
}
4 changes: 3 additions & 1 deletion tests/unit/version2/issueSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ test('searchForIssuesUsingJqlEnhancedSearch should calls without parameters', ({
const client = new Version2Client(config);
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.issueSearch.searchForIssuesUsingJqlEnhancedSearch({});
client.issueSearch.searchForIssuesUsingJqlEnhancedSearch({
jql: '',
});

expect(sendRequestStub.calledOnce).toBeTruthy();
});
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/version3/issueBulkOperations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as sinon from 'sinon';
import { test } from 'vitest';
import { Version3Client } from '@jirajs';

const config = {
host: 'http://localhost',
};

test('getAvailableTransitions should accept follow parameters', ({ expect }) => {
const client = new Version3Client(config);
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.issueBulkOperations.getAvailableTransitions({
issueIdsOrKeys: ['PROJ-1', 'PROJ-2'],
startingAfter: 'cursor1',
endingBefore: 'cursor2',
});

expect(sendRequestStub.calledOnce).toBeTruthy();

const callArgument = sendRequestStub.getCall(0).args[0];

expect(callArgument.url).toBe('/rest/api/3/bulk/issues/transition');
expect(callArgument.method).toBe('GET');
expect(callArgument.params).toStrictEqual({
issueIdsOrKeys: ['PROJ-1', 'PROJ-2'],
startingAfter: 'cursor1',
endingBefore: 'cursor2',
});
expect(callArgument.headers).toStrictEqual({
'Content-Type': 'application/json',
});
});
4 changes: 3 additions & 1 deletion tests/unit/version3/issueSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ test('searchForIssuesUsingJqlEnhancedSearch should calls without parameters', ({
const client = new Version3Client(config);
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.issueSearch.searchForIssuesUsingJqlEnhancedSearch({});
client.issueSearch.searchForIssuesUsingJqlEnhancedSearch({
jql: '',
});

expect(sendRequestStub.calledOnce).toBeTruthy();
});
Expand Down
6 changes: 0 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
"DOM"
],
"baseUrl": ".",
"paths": {
"@jirajs": ["src"],
"@jirajs/*": ["src/*"],
"@tests": ["tests"],
"@tests/*": ["tests/*"]
},
"declaration": true,
"importHelpers": true,
"strict": true,
Expand Down