mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Fix response when learning custom words
GitOrigin-RevId: fe7c8a2862532b83e650d3ecfae2ae5245394620
This commit is contained in:
parent
e38a86d9f4
commit
0b938927af
2 changed files with 65 additions and 30 deletions
|
@ -12,6 +12,9 @@ module.exports = {
|
|||
proxyRequestToSpellingApi(req, res) {
|
||||
const { language } = req.body
|
||||
|
||||
let url = req.url.slice('/spelling'.length)
|
||||
|
||||
if (url === '/check') {
|
||||
if (!language) {
|
||||
logger.error('"language" field should be included for spell checking')
|
||||
return res.status(422).send(JSON.stringify({ misspellings: [] }))
|
||||
|
@ -23,9 +26,9 @@ module.exports = {
|
|||
logger.info({ language }, 'language not supported')
|
||||
return res.status(422).send(JSON.stringify({ misspellings: [] }))
|
||||
}
|
||||
}
|
||||
|
||||
const userId = AuthenticationController.getLoggedInUserId(req)
|
||||
let url = req.url.slice('/spelling'.length)
|
||||
url = `/user/${userId}${url}`
|
||||
req.headers['Host'] = Settings.apis.spelling.host
|
||||
return request({
|
||||
|
|
|
@ -97,6 +97,10 @@ describe('SpellingController', function() {
|
|||
beforeEach(function() {
|
||||
this.req.session.user._id = this.userId = 'user-id-123'
|
||||
this.req.body = { language: 'fi', words: ['blab'] }
|
||||
})
|
||||
|
||||
describe('when the request is a check request', function() {
|
||||
beforeEach(function() {
|
||||
this.controller.proxyRequestToSpellingApi(this.req, this.res)
|
||||
})
|
||||
|
||||
|
@ -115,10 +119,26 @@ describe('SpellingController', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('when the request is not a check request', function() {
|
||||
beforeEach(function() {
|
||||
this.req.url = '/spelling/learn'
|
||||
this.controller.proxyRequestToSpellingApi(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send a request to the spelling host', function() {
|
||||
this.request.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no language is indicated', function() {
|
||||
beforeEach(function() {
|
||||
this.req.session.user._id = this.userId = 'user-id-123'
|
||||
this.req.body = { words: ['blab'] }
|
||||
})
|
||||
|
||||
describe('when the request is a check request', function() {
|
||||
beforeEach(function() {
|
||||
this.controller.proxyRequestToSpellingApi(this.req, this.res)
|
||||
})
|
||||
|
||||
|
@ -136,5 +156,17 @@ describe('SpellingController', function() {
|
|||
this.res.status.calledWith(422).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the request is not a check request', function() {
|
||||
beforeEach(function() {
|
||||
this.req.url = '/spelling/learn'
|
||||
this.controller.proxyRequestToSpellingApi(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send a request to the spelling host', function() {
|
||||
this.request.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue