Files
overleaf-cep/services/web/test/unit/src/HelperFiles/DiffHelperTests.js
June Kelly c4ecded316 Merge pull request #11508 from overleaf/jk-password-disallow-substring
[web] Metric for passwords too similar to email

GitOrigin-RevId: cf8320fc3c9561b4dc6d54a3e97db96400ece2a9
2023-02-02 18:22:17 +00:00

29 lines
988 B
JavaScript

const { expect } = require('chai')
const {
stringSimilarity,
} = require('../../../../app/src/Features/Helpers/DiffHelper')
describe('DiffHelper', function () {
describe('stringSimilarity', function () {
it('should have a ratio of 1 for identical strings', function () {
expect(stringSimilarity('abcdef', 'abcdef')).to.equal(1.0)
})
it('should have a ratio of 0 for completely different strings', function () {
expect(stringSimilarity('abcdef', 'qmglzxv')).to.equal(0.0)
})
it('should have a ratio of between 0 and 1 for strings that are similar', function () {
const ratio = stringSimilarity('abcdef', 'abcdef@zxvkp')
expect(ratio).to.equal(0.66)
})
it('should reject non-string inputs', function () {
expect(() => stringSimilarity(1, 'abc')).to.throw
expect(() => stringSimilarity('abc', 2)).to.throw
expect(() => stringSimilarity('abc', new Array(1000).fill('a').join('')))
.to.throw
})
})
})