diff --git a/services/spelling/app.coffee b/services/spelling/app.coffee index bdefe9224c..9fac369c2c 100644 --- a/services/spelling/app.coffee +++ b/services/spelling/app.coffee @@ -19,6 +19,7 @@ HealthCheckController = require("./app/js/HealthCheckController") server.use bodyParser.json(limit: "2mb") server.use metrics.http.monitor(logger) +server.del "/user/:user_id", SpellingAPIController.deleteDic server.post "/user/:user_id/check", SpellingAPIController.check server.post "/user/:user_id/learn", SpellingAPIController.learn server.get "/status", (req, res)-> diff --git a/services/spelling/app/coffee/LearnedWordsManager.coffee b/services/spelling/app/coffee/LearnedWordsManager.coffee index 681b637318..4b772ea823 100644 --- a/services/spelling/app/coffee/LearnedWordsManager.coffee +++ b/services/spelling/app/coffee/LearnedWordsManager.coffee @@ -29,6 +29,9 @@ module.exports = LearnedWordsManager = mongoCache.set(user_token, words) callback null, words + deleteUsersLearnedWords: (user_token, callback =(error)->)-> + db.spellingPreferences.remove token: user_token, callback + [ 'learnWord', diff --git a/services/spelling/app/coffee/SpellingAPIController.coffee b/services/spelling/app/coffee/SpellingAPIController.coffee index 67a095d12d..8f04123a7d 100644 --- a/services/spelling/app/coffee/SpellingAPIController.coffee +++ b/services/spelling/app/coffee/SpellingAPIController.coffee @@ -21,3 +21,9 @@ module.exports = SpellingAPIController = next() + deleteDic: (req, res, next)-> + logger.log token: req?.params?.user_id, word: req?.body?.word, "deleting user dictionary" + SpellingAPIManager.deleteDic req.params.user_id, (error) -> + return next(error) if error? + res.sendStatus(204) + diff --git a/services/spelling/app/coffee/SpellingAPIManager.coffee b/services/spelling/app/coffee/SpellingAPIManager.coffee index 8830155671..b8b097c893 100644 --- a/services/spelling/app/coffee/SpellingAPIManager.coffee +++ b/services/spelling/app/coffee/SpellingAPIManager.coffee @@ -46,4 +46,6 @@ module.exports = SpellingAPIManager = LearnedWordsManager.learnWord token, request.word, callback + deleteDic: (token, callback)-> + LearnedWordsManager.deleteUsersLearnedWords token, callback diff --git a/services/spelling/test/unit/coffee/LearnedWordsManagerTests.coffee b/services/spelling/test/unit/coffee/LearnedWordsManagerTests.coffee index 09d9dc4440..b9dd938b0a 100644 --- a/services/spelling/test/unit/coffee/LearnedWordsManagerTests.coffee +++ b/services/spelling/test/unit/coffee/LearnedWordsManagerTests.coffee @@ -83,4 +83,15 @@ describe "LearnedWordsManager", -> @LearnedWordsManager.learnWord @token, @word, => @cache.del.calledWith(@token).should.equal true done() - + + + describe "deleteUsersLearnedWords", -> + beforeEach -> + @db.spellingPreferences.delete = sinon.stub().callsArgWith(1) + + + it "should get the word list for the given user", (done)-> + @LearnedWordsManager.deleteUsersLearnedWords @token, => + @db.spellingPreferences.delete.calledWith(token: @token).should.equal true + done() +