mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-01 14:21:34 -05:00
Cleanup decaffienation in LearnedWordsManagerTests
This commit is contained in:
parent
e7ab9f79a9
commit
7105ee58d3
1 changed files with 37 additions and 68 deletions
|
@ -1,14 +1,3 @@
|
||||||
/* eslint-disable
|
|
||||||
handle-callback-err,
|
|
||||||
no-undef
|
|
||||||
*/
|
|
||||||
// TODO: This file was created by bulk-decaffeinate.
|
|
||||||
// Sanity-check the conversion and remove this comment.
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const { expect } = chai
|
const { expect } = chai
|
||||||
|
@ -32,7 +21,7 @@ describe('LearnedWordsManager', function() {
|
||||||
set: sinon.stub(),
|
set: sinon.stub(),
|
||||||
del: sinon.stub()
|
del: sinon.stub()
|
||||||
}
|
}
|
||||||
return (this.LearnedWordsManager = SandboxedModule.require(modulePath, {
|
this.LearnedWordsManager = SandboxedModule.require(modulePath, {
|
||||||
requires: {
|
requires: {
|
||||||
'./DB': this.db,
|
'./DB': this.db,
|
||||||
'./MongoCache': this.cache,
|
'./MongoCache': this.cache,
|
||||||
|
@ -46,21 +35,17 @@ describe('LearnedWordsManager', function() {
|
||||||
inc: sinon.stub()
|
inc: sinon.stub()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('learnWord', function() {
|
describe('learnWord', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.word = 'instanton'
|
this.word = 'instanton'
|
||||||
return this.LearnedWordsManager.learnWord(
|
this.LearnedWordsManager.learnWord(this.token, this.word, this.callback)
|
||||||
this.token,
|
|
||||||
this.word,
|
|
||||||
this.callback
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should insert the word in the word list in the database', function() {
|
it('should insert the word in the word list in the database', function() {
|
||||||
return expect(
|
expect(
|
||||||
this.db.spellingPreferences.update.calledWith(
|
this.db.spellingPreferences.update.calledWith(
|
||||||
{
|
{
|
||||||
token: this.token
|
token: this.token
|
||||||
|
@ -75,23 +60,19 @@ describe('LearnedWordsManager', function() {
|
||||||
).to.equal(true)
|
).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should call the callback', function() {
|
it('should call the callback', function() {
|
||||||
return expect(this.callback.called).to.equal(true)
|
expect(this.callback.called).to.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('unlearnWord', function() {
|
describe('unlearnWord', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.word = 'instanton'
|
this.word = 'instanton'
|
||||||
return this.LearnedWordsManager.unlearnWord(
|
this.LearnedWordsManager.unlearnWord(this.token, this.word, this.callback)
|
||||||
this.token,
|
|
||||||
this.word,
|
|
||||||
this.callback
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove the word from the word list in the database', function() {
|
it('should remove the word from the word list in the database', function() {
|
||||||
return expect(
|
expect(
|
||||||
this.db.spellingPreferences.update.calledWith(
|
this.db.spellingPreferences.update.calledWith(
|
||||||
{
|
{
|
||||||
token: this.token
|
token: this.token
|
||||||
|
@ -103,8 +84,8 @@ describe('LearnedWordsManager', function() {
|
||||||
).to.equal(true)
|
).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should call the callback', function() {
|
it('should call the callback', function() {
|
||||||
return expect(this.callback.called).to.equal(true)
|
expect(this.callback.called).to.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -112,22 +93,20 @@ describe('LearnedWordsManager', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.wordList = ['apples', 'bananas', 'pears']
|
this.wordList = ['apples', 'bananas', 'pears']
|
||||||
this.db.spellingPreferences.findOne = (conditions, callback) => {
|
this.db.spellingPreferences.findOne = (conditions, callback) => {
|
||||||
return callback(null, { learnedWords: this.wordList })
|
callback(null, { learnedWords: this.wordList })
|
||||||
}
|
}
|
||||||
sinon.spy(this.db.spellingPreferences, 'findOne')
|
sinon.spy(this.db.spellingPreferences, 'findOne')
|
||||||
return this.LearnedWordsManager.getLearnedWords(this.token, this.callback)
|
this.LearnedWordsManager.getLearnedWords(this.token, this.callback)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should get the word list for the given user', function() {
|
it('should get the word list for the given user', function() {
|
||||||
return expect(
|
expect(
|
||||||
this.db.spellingPreferences.findOne.calledWith({ token: this.token })
|
this.db.spellingPreferences.findOne.calledWith({ token: this.token })
|
||||||
).to.equal(true)
|
).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should return the word list in the callback', function() {
|
it('should return the word list in the callback', function() {
|
||||||
return expect(this.callback.calledWith(null, this.wordList)).to.equal(
|
expect(this.callback.calledWith(null, this.wordList)).to.equal(true)
|
||||||
true
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -136,14 +115,12 @@ describe('LearnedWordsManager', function() {
|
||||||
this.wordList = ['apples', 'bananas', 'pears']
|
this.wordList = ['apples', 'bananas', 'pears']
|
||||||
this.cache.get.returns(this.wordList)
|
this.cache.get.returns(this.wordList)
|
||||||
this.db.spellingPreferences.findOne = sinon.stub()
|
this.db.spellingPreferences.findOne = sinon.stub()
|
||||||
return this.LearnedWordsManager.getLearnedWords(
|
this.LearnedWordsManager.getLearnedWords(this.token, (err, spellings) => {
|
||||||
this.token,
|
expect(err).not.to.exist
|
||||||
(err, spellings) => {
|
|
||||||
this.db.spellingPreferences.findOne.called.should.equal(false)
|
this.db.spellingPreferences.findOne.called.should.equal(false)
|
||||||
assert.deepEqual(this.wordList, spellings)
|
assert.deepEqual(this.wordList, spellings)
|
||||||
return done()
|
done()
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set the cache after hitting the db', function(done) {
|
it('should set the cache after hitting the db', function(done) {
|
||||||
|
@ -151,41 +128,33 @@ describe('LearnedWordsManager', function() {
|
||||||
this.db.spellingPreferences.findOne = sinon
|
this.db.spellingPreferences.findOne = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(1, null, { learnedWords: this.wordList })
|
.callsArgWith(1, null, { learnedWords: this.wordList })
|
||||||
return this.LearnedWordsManager.getLearnedWords(
|
this.LearnedWordsManager.getLearnedWords(this.token, () => {
|
||||||
this.token,
|
this.cache.set.calledWith(this.token, this.wordList).should.equal(true)
|
||||||
(err, spellings) => {
|
done()
|
||||||
this.cache.set
|
})
|
||||||
.calledWith(this.token, this.wordList)
|
|
||||||
.should.equal(true)
|
|
||||||
return done()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should break cache when update is called', function(done) {
|
it('should break cache when update is called', function(done) {
|
||||||
this.word = 'instanton'
|
this.word = 'instanton'
|
||||||
return this.LearnedWordsManager.learnWord(this.token, this.word, () => {
|
this.LearnedWordsManager.learnWord(this.token, this.word, () => {
|
||||||
this.cache.del.calledWith(this.token).should.equal(true)
|
this.cache.del.calledWith(this.token).should.equal(true)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return describe('deleteUsersLearnedWords', function() {
|
describe('deleteUsersLearnedWords', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return (this.db.spellingPreferences.remove = sinon.stub().callsArgWith(1))
|
this.db.spellingPreferences.remove = sinon.stub().callsArgWith(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should get the word list for the given user', function(done) {
|
it('should get the word list for the given user', function(done) {
|
||||||
return this.LearnedWordsManager.deleteUsersLearnedWords(
|
this.LearnedWordsManager.deleteUsersLearnedWords(this.token, () => {
|
||||||
this.token,
|
|
||||||
() => {
|
|
||||||
this.db.spellingPreferences.remove
|
this.db.spellingPreferences.remove
|
||||||
.calledWith({ token: this.token })
|
.calledWith({ token: this.token })
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue