Send operations to project-history when resolving/unresolving comments (#17540)

* Send operations to project-history when resolving/unresolving comments

* small fixes

* added doc_id in web unit test

* Revert "added doc_id in web unit test"

This reverts commit f0b8251abfce17965d5e1b0e45d8784fcf1d9eed.

* fix mocked dependency in test

* wip: web unit tests

* document updater, reopen test

* document-updater tests

* format fix

* fix typo

* fix callsArgWith

* fix reopenThread calls in doc updater tests

* fix typos

* log error if chat api resolve failes

* log error when reopening thread

* sendStatus calls done() in tests

* using OError instead of logging

* removed timers

* preserve legacy endpoints

* update after merge

* Remove timer check in HttpControllerTest

* prettier

* added "legacy" in log

* remove metrics.timer

* fix promisify issues

* remove unused cb

GitOrigin-RevId: 849538c86996973a065c727835e93028e5429344
This commit is contained in:
Domagoj Kriskovic
2024-04-10 08:04:08 +00:00
committed by Copybot
parent 1557338775
commit 8bde496da4
12 changed files with 485 additions and 10 deletions
@@ -838,6 +838,174 @@ describe('DocumentUpdaterHandler', function () {
})
})
describe('resolveThread', function () {
beforeEach(function () {
this.thread_id = 'mock-thread-id-1'
})
describe('successfully', function () {
beforeEach(function () {
this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
this.handler.resolveThread(
this.project_id,
this.doc_id,
this.thread_id,
this.user_id,
this.callback
)
})
it('should resolve the thread in the document updater', function () {
this.request
.calledWithMatch({
url: `${this.settings.apis.documentupdater.url}/project/${this.project_id}/doc/${this.doc_id}/comment/${this.thread_id}/resolve`,
method: 'POST',
})
.should.equal(true)
})
it('should call the callback', function () {
this.callback.calledWith(null).should.equal(true)
})
})
describe('when the document updater API returns an error', function () {
beforeEach(function () {
this.request.callsArgWith(
1,
new Error('something went wrong'),
null,
null
)
this.handler.resolveThread(
this.project_id,
this.doc_id,
this.thread_id,
this.user_id,
this.callback
)
})
it('should return an error to the callback', function () {
this.callback
.calledWith(sinon.match.instanceOf(Error))
.should.equal(true)
})
})
describe('when the document updater returns a failure error code', function () {
beforeEach(function () {
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
this.handler.resolveThread(
this.project_id,
this.doc_id,
this.thread_id,
this.user_id,
this.callback
)
})
it('should return the callback with an error', function () {
this.callback
.calledWith(
sinon.match
.instanceOf(Error)
.and(
sinon.match.has(
'message',
'document updater returned a failure status code: 500'
)
)
)
.should.equal(true)
})
})
})
describe('reopenThread', function () {
beforeEach(function () {
this.thread_id = 'mock-thread-id-1'
})
describe('successfully', function () {
beforeEach(function () {
this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
this.handler.reopenThread(
this.project_id,
this.doc_id,
this.thread_id,
this.user_id,
this.callback
)
})
it('should reopen the thread in the document updater', function () {
this.request
.calledWithMatch({
url: `${this.settings.apis.documentupdater.url}/project/${this.project_id}/doc/${this.doc_id}/comment/${this.thread_id}/reopen`,
method: 'POST',
})
.should.equal(true)
})
it('should call the callback', function () {
this.callback.calledWith(null).should.equal(true)
})
})
describe('when the document updater API returns an error', function () {
beforeEach(function () {
this.request.callsArgWith(
1,
new Error('something went wrong'),
null,
null
)
this.handler.reopenThread(
this.project_id,
this.doc_id,
this.thread_id,
this.user_id,
this.callback
)
})
it('should return an error to the callback', function () {
this.callback
.calledWith(sinon.match.instanceOf(Error))
.should.equal(true)
})
})
describe('when the document updater returns a failure error code', function () {
beforeEach(function () {
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
this.handler.reopenThread(
this.project_id,
this.doc_id,
this.thread_id,
this.user_id,
this.callback
)
})
it('should return the callback with an error', function () {
this.callback
.calledWith(
sinon.match
.instanceOf(Error)
.and(
sinon.match.has(
'message',
'document updater returned a failure status code: 500'
)
)
)
.should.equal(true)
})
})
})
describe('updateProjectStructure ', function () {
beforeEach(function () {
this.user_id = 1234