mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Changes requested by @mattwr18
This commit is contained in:
parent
48564565a5
commit
9c08db22dc
@ -41,16 +41,17 @@ export default {
|
||||
RETURN resource {.*, __typename: labels(resource)[0]}
|
||||
LIMIT $limit
|
||||
`
|
||||
|
||||
const myQuery = queryString(query)
|
||||
|
||||
const session = context.driver.session()
|
||||
const searchResultPromise = session.readTransaction(async transaction => {
|
||||
const postTransactionResponse = transaction.run(postCypher, {
|
||||
query: queryString(query),
|
||||
query: myQuery,
|
||||
limit,
|
||||
thisUserId,
|
||||
})
|
||||
const userTransactionResponse = transaction.run(userCypher, {
|
||||
query: queryString(query),
|
||||
query: myQuery,
|
||||
limit,
|
||||
thisUserId,
|
||||
})
|
||||
@ -61,8 +62,6 @@ export default {
|
||||
const [postResults, userResults] = await searchResultPromise
|
||||
log(postResults)
|
||||
log(userResults)
|
||||
// console.log(postResults.summary.query.parameters)
|
||||
// console.log(userResults)
|
||||
return [...postResults.records, ...userResults.records].map(r => r.get('resource'))
|
||||
} finally {
|
||||
session.close()
|
||||
|
||||
@ -4,7 +4,7 @@ import { getNeode, getDriver } from '../../db/neo4j'
|
||||
import createServer from '../../server'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
|
||||
let query, authenticatedUser
|
||||
let query, authenticatedUser, user
|
||||
|
||||
const driver = getDriver()
|
||||
const neode = getNeode()
|
||||
@ -44,36 +44,60 @@ const searchQuery = gql`
|
||||
}
|
||||
}
|
||||
`
|
||||
let user
|
||||
describe('resolvers/searches', () => {
|
||||
let variables
|
||||
|
||||
describe('resolvers', () => {
|
||||
describe('searches', () => {
|
||||
let variables
|
||||
describe('given one user', () => {
|
||||
beforeAll(async () => {
|
||||
user = await Factory.build('user', {
|
||||
id: 'a-user',
|
||||
name: 'John Doe',
|
||||
slug: 'john-doe',
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
})
|
||||
|
||||
describe('given one user', () => {
|
||||
beforeAll(async () => {
|
||||
user = await Factory.build('user', {
|
||||
id: 'a-user',
|
||||
name: 'John Doe',
|
||||
slug: 'john-doe',
|
||||
describe('query contains first name of user', () => {
|
||||
it('finds the user', async () => {
|
||||
variables = { query: 'John' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
id: 'a-user',
|
||||
name: 'John Doe',
|
||||
slug: 'john-doe',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding one post', () => {
|
||||
beforeAll(async () => {
|
||||
await Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
{ authorId: 'a-user' },
|
||||
)
|
||||
})
|
||||
|
||||
const factoryOptions = {
|
||||
authorId: 'a-user',
|
||||
}
|
||||
|
||||
describe('query contains first name of user', () => {
|
||||
it('finds the user', async () => {
|
||||
variables = { query: 'John' }
|
||||
describe('query contains title of post', () => {
|
||||
it('finds the post', async () => {
|
||||
variables = { query: 'beitrag' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
id: 'a-user',
|
||||
name: 'John Doe',
|
||||
slug: 'john-doe',
|
||||
__typename: 'Post',
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -81,326 +105,97 @@ describe('resolvers', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding one post', () => {
|
||||
beforeAll(async () => {
|
||||
await Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
describe('casing', () => {
|
||||
it('does not matter', async () => {
|
||||
variables = { query: 'BEITRAG' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
],
|
||||
},
|
||||
factoryOptions,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query contains title of post', () => {
|
||||
it('finds the post', async () => {
|
||||
variables = { query: 'beitrag' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
],
|
||||
describe('query consists of words not present in the corpus', () => {
|
||||
it('returns empty search results', async () => {
|
||||
await expect(
|
||||
query({ query: searchQuery, variables: { query: 'Unfug' } }),
|
||||
).resolves.toMatchObject({ data: { findResources: [] } })
|
||||
})
|
||||
})
|
||||
|
||||
describe('testing different post content', () => {
|
||||
beforeAll(async () => {
|
||||
return Promise.all([
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'b-post',
|
||||
title: 'Aufruf',
|
||||
content: 'Jeder sollte seinen Beitrag leisten.',
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('casing', () => {
|
||||
it('does not matter', async () => {
|
||||
variables = { query: 'BEITRAG' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
],
|
||||
{ authorId: 'a-user' },
|
||||
),
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query consists of words not present in the corpus', () => {
|
||||
it('returns empty search results', async () => {
|
||||
await expect(
|
||||
query({ query: searchQuery, variables: { query: 'Unfug' } }),
|
||||
).resolves.toMatchObject({ data: { findResources: [] } })
|
||||
})
|
||||
})
|
||||
|
||||
describe('testing different post content', () => {
|
||||
beforeAll(async () => {
|
||||
return Promise.all([
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'b-post',
|
||||
title: 'Aufruf',
|
||||
content: 'Jeder sollte seinen Beitrag leisten.',
|
||||
},
|
||||
factoryOptions,
|
||||
),
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
factoryOptions,
|
||||
),
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²
|
||||
{ authorId: 'a-user' },
|
||||
),
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
factoryOptions,
|
||||
),
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'd-post',
|
||||
title: 'Der Panther',
|
||||
content: `Sein Blick ist vom Vorübergehn der Stäbe
|
||||
},
|
||||
{ authorId: 'a-user' },
|
||||
),
|
||||
Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'd-post',
|
||||
title: 'Der Panther',
|
||||
content: `Sein Blick ist vom Vorübergehn der Stäbe
|
||||
so müd geworden, daß er nichts mehr hält.
|
||||
Ihm ist, als ob es tausend Stäbe gäbe
|
||||
und hinter tausend Stäben keine Welt.`,
|
||||
},
|
||||
factoryOptions,
|
||||
),
|
||||
])
|
||||
})
|
||||
|
||||
describe('a post which content contains the title of the first post', () => {
|
||||
describe('query contains the title of the first post', () => {
|
||||
it('finds both posts', async () => {
|
||||
variables = { query: 'beitrag' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.arrayContaining([
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'b-post',
|
||||
title: 'Aufruf',
|
||||
content: 'Jeder sollte seinen Beitrag leisten.',
|
||||
},
|
||||
]),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('a post that contains a hyphen between two words and German quotation marks', () => {
|
||||
describe('hyphens in query', () => {
|
||||
it('will be treated as ordinary characters', async () => {
|
||||
variables = { query: 'tee-ei' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('German quotation marks in query', () => {
|
||||
it('will be treated as ordinary characters', async () => {
|
||||
variables = { query: '„teeei“' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('a post that contains a simple mathematical exprssion and linebreaks', () => {
|
||||
describe('query a part of the mathematical expression', () => {
|
||||
it('finds that post', async () => {
|
||||
variables = { query: '(a - b)²' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²<br>
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²<br>
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query the same part of the mathematical expression without spaces', () => {
|
||||
it('finds that post', async () => {
|
||||
variables = { query: '(a-b)²' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²<br>
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²<br>
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query the mathematical expression over linebreak', () => {
|
||||
it('finds that post', async () => {
|
||||
variables = { query: '+ b² 2.' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²<br>
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²<br>
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('a post that contains a poem', () => {
|
||||
describe('query for more than one word, e.g. the title of the poem', () => {
|
||||
it('finds the poem and another post that contains only one word but with lower score', async () => {
|
||||
variables = { query: 'der panther' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'd-post',
|
||||
title: 'Der Panther',
|
||||
content: `Sein Blick ist vom Vorübergehn der Stäbe<br>
|
||||
so müd geworden, daß er nichts mehr hält.<br>
|
||||
Ihm ist, als ob es tausend Stäbe gäbe<br>
|
||||
und hinter tausend Stäben keine Welt.`,
|
||||
},
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query for the first four letters of two longer words', () => {
|
||||
it('finds the posts that contain words starting with these four letters', async () => {
|
||||
variables = { query: 'Vorü Subs' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.arrayContaining([
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'd-post',
|
||||
title: 'Der Panther',
|
||||
content: `Sein Blick ist vom Vorübergehn der Stäbe<br>
|
||||
so müd geworden, daß er nichts mehr hält.<br>
|
||||
Ihm ist, als ob es tausend Stäbe gäbe<br>
|
||||
und hinter tausend Stäben keine Welt.`,
|
||||
},
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
]),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
{ authorId: 'a-user' },
|
||||
),
|
||||
])
|
||||
})
|
||||
|
||||
describe('adding two users that have the same word in their slugs', () => {
|
||||
beforeAll(async () => {
|
||||
await Promise.all([
|
||||
Factory.build('user', {
|
||||
id: 'c-user',
|
||||
name: 'Rainer Maria Rilke',
|
||||
slug: 'rainer-maria-rilke',
|
||||
}),
|
||||
Factory.build('user', {
|
||||
id: 'd-user',
|
||||
name: 'Erich Maria Remarque',
|
||||
slug: 'erich-maria-remarque',
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
describe('query the word that both slugs contain', () => {
|
||||
it('finds both users', async () => {
|
||||
variables = { query: '-maria-' }
|
||||
describe('a post which content contains the title of the first post', () => {
|
||||
describe('query contains the title of the first post', () => {
|
||||
it('finds both posts', async () => {
|
||||
variables = { query: 'beitrag' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.arrayContaining([
|
||||
{
|
||||
__typename: 'User',
|
||||
id: 'c-user',
|
||||
name: 'Rainer Maria Rilke',
|
||||
slug: 'rainer-maria-rilke',
|
||||
__typename: 'Post',
|
||||
id: 'a-post',
|
||||
title: 'Beitrag',
|
||||
content: 'Ein erster Beitrag',
|
||||
},
|
||||
{
|
||||
__typename: 'User',
|
||||
id: 'd-user',
|
||||
name: 'Erich Maria Remarque',
|
||||
slug: 'erich-maria-remarque',
|
||||
__typename: 'Post',
|
||||
id: 'b-post',
|
||||
title: 'Aufruf',
|
||||
content: 'Jeder sollte seinen Beitrag leisten.',
|
||||
},
|
||||
]),
|
||||
},
|
||||
@ -409,36 +204,154 @@ und hinter tausend Stäben keine Welt.`,
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding a post, written by a user who is muted by the authenticated user', () => {
|
||||
beforeAll(async () => {
|
||||
const mutedUser = await Factory.build('user', {
|
||||
id: 'muted-user',
|
||||
name: 'Muted',
|
||||
slug: 'muted',
|
||||
})
|
||||
await user.relateTo(mutedUser, 'muted')
|
||||
await Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'muted-post',
|
||||
title: 'Beleidigender Beitrag',
|
||||
content: 'Dieser Beitrag stammt von einem bleidigendem Nutzer.',
|
||||
},
|
||||
{ authorId: 'muted-user' },
|
||||
)
|
||||
})
|
||||
|
||||
describe('query for text in a post written by a muted user', () => {
|
||||
it('does not include the post of the muted user in the results', async () => {
|
||||
variables = { query: 'beitrag' }
|
||||
describe('a post that contains a hyphen between two words and German quotation marks', () => {
|
||||
describe('hyphens in query', () => {
|
||||
it('will be treated as ordinary characters', async () => {
|
||||
variables = { query: 'tee-ei' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.not.arrayContaining([
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'muted-post',
|
||||
title: 'Beleidigender Beitrag',
|
||||
content: 'Dieser Beitrag stammt von einem bleidigendem Nutzer.',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('German quotation marks in query to test unicode characters (\u201E ... \u201C)', () => {
|
||||
it('will be treated as ordinary characters', async () => {
|
||||
variables = { query: '„teeei“' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('a post that contains a simple mathematical exprssion and line breaks', () => {
|
||||
describe('query a part of the mathematical expression', () => {
|
||||
it('finds that post', async () => {
|
||||
variables = { query: '(a - b)²' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²<br>
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²<br>
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query the same part of the mathematical expression without spaces', () => {
|
||||
it('finds that post', async () => {
|
||||
variables = { query: '(a-b)²' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²<br>
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²<br>
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query the mathematical expression over line break', () => {
|
||||
it('finds that post', async () => {
|
||||
variables = { query: '+ b² 2.' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'c-post',
|
||||
title: 'Die binomischen Formeln',
|
||||
content: `1. binomische Formel: (a + b)² = a² + 2ab + b²<br>
|
||||
2. binomische Formel: (a - b)² = a² - 2ab + b²<br>
|
||||
3. binomische Formel: (a + b)(a - b) = a² - b²`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('a post that contains a poem', () => {
|
||||
describe('query for more than one word, e.g. the title of the poem', () => {
|
||||
it('finds the poem and another post that contains only one word but with lower score', async () => {
|
||||
variables = { query: 'der panther' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: [
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'd-post',
|
||||
title: 'Der Panther',
|
||||
content: `Sein Blick ist vom Vorübergehn der Stäbe<br>
|
||||
so müd geworden, daß er nichts mehr hält.<br>
|
||||
Ihm ist, als ob es tausend Stäbe gäbe<br>
|
||||
und hinter tausend Stäben keine Welt.`,
|
||||
},
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('query for the first four letters of two longer words', () => {
|
||||
it('finds the posts that contain words starting with these four letters', async () => {
|
||||
variables = { query: 'Vorü Subs' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.arrayContaining([
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'd-post',
|
||||
title: 'Der Panther',
|
||||
content: `Sein Blick ist vom Vorübergehn der Stäbe<br>
|
||||
so müd geworden, daß er nichts mehr hält.<br>
|
||||
Ihm ist, als ob es tausend Stäbe gäbe<br>
|
||||
und hinter tausend Stäben keine Welt.`,
|
||||
},
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'g-post',
|
||||
title: 'Zusammengesetzte Wörter',
|
||||
content: `Ein Bindestrich kann zwischen zwei Substantiven auch dann gesetzt werden, wenn drei gleichlautende Buchstaben aufeinandertreffen. Das ist etwa bei einem „Teeei“ der Fall, das so korrekt geschrieben ist. Möglich ist hier auch die Schreibweise mit Bindestrich: Tee-Ei.`,
|
||||
},
|
||||
]),
|
||||
},
|
||||
@ -447,6 +360,85 @@ und hinter tausend Stäben keine Welt.`,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding two users that have the same word in their slugs', () => {
|
||||
beforeAll(async () => {
|
||||
await Promise.all([
|
||||
Factory.build('user', {
|
||||
id: 'c-user',
|
||||
name: 'Rainer Maria Rilke',
|
||||
slug: 'rainer-maria-rilke',
|
||||
}),
|
||||
Factory.build('user', {
|
||||
id: 'd-user',
|
||||
name: 'Erich Maria Remarque',
|
||||
slug: 'erich-maria-remarque',
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
describe('query the word that both slugs contain', () => {
|
||||
it('finds both users', async () => {
|
||||
variables = { query: '-maria-' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.arrayContaining([
|
||||
{
|
||||
__typename: 'User',
|
||||
id: 'c-user',
|
||||
name: 'Rainer Maria Rilke',
|
||||
slug: 'rainer-maria-rilke',
|
||||
},
|
||||
{
|
||||
__typename: 'User',
|
||||
id: 'd-user',
|
||||
name: 'Erich Maria Remarque',
|
||||
slug: 'erich-maria-remarque',
|
||||
},
|
||||
]),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding a post, written by a user who is muted by the authenticated user', () => {
|
||||
beforeAll(async () => {
|
||||
const mutedUser = await Factory.build('user', {
|
||||
id: 'muted-user',
|
||||
name: 'Muted',
|
||||
slug: 'muted',
|
||||
})
|
||||
await user.relateTo(mutedUser, 'muted')
|
||||
await Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'muted-post',
|
||||
title: 'Beleidigender Beitrag',
|
||||
content: 'Dieser Beitrag stammt von einem bleidigendem Nutzer.',
|
||||
},
|
||||
{ authorId: 'muted-user' },
|
||||
)
|
||||
})
|
||||
|
||||
describe('query for text in a post written by a muted user', () => {
|
||||
it('does not include the post of the muted user in the results', async () => {
|
||||
variables = { query: 'beitrag' }
|
||||
await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
findResources: expect.not.arrayContaining([
|
||||
{
|
||||
__typename: 'Post',
|
||||
id: 'muted-post',
|
||||
title: 'Beleidigender Beitrag',
|
||||
content: 'Dieser Beitrag stammt von einem bleidigendem Nutzer.',
|
||||
},
|
||||
]),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -14,26 +14,20 @@ const matchWholeText = (str, boost = 8) => {
|
||||
}
|
||||
|
||||
const matchEachWordExactly = (str, boost = 4) => {
|
||||
if (str.includes(' ')) {
|
||||
const tmp = str
|
||||
.split(' ')
|
||||
.map((s, i) => (i === 0 ? `"${s}"` : `AND "${s}"`))
|
||||
.join(' ')
|
||||
return `(${tmp})^${boost}`
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
if (!str.includes(' ')) return ''
|
||||
const tmp = str
|
||||
.split(' ')
|
||||
.map((s, i) => (i === 0 ? `"${s}"` : `AND "${s}"`))
|
||||
.join(' ')
|
||||
return `(${tmp})^${boost}`
|
||||
}
|
||||
|
||||
const matchSomeWordsExactly = (str, boost = 2) => {
|
||||
if (str.includes(' ')) {
|
||||
return str
|
||||
.split(' ')
|
||||
.map(s => `"${s}"^${boost}`)
|
||||
.join(' ')
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
if (!str.includes(' ')) return ''
|
||||
return str
|
||||
.split(' ')
|
||||
.map(s => `"${s}"^${boost}`)
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
const matchBeginningOfWords = str => {
|
||||
|
||||
@ -10,7 +10,7 @@ describe('queryString', () => {
|
||||
})
|
||||
|
||||
describe('whitespace', () => {
|
||||
it('is normalized correctly', () => {
|
||||
it('normalizes correctly', () => {
|
||||
expect(normalizeWhitespace(' a \t \n b \n ')).toEqual('a b')
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user