Skip to content

Commit 9b574c7

Browse files
authored
Fix updateComment payload (#184)
Payload is currently set to send the body as a string, this causes payload to be encoded as form-data not json. Passing a json object solves this and avoids the 405 error from the API.
1 parent f481c6e commit 9b574c7

File tree

4 files changed

+114
-2
lines changed

4 files changed

+114
-2
lines changed

src/version2/issueComments.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ export class IssueComments {
244244
params: {
245245
expand: parameters.expand,
246246
},
247-
data: parameters.body,
247+
data: {
248+
body: parameters.body,
249+
},
248250
};
249251

250252
return this.client.sendRequest(config, callback);

src/version3/issueComments.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ export class IssueComments {
245245
notifyUsers: parameters.notifyUsers,
246246
expand: parameters.expand,
247247
},
248-
data: parameters.body,
248+
data: {
249+
body: parameters.body,
250+
},
249251
};
250252

251253
return this.client.sendRequest(config, callback);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
cleanupEnvironment,
3+
getVersion2Client,
4+
prepareEnvironment,
5+
} from '../utils';
6+
import { Constants } from '../constants';
7+
8+
describe('IssueAttachments', () => {
9+
beforeAll(async () => {
10+
await prepareEnvironment();
11+
});
12+
13+
afterAll(async () => {
14+
await cleanupEnvironment();
15+
});
16+
17+
it('should update comment', async () => {
18+
const client = getVersion2Client({ noCheckAtlassianToken: true });
19+
20+
const issue = await client.issues.createIssue({
21+
fields: {
22+
summary: 'Issue with comments',
23+
project: {
24+
key: Constants.testProjectKey,
25+
},
26+
issuetype: {
27+
name: 'Task',
28+
},
29+
},
30+
});
31+
32+
expect(issue).toBeDefined();
33+
34+
const comment = await client.issueComments.addComment({
35+
issueIdOrKey: issue.key,
36+
body: 'this is a comment',
37+
});
38+
39+
expect(comment).toBeDefined();
40+
41+
const updatedComment = await client.issueComments.updateComment({
42+
issueIdOrKey: issue.key,
43+
id: comment.id,
44+
body: 'updated comment',
45+
});
46+
47+
expect(updatedComment).toBeDefined();
48+
expect(updatedComment.id).toEqual(comment.id);
49+
50+
await client.issues.deleteIssue({
51+
issueIdOrKey: issue.key,
52+
});
53+
});
54+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
cleanupEnvironment,
3+
getVersion3Client,
4+
prepareEnvironment,
5+
} from '../utils';
6+
import { Constants } from '../constants';
7+
8+
describe('IssueAttachments', () => {
9+
beforeAll(async () => {
10+
await prepareEnvironment();
11+
});
12+
13+
afterAll(async () => {
14+
await cleanupEnvironment();
15+
});
16+
17+
it('should update comment', async () => {
18+
const client = getVersion3Client({ noCheckAtlassianToken: true });
19+
20+
const issue = await client.issues.createIssue({
21+
fields: {
22+
summary: 'Issue with comments',
23+
project: {
24+
key: Constants.testProjectKey,
25+
},
26+
issuetype: {
27+
name: 'Task',
28+
},
29+
},
30+
});
31+
32+
expect(issue).toBeDefined();
33+
34+
const comment = await client.issueComments.addComment({
35+
issueIdOrKey: issue.key,
36+
body: 'this is a comment',
37+
});
38+
39+
expect(comment).toBeDefined();
40+
41+
const updatedComment = await client.issueComments.updateComment({
42+
issueIdOrKey: issue.key,
43+
id: comment.id,
44+
body: 'updated comment',
45+
});
46+
47+
expect(updatedComment).toBeDefined();
48+
expect(updatedComment.id).toEqual(comment.id);
49+
50+
await client.issues.deleteIssue({
51+
issueIdOrKey: issue.key,
52+
});
53+
});
54+
});

0 commit comments

Comments
 (0)