From 536e014600c5576b9b00765e2f69fa3d4247a335 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 3 Mar 2015 14:27:38 +0000 Subject: [PATCH] remove js tests --- services/spelling/.gitignore | 1 + services/spelling/test/unit/js/ASpellTests.js | 112 ---------- .../test/unit/js/LearnedWordsManagerTests.js | 99 --------- .../test/unit/js/SpellingAPIManagerTests.js | 208 ------------------ 4 files changed, 1 insertion(+), 419 deletions(-) delete mode 100644 services/spelling/test/unit/js/ASpellTests.js delete mode 100644 services/spelling/test/unit/js/LearnedWordsManagerTests.js delete mode 100644 services/spelling/test/unit/js/SpellingAPIManagerTests.js diff --git a/services/spelling/.gitignore b/services/spelling/.gitignore index 1d056a1921..6a7109dc73 100644 --- a/services/spelling/.gitignore +++ b/services/spelling/.gitignore @@ -4,3 +4,4 @@ app/js/* app.js test/UnitTests/js/* node_modules/* +test/unit/js/ diff --git a/services/spelling/test/unit/js/ASpellTests.js b/services/spelling/test/unit/js/ASpellTests.js deleted file mode 100644 index fbcfddba55..0000000000 --- a/services/spelling/test/unit/js/ASpellTests.js +++ /dev/null @@ -1,112 +0,0 @@ -(function() { - var chai, should, sinon; - - sinon = require('sinon'); - - chai = require('chai'); - - should = chai.should(); - - describe("ASpell", function() { - beforeEach(function() { - return this.ASpell = require("../../../app/js/ASpell"); - }); - describe("a correctly spelled word", function() { - beforeEach(function(done) { - return this.ASpell.checkWords("en", ["word"], (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should not correct the word", function() { - return this.result.length.should.equal(0); - }); - }); - describe("a misspelled word", function() { - beforeEach(function(done) { - return this.ASpell.checkWords("en", ["bussines"], (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should correct the word", function() { - this.result.length.should.equal(1); - return this.result[0].suggestions.indexOf("business").should.not.equal(-1); - }); - }); - describe("multiple words", function() { - beforeEach(function(done) { - return this.ASpell.checkWords("en", ["bussines", "word", "neccesary"], (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should correct the incorrect words", function() { - this.result[0].index.should.equal(0); - this.result[0].suggestions.indexOf("business").should.not.equal(-1); - this.result[1].index.should.equal(2); - return this.result[1].suggestions.indexOf("necessary").should.not.equal(-1); - }); - }); - describe("without a valid language", function() { - beforeEach(function(done) { - return this.ASpell.checkWords("notALang", ["banana"], (function(_this) { - return function(error, result) { - _this.error = error; - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should return an error", function() { - return should.exist(this.error); - }); - }); - describe("when there are no suggestions", function() { - beforeEach(function(done) { - return this.ASpell.checkWords("en", ["asdkfjalkdjfadhfkajsdhfashdfjhadflkjadhflajsd"], (function(_this) { - return function(error, result) { - _this.error = error; - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should return a blank array", function() { - this.result.length.should.equal(1); - return this.result[0].suggestions.should.deep.equal([]); - }); - }); - return describe("when the request times out", function() { - beforeEach(function(done) { - var i, words; - words = (function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i <= 1000000; i = ++_i) { - _results.push("abcdefg"); - } - return _results; - })(); - this.ASpell.ASPELL_TIMEOUT = 100; - this.start = new Date(); - return this.ASpell.checkWords("en", words, (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should return in reasonable time", function(done) { - return done(); - }); - }); - }); - -}).call(this); diff --git a/services/spelling/test/unit/js/LearnedWordsManagerTests.js b/services/spelling/test/unit/js/LearnedWordsManagerTests.js deleted file mode 100644 index a4da3013f0..0000000000 --- a/services/spelling/test/unit/js/LearnedWordsManagerTests.js +++ /dev/null @@ -1,99 +0,0 @@ -(function() { - var SandboxedModule, chai, expect, modulePath, sinon; - - sinon = require('sinon'); - - chai = require('chai'); - - expect = chai.expect; - - SandboxedModule = require('sandboxed-module'); - - modulePath = require('path').join(__dirname, '../../../app/js/LearnedWordsManager'); - - describe("LearnedWordsManager", function() { - beforeEach(function() { - this.token = "a6b3cd919ge"; - this.callback = sinon.stub(); - this.db = { - spellingPreferences: { - update: sinon.stub().callsArg(3) - } - }; - return this.LearnedWordsManager = SandboxedModule.require(modulePath, { - requires: { - "./DB": this.db - } - }); - }); - describe("learnWord", function() { - beforeEach(function() { - this.word = "instanton"; - return this.LearnedWordsManager.learnWord(this.token, this.word, this.callback); - }); - it("should insert the word in the word list in the database", function() { - return expect(this.db.spellingPreferences.update.calledWith({ - token: this.token - }, { - $push: { - learnedWords: this.word - } - }, { - upsert: true - })).to.equal(true); - }); - return it("should call the callback", function() { - return expect(this.callback.called).to.equal(true); - }); - }); - return describe("getLearnedWords", function() { - beforeEach(function() { - this.wordList = ["apples", "bananas", "pears"]; - this.db.spellingPreferences.findOne = (function(_this) { - return function(conditions, callback) { - return callback(null, { - learnedWords: _this.wordList - }); - }; - })(this); - sinon.spy(this.db.spellingPreferences, "findOne"); - return this.LearnedWordsManager.getLearnedWords(this.token, this.callback); - }); - it("should get the word list for the given user", function() { - return expect(this.db.spellingPreferences.findOne.calledWith({ - token: this.token - })).to.equal(true); - }); - return it("should return the word list in the callback", function() { - return expect(this.callback.calledWith(null, this.wordList)).to.equal(true); - }); - }); - - /* - describe "caching the result", -> - it 'should use the cache first if it is primed', (done)-> - @wordList = ["apples", "bananas", "pears"] - @cache.get.callsArgWith(1, null, learnedWords: @wordList) - @db.spellingPreferences.findOne = sinon.stub() - @LearnedWordsManager.getLearnedWords @token, (err, spellings)=> - @db.spellingPreferences.find.called.should.equal false - @wordList.should.equal spellings - done() - - it 'should set the cache after hitting the db', (done)-> - @wordList = ["apples", "bananas", "pears"] - @cache.get.callsArgWith(1) - @db.spellingPreferences.findOne = sinon.stub().callsArgWith(1, null, learnedWords: @wordList) - @LearnedWordsManager.getLearnedWords @token, (err, spellings)=> - @cache.set.calledWith(@token, learnedWords:@wordList).should.equal true - done() - - it 'should break cache when update is called', (done)-> - @word = "instanton" - @LearnedWordsManager.learnWord @token, @word, => - @cache.break.calledWith(@token).should.equal true - done() - */ - }); - -}).call(this); diff --git a/services/spelling/test/unit/js/SpellingAPIManagerTests.js b/services/spelling/test/unit/js/SpellingAPIManagerTests.js deleted file mode 100644 index 4c79859865..0000000000 --- a/services/spelling/test/unit/js/SpellingAPIManagerTests.js +++ /dev/null @@ -1,208 +0,0 @@ -(function() { - var SandboxedModule, chai, expect, modulePath, sinon; - - sinon = require('sinon'); - - chai = require('chai'); - - expect = chai.expect; - - chai.should(); - - SandboxedModule = require('sandboxed-module'); - - modulePath = require('path').join(__dirname, '../../../app/js/SpellingAPIManager'); - - describe("SpellingAPIManager", function() { - beforeEach(function() { - this.token = "user-id-123"; - this.ASpell = {}; - this.learnedWords = ["lerned"]; - this.LearnedWordsManager = { - getLearnedWords: sinon.stub().callsArgWith(1, null, this.learnedWords), - learnWord: sinon.stub().callsArg(2) - }; - return this.SpellingAPIManager = SandboxedModule.require(modulePath, { - requires: { - "./ASpell": this.ASpell, - "./LearnedWordsManager": this.LearnedWordsManager - } - }); - }); - describe("runRequest", function() { - beforeEach(function() { - this.nonLearnedWords = ["some", "words", "htat", "are", "speled", "rong", "lerned"]; - this.allWords = this.nonLearnedWords.concat(this.learnedWords); - this.misspellings = [ - { - index: 2, - suggestions: ["that"] - }, { - index: 4, - suggestions: ["spelled"] - }, { - index: 5, - suggestions: ["wrong", "ring"] - }, { - index: 6, - suggestions: ["learned"] - } - ]; - this.misspellingsWithoutLearnedWords = this.misspellings.slice(0, 3); - this.ASpell.checkWords = (function(_this) { - return function(lang, word, callback) { - return callback(null, _this.misspellings); - }; - })(this); - return sinon.spy(this.ASpell, "checkWords"); - }); - describe("with sensible JSON", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.runRequest(this.token, { - words: this.allWords - }, (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should return the words that are spelled incorrectly and not learned", function() { - return expect(this.result.misspellings).to.deep.equal(this.misspellingsWithoutLearnedWords); - }); - }); - describe("with a missing words array", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.runRequest(this.token, {}, (function(_this) { - return function(error, result) { - _this.error = error; - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should return an error", function() { - return expect(this.error).to.deep.equal(new Error("malformed JSON")); - }); - }); - describe("with a missing token", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.runRequest(null, { - words: this.allWords - }, (function(_this) { - return function(error, result) { - _this.error = error; - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should spell check without using any learned words", function() { - return this.LearnedWordsManager.getLearnedWords.called.should.equal(false); - }); - }); - describe("without a language", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.runRequest(this.token, { - words: this.allWords - }, (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should use en as the default", function() { - return this.ASpell.checkWords.calledWith("en").should.equal(true); - }); - }); - describe("with a language", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.runRequest(this.token, { - words: this.allWords, - language: this.language = "fr" - }, (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should use the language", function() { - return this.ASpell.checkWords.calledWith(this.language).should.equal(true); - }); - }); - return describe("with a very large collection of words", function() { - beforeEach(function(done) { - var i; - this.manyWords = (function() { - var _i, _results; - _results = []; - for (i = _i = 1; _i <= 100000; i = ++_i) { - _results.push("word"); - } - return _results; - })(); - return this.SpellingAPIManager.runRequest(this.token, { - words: this.manyWords - }, (function(_this) { - return function(error, result) { - _this.result = result; - return done(); - }; - })(this)); - }); - return it("should truncate to 10,000 words", function() { - return this.ASpell.checkWords.calledWith(sinon.match.any, this.manyWords.slice(0, 10000)).should.equal(true); - }); - }); - }); - return describe("learnWord", function() { - describe("without a token", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.learnWord(null, { - word: "banana" - }, (function(_this) { - return function(error) { - _this.error = error; - return done(); - }; - })(this)); - }); - return it("should return an error", function() { - return expect(this.error).to.deep.equal(new Error("malformed JSON")); - }); - }); - describe("without a word", function() { - beforeEach(function(done) { - return this.SpellingAPIManager.learnWord(this.token, {}, (function(_this) { - return function(error) { - _this.error = error; - return done(); - }; - })(this)); - }); - return it("should return an error", function() { - return expect(this.error).to.deep.equal(new Error("no token provided")); - }); - }); - return describe("with a word and a token", function() { - beforeEach(function(done) { - this.word = "banana"; - return this.SpellingAPIManager.learnWord(this.token, { - word: this.word - }, (function(_this) { - return function(error) { - _this.error = error; - return done(); - }; - })(this)); - }); - return it("should call LearnedWordsManager.learnWord", function() { - return this.LearnedWordsManager.learnWord.calledWith(this.token, this.word).should.equal(true); - }); - }); - }); - }); - -}).call(this);