2022-12-20 07:11:25 -05:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import * as request from './helpers/request.js'
|
2019-07-09 14:12:30 -04:00
|
|
|
|
|
|
|
const USER_ID = 101
|
|
|
|
|
2019-09-27 06:58:35 -04:00
|
|
|
const checkWord = (words, language) =>
|
2019-07-09 14:12:30 -04:00
|
|
|
request.post({
|
|
|
|
url: `/user/${USER_ID}/check`,
|
|
|
|
body: JSON.stringify({
|
2019-10-03 04:41:16 -04:00
|
|
|
words,
|
2021-07-13 07:04:47 -04:00
|
|
|
language,
|
|
|
|
}),
|
2019-07-09 14:12:30 -04:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
describe('checking words', function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
let response
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
describe('on successful response', function () {
|
|
|
|
beforeEach(async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
response = await checkWord(['anather'])
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return status 200', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return the list of misspellings', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body).to.deep.equal({
|
2024-01-10 03:50:48 -05:00
|
|
|
misspellings: [
|
|
|
|
{
|
|
|
|
index: 0,
|
|
|
|
suggestions: [
|
|
|
|
'anther',
|
|
|
|
'another',
|
|
|
|
'anthers',
|
|
|
|
'panther',
|
|
|
|
'anathema',
|
|
|
|
'anthem',
|
|
|
|
'nether',
|
|
|
|
"anther's",
|
|
|
|
'ante',
|
|
|
|
'neither',
|
|
|
|
'norther',
|
|
|
|
'ether',
|
|
|
|
'other',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2019-07-09 14:12:30 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
describe('when multiple words are submitted', function () {
|
|
|
|
beforeEach(async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
response = await checkWord(['anather', 'anather', 'theorie'])
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return the misspellings for all the words', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body.misspellings.length).to.equal(3)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should have misspelling suggestions with consecutive indexes', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
const body = JSON.parse(response.body)
|
2021-07-13 07:04:47 -04:00
|
|
|
const indexes = body.misspellings.map(mspl => mspl.index)
|
2019-07-09 14:12:30 -04:00
|
|
|
expect(indexes).to.deep.equal([0, 1, 2])
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return identical suggestions for the same entry', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body.misspellings[0].suggestions).to.deep.equal(
|
|
|
|
body.misspellings[1].suggestions
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
describe('when a very long list of words if submitted', function () {
|
|
|
|
beforeEach(async function () {
|
2020-06-03 04:52:36 -04:00
|
|
|
const words = []
|
2019-07-09 14:12:30 -04:00
|
|
|
for (let i = 0; i <= 20000; i++) {
|
|
|
|
words.push('anather')
|
|
|
|
}
|
|
|
|
response = await checkWord(words)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return misspellings for the first 10K results only', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body.misspellings.length).to.equal(10000)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should have misspelling suggestions with consecutive indexes', async function () {
|
2019-07-09 14:12:30 -04:00
|
|
|
const body = JSON.parse(response.body)
|
2021-07-13 07:04:47 -04:00
|
|
|
const indexList = body.misspellings.map(mspl => mspl.index)
|
2019-07-09 14:12:30 -04:00
|
|
|
expect(indexList.length).to.equal(10000) // avoid testing over an incorrect array
|
|
|
|
for (let i = 0; i < indexList.length - 1; i++) {
|
|
|
|
expect(indexList[i] + 1).to.equal(indexList[i + 1])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2019-09-27 06:58:35 -04:00
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
describe('when a very long list of words with utf8 responses', function () {
|
|
|
|
beforeEach(async function () {
|
2020-06-03 04:52:36 -04:00
|
|
|
const words = []
|
2019-09-27 06:58:35 -04:00
|
|
|
for (let i = 0; i <= 20000; i++) {
|
|
|
|
words.push('anéther')
|
|
|
|
}
|
|
|
|
response = await checkWord(words, 'bg') // use Bulgarian to generate utf8 response
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return misspellings for the first 10K results only', async function () {
|
2019-09-27 06:58:35 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body.misspellings.length).to.equal(10000)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should have misspelling suggestions with consecutive indexes', async function () {
|
2019-09-27 06:58:35 -04:00
|
|
|
const body = JSON.parse(response.body)
|
2021-07-13 07:04:47 -04:00
|
|
|
const indexList = body.misspellings.map(mspl => mspl.index)
|
2019-09-27 06:58:35 -04:00
|
|
|
expect(indexList.length).to.equal(10000) // avoid testing over an incorrect array
|
|
|
|
for (let i = 0; i < indexList.length - 1; i++) {
|
|
|
|
expect(indexList[i] + 1).to.equal(indexList[i + 1])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
describe('when multiple words with utf8 are submitted', function () {
|
|
|
|
beforeEach(async function () {
|
2019-09-27 06:58:35 -04:00
|
|
|
response = await checkWord(['mneá', 'meniésn', 'meônoi', 'mneá'], 'pt_BR')
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return the misspellings for all the words', async function () {
|
2019-09-27 06:58:35 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body.misspellings.length).to.equal(4)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should have misspelling suggestions with consecutive indexes', async function () {
|
2019-09-27 06:58:35 -04:00
|
|
|
const body = JSON.parse(response.body)
|
2021-07-13 07:04:47 -04:00
|
|
|
const indexes = body.misspellings.map(mspl => mspl.index)
|
2019-09-27 06:58:35 -04:00
|
|
|
expect(indexes).to.deep.equal([0, 1, 2, 3])
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:23:15 -04:00
|
|
|
it('should return identical suggestions for the same entry', async function () {
|
2019-09-27 06:58:35 -04:00
|
|
|
const body = JSON.parse(response.body)
|
|
|
|
expect(body.misspellings[0].suggestions).to.deep.equal(
|
|
|
|
body.misspellings[3].suggestions
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2019-07-09 14:12:30 -04:00
|
|
|
})
|