Skip to content

Commit

Permalink
fix: test fixes for new parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
drodil committed Feb 14, 2025
1 parent d84f591 commit 895b3ec
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
13 changes: 11 additions & 2 deletions plugins/qeta-backend/src/database/DatabaseQetaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,10 @@ export class DatabaseQetaStore implements QetaStore {
return {
collections: await Promise.all(
rows.map(async val => {
return this.mapCollectionEntity(val, user_ref, opts);
return this.mapCollectionEntity(val, user_ref, {
...opts,
includePosts: options.includePosts,
});
}),
),
total,
Expand Down Expand Up @@ -2341,7 +2344,13 @@ export class DatabaseQetaStore implements QetaStore {
user_ref,
{ collectionId: val.id, includeEntities: true },
postFilters,
{ tagsFilter: options?.tagFilters },
{
tagsFilter: options?.tagFilters,
includeComments: false,
includeAnswers: false,
includeAttachments: false,
includeVotes: false,
},
)
: { posts: [] },
this.db('attachments').where('collectionId', val.id).select('id'),
Expand Down
19 changes: 18 additions & 1 deletion plugins/qeta-backend/src/service/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ describe('createRouter', () => {

const response = await request(app).get('/posts/1');

expect(qetaStore.getPost).toHaveBeenCalledWith('user:default/mock', 1);
expect(qetaStore.getPost).toHaveBeenCalledWith(
'user:default/mock',
1,
true,
{},
);
expect(response.status).toEqual(200);
expect(response.body).toEqual({
...question,
Expand Down Expand Up @@ -335,6 +340,11 @@ describe('createRouter', () => {
entities: ['component:default/comp1'],
anonymous: false,
type: 'question',
opts: {
includeAnswers: false,
includeComments: false,
includeVotes: false,
},
});
});

Expand Down Expand Up @@ -364,6 +374,11 @@ describe('createRouter', () => {
entities: ['component:default/comp1'],
anonymous: false,
type: 'question',
opts: {
includeAnswers: false,
includeComments: false,
includeVotes: false,
},
});
expect(response.status).toEqual(201);
});
Expand Down Expand Up @@ -429,6 +444,7 @@ describe('createRouter', () => {
'user:default/mock',
'content',
question.created,
{},
);
expect(response.body).toEqual(
JSON.parse(JSON.stringify(questionWithComment)),
Expand All @@ -452,6 +468,7 @@ describe('createRouter', () => {
'user2',
'content2',
testDate,
{},
);
});

Expand Down
3 changes: 3 additions & 0 deletions plugins/qeta-backend/src/service/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const CollectionsQuerySchema: JSONSchemaType<CollectionsQuery> = {
tags: { type: 'array', items: { type: 'string' }, nullable: true },
entities: { type: 'array', items: { type: 'string' }, nullable: true },
entitiesRelation: { type: 'string', enum: ['and', 'or'], nullable: true },
includePosts: { type: 'boolean', nullable: true },
tagsRelation: { type: 'string', enum: ['and', 'or'], nullable: true },
fromDate: { type: 'string', nullable: true, format: 'date' },
toDate: { type: 'string', nullable: true, format: 'date' },
Expand Down Expand Up @@ -152,6 +153,8 @@ export const PostsQuerySchema: JSONSchemaType<PostsQuery> = {
tagsRelation: { type: 'string', enum: ['and', 'or'], nullable: true },
includeAnswers: { type: 'boolean', nullable: true },
includeVotes: { type: 'boolean', nullable: true },
includeAttachments: { type: 'boolean', nullable: true },
includeTags: { type: 'boolean', nullable: true },
includeEntities: { type: 'boolean', nullable: true },
includeTrend: { type: 'boolean', nullable: true },
includeComments: { type: 'boolean', nullable: true },
Expand Down
3 changes: 3 additions & 0 deletions plugins/qeta-common/src/api/QetaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface PostsQuery extends PaginatedQuery {
includeEntities?: boolean;
includeTrend?: boolean;
includeComments?: boolean;
includeTags?: boolean;
includeAttachments?: boolean;
fromDate?: string;
toDate?: string;
type?: PostType;
Expand All @@ -71,6 +73,7 @@ export interface CollectionsQuery extends PaginatedQuery {
owner?: string;
entities?: string[];
entitiesRelation?: 'and' | 'or';
includePosts?: boolean;
tags?: string[];
tagsRelation?: 'and' | 'or';
fromDate?: string;
Expand Down
3 changes: 3 additions & 0 deletions plugins/qeta-react/src/hooks/usePaginatedPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export function usePaginatedPosts(props: PaginatedPostsProps) {
limit: postsPerPage,
offset: (page - 1) * postsPerPage,
includeEntities: true,
includeAnswers: false,
includeComments: false,
includeAttachments: false,
author,
favorite,
...(getFiltersWithDateRange(filters) as any),
Expand Down

0 comments on commit 895b3ec

Please sign in to comment.