|
|
@@ -11,10 +11,10 @@ const modulePath = require('path').join(
|
|
|
'../../../app/js/SpellingAPIManager'
|
|
|
)
|
|
|
|
|
|
-const promiseStub = val => new Promise(resolve => resolve(val))
|
|
|
+const promiseStub = (val) => new Promise((resolve) => resolve(val))
|
|
|
|
|
|
-describe('SpellingAPIManager', function() {
|
|
|
- beforeEach(function() {
|
|
|
+describe('SpellingAPIManager', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.token = 'user-id-123'
|
|
|
this.ASpell = {}
|
|
|
this.learnedWords = ['lerned']
|
|
|
@@ -35,8 +35,8 @@ describe('SpellingAPIManager', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('runRequest', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ describe('runRequest', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.nonLearnedWords = [
|
|
|
'some',
|
|
|
'words',
|
|
|
@@ -64,8 +64,8 @@ describe('SpellingAPIManager', function() {
|
|
|
sinon.spy(this.ASpell, 'checkWords')
|
|
|
})
|
|
|
|
|
|
- describe('with sensible JSON', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with sensible JSON', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.SpellingAPIManager.runRequest(
|
|
|
this.token,
|
|
|
{ words: this.allWords },
|
|
|
@@ -76,15 +76,15 @@ describe('SpellingAPIManager', function() {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should return the words that are spelled incorrectly and not learned', function() {
|
|
|
+ it('should return the words that are spelled incorrectly and not learned', function () {
|
|
|
expect(this.result.misspellings).to.deep.equal(
|
|
|
this.misspellingsWithoutLearnedWords
|
|
|
)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with a missing words array', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with a missing words array', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.SpellingAPIManager.runRequest(this.token, {}, (error, result) => {
|
|
|
this.error = error
|
|
|
this.result = result
|
|
|
@@ -92,15 +92,15 @@ describe('SpellingAPIManager', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should return an error', function() {
|
|
|
+ it('should return an error', function () {
|
|
|
expect(this.error).to.exist
|
|
|
expect(this.error).to.be.instanceof(Error)
|
|
|
expect(this.error.message).to.equal('malformed JSON')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with a missing token', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with a missing token', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.SpellingAPIManager.runRequest(
|
|
|
null,
|
|
|
{ words: this.allWords },
|
|
|
@@ -112,13 +112,13 @@ describe('SpellingAPIManager', function() {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should spell check without using any learned words', function() {
|
|
|
+ it('should spell check without using any learned words', function () {
|
|
|
this.LearnedWordsManager.getLearnedWords.called.should.equal(false)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('without a language', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('without a language', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.SpellingAPIManager.runRequest(
|
|
|
this.token,
|
|
|
{ words: this.allWords },
|
|
|
@@ -129,13 +129,13 @@ describe('SpellingAPIManager', function() {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should use en as the default', function() {
|
|
|
+ it('should use en as the default', function () {
|
|
|
this.ASpell.promises.checkWords.calledWith('en').should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with a language', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with a language', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.language = 'fr'
|
|
|
this.SpellingAPIManager.runRequest(
|
|
|
this.token,
|
|
|
@@ -150,15 +150,15 @@ describe('SpellingAPIManager', function() {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should use the language', function() {
|
|
|
+ it('should use the language', function () {
|
|
|
this.ASpell.promises.checkWords
|
|
|
.calledWith(this.language)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with words from the whitelist', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with words from the whitelist', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.whitelistWord = this.SpellingAPIManager.whitelist[0]
|
|
|
this.words = ['One', 'Two', this.whitelistWord]
|
|
|
this.SpellingAPIManager.runRequest(
|
|
|
@@ -171,7 +171,7 @@ describe('SpellingAPIManager', function() {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should ignore the white-listed word', function() {
|
|
|
+ it('should ignore the white-listed word', function () {
|
|
|
expect(this.result.misspellings.length).to.equal(
|
|
|
this.misspellings.length - 1
|
|
|
)
|
|
|
@@ -179,51 +179,51 @@ describe('SpellingAPIManager', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('learnWord', function() {
|
|
|
- describe('without a token', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.SpellingAPIManager.learnWord(null, { word: 'banana' }, error => {
|
|
|
+ describe('learnWord', function () {
|
|
|
+ describe('without a token', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.SpellingAPIManager.learnWord(null, { word: 'banana' }, (error) => {
|
|
|
this.error = error
|
|
|
done()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should return an error', function() {
|
|
|
+ it('should return an error', function () {
|
|
|
expect(this.error).to.exist
|
|
|
expect(this.error).to.be.instanceof(Error)
|
|
|
expect(this.error.message).to.equal('no token provided')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('without a word', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.SpellingAPIManager.learnWord(this.token, {}, error => {
|
|
|
+ describe('without a word', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.SpellingAPIManager.learnWord(this.token, {}, (error) => {
|
|
|
this.error = error
|
|
|
done()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should return an error', function() {
|
|
|
+ it('should return an error', function () {
|
|
|
expect(this.error).to.exist
|
|
|
expect(this.error).to.be.instanceof(Error)
|
|
|
expect(this.error.message).to.equal('malformed JSON')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with a word and a token', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with a word and a token', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.word = 'banana'
|
|
|
this.SpellingAPIManager.learnWord(
|
|
|
this.token,
|
|
|
{ word: this.word },
|
|
|
- error => {
|
|
|
+ (error) => {
|
|
|
this.error = error
|
|
|
done()
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should call LearnedWordsManager.learnWord', function() {
|
|
|
+ it('should call LearnedWordsManager.learnWord', function () {
|
|
|
this.LearnedWordsManager.learnWord
|
|
|
.calledWith(this.token, this.word)
|
|
|
.should.equal(true)
|
|
|
@@ -231,51 +231,55 @@ describe('SpellingAPIManager', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('unlearnWord', function() {
|
|
|
- describe('without a token', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.SpellingAPIManager.unlearnWord(null, { word: 'banana' }, error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- })
|
|
|
+ describe('unlearnWord', function () {
|
|
|
+ describe('without a token', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.SpellingAPIManager.unlearnWord(
|
|
|
+ null,
|
|
|
+ { word: 'banana' },
|
|
|
+ (error) => {
|
|
|
+ this.error = error
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
})
|
|
|
|
|
|
- it('should return an error', function() {
|
|
|
+ it('should return an error', function () {
|
|
|
expect(this.error).to.exist
|
|
|
expect(this.error).to.be.instanceof(Error)
|
|
|
expect(this.error.message).to.equal('no token provided')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('without a word', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.SpellingAPIManager.unlearnWord(this.token, {}, error => {
|
|
|
+ describe('without a word', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.SpellingAPIManager.unlearnWord(this.token, {}, (error) => {
|
|
|
this.error = error
|
|
|
done()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should return an error', function() {
|
|
|
+ it('should return an error', function () {
|
|
|
expect(this.error).to.exist
|
|
|
expect(this.error).to.be.instanceof(Error)
|
|
|
expect(this.error.message).to.equal('malformed JSON')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with a word and a token', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ describe('with a word and a token', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.word = 'banana'
|
|
|
this.SpellingAPIManager.unlearnWord(
|
|
|
this.token,
|
|
|
{ word: this.word },
|
|
|
- error => {
|
|
|
+ (error) => {
|
|
|
this.error = error
|
|
|
done()
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should call LearnedWordsManager.unlearnWord', function() {
|
|
|
+ it('should call LearnedWordsManager.unlearnWord', function () {
|
|
|
this.LearnedWordsManager.unlearnWord
|
|
|
.calledWith(this.token, this.word)
|
|
|
.should.equal(true)
|