-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resourceDiscussions.editNote add content params, and allowed dis…
…cussionId to accept a string type (#524) Co-authored-by: Liu Jia <ldspirit0801@163.com>
- Loading branch information
1 parent
9ad767b
commit 22d916a
Showing
2 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}), | ||
); | ||
}); | ||
}); |