Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missed bracket notation #2475

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions __tests__/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,12 @@ describe('query searchSourceSuggestions', () => {

it('should return search suggestions', async () => {
await con.getRepository(Source).update({ id: 'a' }, { name: 'Java news' });
await con
.getRepository(Source)
.update({ id: 'b' }, { name: 'JavaScript news' });
await con.getRepository(Source).update(
{ id: 'b' },
{
name: 'JavaScript news',
},
);
const res = await client.query(QUERY('java'));
expect(res.errors).toBeFalsy();
expect(res.data.searchSourceSuggestions).toBeTruthy();
Expand Down Expand Up @@ -539,6 +542,37 @@ describe('query searchSourceSuggestions', () => {
},
]);
});
it('should only return public threshold sources', async () => {
await con.getRepository(Source).update(
{ id: 'squad' },
{
private: false,
flags: updateFlagsStatement<Source>({ publicThreshold: true }),
},
);
await con.getRepository(Source).update(
{ id: 'm' },
{
private: false,
},
);
const res = await client.query(QUERY('squad'));
expect(res.errors).toBeFalsy();
expect(res.data.searchSourceSuggestions).toBeTruthy();

const result = res.data.searchSourceSuggestions;

expect(result.query).toBe('squad');
expect(result.hits).toHaveLength(1);
expect(result.hits).toMatchObject([
{
id: 'squad',
image: 'http//image.com/s',
subtitle: 'squad',
title: 'Squad',
},
]);
});
});

describe('query searchUserSuggestions', () => {
Expand Down
22 changes: 15 additions & 7 deletions src/schema/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../common';
import { GQLPost } from './posts';
import { MeiliPagination, searchMeili } from '../integrations/meilisearch';
import { Keyword, Post, Source, UserPost } from '../entity';
import { Keyword, Post, Source, SourceType, UserPost } from '../entity';
import {
SearchSuggestionArgs,
defaultSearchLimit,
Expand Down Expand Up @@ -419,12 +419,20 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
.createQueryBuilder()
.select(`id, name as title, handle as subtitle, image`)
.where(`private = false`)
.andWhere(`name ILIKE :query`, {
query: `%${query}%`,
})
.orWhere(`handle ILIKE :query`, {
query: `%${query}%`,
})
.andWhere(
`(type != '${SourceType.Squad}' OR (flags->>'publicThreshold')::boolean IS TRUE)`,
)
.andWhere(
new Brackets((qb) => {
return qb
.where(`name ILIKE :query`, {
query: `%${query}%`,
})
.orWhere(`handle ILIKE :query`, {
query: `%${query}%`,
});
}),
)
.limit(getSearchLimit({ limit }));
const hits = await searchQuery.getRawMany();

Expand Down
Loading