mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-25 16:04:01 +00:00
fix: resourceDiscussions.editNote add content params, and allowed discussionId to accept a string type (#524)
Co-authored-by: Liu Jia <ldspirit0801@163.com>
This commit is contained in:
parent
9ad767b235
commit
22d916a05f
@ -19,7 +19,7 @@ export class ResourceDiscussions extends BaseService {
|
||||
addNote(
|
||||
resourceId: string | number,
|
||||
resource2Id: string | number,
|
||||
discussionId: number,
|
||||
discussionId: string | number,
|
||||
noteId: number,
|
||||
content: string,
|
||||
options?: BaseRequestOptions,
|
||||
@ -66,8 +66,9 @@ export class ResourceDiscussions extends BaseService {
|
||||
editNote(
|
||||
resourceId: string | number,
|
||||
resource2Id: string | number,
|
||||
discussionId: number,
|
||||
discussionId: string | number,
|
||||
noteId: number,
|
||||
content: string,
|
||||
options?: BaseRequestOptions,
|
||||
) {
|
||||
const [rId, r2Id, dId, nId] = [resourceId, resource2Id, discussionId, noteId].map(
|
||||
@ -77,14 +78,17 @@ export class ResourceDiscussions extends BaseService {
|
||||
return RequestHelper.put(
|
||||
this,
|
||||
`${rId}/${this.resource2Type}/${r2Id}/discussions/${dId}/notes/${nId}`,
|
||||
{ body: options },
|
||||
{
|
||||
body: content,
|
||||
...options,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
removeNote(
|
||||
resourceId: string | number,
|
||||
resource2Id: string | number,
|
||||
discussionId: number,
|
||||
discussionId: string | number,
|
||||
noteId: number,
|
||||
options?: Sudo,
|
||||
) {
|
||||
@ -102,7 +106,7 @@ export class ResourceDiscussions extends BaseService {
|
||||
show(
|
||||
resourceId: string | number,
|
||||
resource2Id: string | number,
|
||||
discussionId: number,
|
||||
discussionId: string | number,
|
||||
options?: Sudo,
|
||||
) {
|
||||
const [rId, r2Id, dId] = [resourceId, resource2Id, discussionId].map(encodeURIComponent);
|
||||
|
||||
68
test/unit/templates/ResourceDiscussions.ts
Normal file
68
test/unit/templates/ResourceDiscussions.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { ResourceDiscussions } from '../../../src/core/templates';
|
||||
import { RequestHelper } from '../../../src/core/infrastructure';
|
||||
|
||||
jest.mock('../../../src/core/infrastructure/RequestHelper');
|
||||
jest.mock('../../../src/core/infrastructure/KyRequester', () => ({
|
||||
get: jest.fn(() => []),
|
||||
post: jest.fn(() => {}),
|
||||
put: jest.fn(() => {}),
|
||||
}));
|
||||
|
||||
let issuesService: ResourceDiscussions;
|
||||
|
||||
beforeEach(() => {
|
||||
issuesService = new ResourceDiscussions('projects', 'issues', {
|
||||
token: 'abcdefg',
|
||||
});
|
||||
});
|
||||
|
||||
describe('Instantiating Projects service', () => {
|
||||
it('should create a valid service object', async () => {
|
||||
expect(issuesService).toBeInstanceOf(ResourceDiscussions);
|
||||
expect(issuesService.url).toBeDefined();
|
||||
expect(issuesService.rejectUnauthorized).toBeTruthy();
|
||||
expect(issuesService.headers).toMatchObject({ 'private-token': 'abcdefg' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('ResourceDiscussions.editNote', () => {
|
||||
it('should request PUT /projects/:id/issues/:issue_iid/discussions/:discussion_id/notes/:note_id', async () => {
|
||||
const projectId = 75159;
|
||||
const issueIid = 1;
|
||||
const discussionId = 'xxxx';
|
||||
const noteId = 11236631;
|
||||
const body = 'add note from gitbeaker';
|
||||
|
||||
await issuesService.editNote(projectId, issueIid, discussionId, noteId, body);
|
||||
|
||||
expect(RequestHelper.put).toHaveBeenCalledWith(
|
||||
issuesService,
|
||||
`${projectId}/issues/${issueIid}/discussions/${discussionId}/notes/${noteId}`,
|
||||
{
|
||||
body,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('should use body property in options', async () => {
|
||||
const projectId = 75159;
|
||||
const issueIid = 1;
|
||||
const discussionId = 'xxxx';
|
||||
const noteId = 11236631;
|
||||
const body = 'add note from gitbeaker';
|
||||
const optionsBody = 'add note from gitbeaker in options';
|
||||
|
||||
await issuesService.editNote(projectId, issueIid, discussionId, noteId, body, {
|
||||
hah: 1,
|
||||
body: optionsBody,
|
||||
});
|
||||
|
||||
expect(RequestHelper.put).toHaveBeenLastCalledWith(
|
||||
issuesService,
|
||||
`${projectId}/issues/${issueIid}/discussions/${discussionId}/notes/${noteId}`,
|
||||
expect.objectContaining({
|
||||
body: optionsBody,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user