added delete dic endpoint

This commit is contained in:
Henry Oswald 2017-10-30 16:57:34 +00:00
parent 84ff55cf14
commit 31d62c3359
5 changed files with 24 additions and 1 deletions

View file

@ -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)->

View file

@ -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',

View file

@ -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)

View file

@ -46,4 +46,6 @@ module.exports = SpellingAPIManager =
LearnedWordsManager.learnWord token, request.word, callback
deleteDic: (token, callback)->
LearnedWordsManager.deleteUsersLearnedWords token, callback

View file

@ -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()