mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
basic tests for language detection
This commit is contained in:
parent
f3847e5c97
commit
3bd8a531f1
@ -1,18 +1,15 @@
|
||||
import LanguageDetect from 'languagedetect'
|
||||
|
||||
const setPostLanguage = (text) => {
|
||||
console.log(text)
|
||||
const lngDetector = new LanguageDetect()
|
||||
lngDetector.setLanguageType('iso2')
|
||||
const result = lngDetector.detect(text, 2)
|
||||
console.log(result)
|
||||
return result[0][0]
|
||||
}
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
CreatePost: async (resolve, root, args, context, info) => {
|
||||
console.log('CreatePost, language', args)
|
||||
args.language = await setPostLanguage(args.content)
|
||||
return resolve(root, args, context, info)
|
||||
},
|
||||
|
||||
@ -23,15 +23,6 @@ beforeAll(async () => {
|
||||
},
|
||||
})
|
||||
mutate = createTestClient(server).mutate
|
||||
await cleanDatabase()
|
||||
variables = {}
|
||||
const user = await Factory.build('user')
|
||||
authenticatedUser = await user.toJson()
|
||||
await Factory.build('category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
icon: 'university',
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -54,6 +45,17 @@ describe('languagesMiddleware', () => {
|
||||
categoryIds: ['cat9'],
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
await cleanDatabase()
|
||||
const user = await Factory.build('user')
|
||||
authenticatedUser = await user.toJson()
|
||||
await Factory.build('category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
icon: 'university',
|
||||
})
|
||||
})
|
||||
|
||||
it('detects German', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
@ -71,4 +73,37 @@ 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({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'en',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('detects Spanish', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
content: 'A caballo regalado, no le mires el diente.',
|
||||
}
|
||||
await expect(mutate({
|
||||
mutation: createPostMutation,
|
||||
variables,
|
||||
})).resolves.toMatchObject({
|
||||
data: {
|
||||
CreatePost: {
|
||||
language: 'es',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user