mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
detect languages removes html tags before detection
This commit is contained in:
parent
3bd8a531f1
commit
5559a9bc06
@ -1,9 +1,17 @@
|
||||
import LanguageDetect from 'languagedetect'
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
|
||||
const removeHtmlTags = (input) => {
|
||||
return sanitizeHtml(input, {
|
||||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})
|
||||
}
|
||||
|
||||
const setPostLanguage = (text) => {
|
||||
const lngDetector = new LanguageDetect()
|
||||
lngDetector.setLanguageType('iso2')
|
||||
const result = lngDetector.detect(text, 2)
|
||||
const result = lngDetector.detect(removeHtmlTags(text), 2)
|
||||
return result[0][0]
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ import { getNeode, getDriver } from '../../db/neo4j'
|
||||
import createServer from '../../server'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
|
||||
|
||||
let mutate
|
||||
let authenticatedUser
|
||||
let variables
|
||||
@ -25,12 +24,10 @@ beforeAll(async () => {
|
||||
mutate = createTestClient(server).mutate
|
||||
})
|
||||
|
||||
|
||||
afterAll(async () => {
|
||||
//await cleanDatabase()
|
||||
// await cleanDatabase()
|
||||
})
|
||||
|
||||
|
||||
const createPostMutation = gql`
|
||||
mutation($title: String!, $content: String!, $categoryIds: [ID]) {
|
||||
CreatePost(title: $title, content: $content, categoryIds: $categoryIds) {
|
||||
@ -55,16 +52,18 @@ describe('languagesMiddleware', () => {
|
||||
icon: 'university',
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('detects German', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
content: 'Jeder sollte vor seiner eigenen Tür kehren.',
|
||||
}
|
||||
await expect(mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})).resolves.toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'de',
|
||||
@ -72,16 +71,18 @@ describe('languagesMiddleware', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('detects English', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
content: 'A journey of a thousand miles begins with a single step.',
|
||||
}
|
||||
await expect(mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})).resolves.toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'en',
|
||||
@ -95,15 +96,37 @@ describe('languagesMiddleware', () => {
|
||||
...variables,
|
||||
content: 'A caballo regalado, no le mires el diente.',
|
||||
}
|
||||
await expect(mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})).resolves.toMatchObject({
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'es',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('detects German in between lots of html tags', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
content:
|
||||
'<strong>Jeder</strong> <strike>sollte</strike> <strong>vor</strong> <span>seiner</span> eigenen <blockquote>Tür</blockquote> kehren.',
|
||||
}
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'de',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user