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

Fixes xp queries #11255

Merged
merged 2 commits into from
Mar 4, 2025
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
2 changes: 1 addition & 1 deletion libs/model/src/quest/GetQuests.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function GetQuests(): Query<typeof schemas.GetQuests> {
FROM
"Quests" as Q
LEFT JOIN "QuestActionMetas" QAS on QAS.quest_id = Q.id
${filterConditions.length > 0 ? `WHERE ${filterConditions.join(' AND ')}` : ''}
${filterConditions.length > 0 ? `WHERE Q.id > 0 AND ${filterConditions.join(' AND ')}` : ''}
GROUP BY Q.id
ORDER BY Q.${order} ${direction}
LIMIT :limit OFFSET :offset
Expand Down
28 changes: 11 additions & 17 deletions libs/model/src/user/GetXps.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,17 @@ export function GetXps(): Query<typeof schemas.GetXps> {
as: 'quest_action_meta',
required: true,
where: event_name ? { event_name } : {},
include: community_id
? [
{
model: models.Quest,
required: true,
attributes: ['id', 'name'],
where: { community_id, ...(quest_id && { id: quest_id }) },
},
]
: [
{
model: models.Quest,
required: true,
attributes: ['id', 'name'],
...(quest_id && { where: { id: quest_id } }),
},
],
include: [
{
model: models.Quest,
required: true,
attributes: ['id', 'name'],
where: {
...(community_id && { community_id }),
...(quest_id ? { id: quest_id } : { id: { [Op.gt]: 0 } }),
},
},
],
},
];

Expand Down
16 changes: 7 additions & 9 deletions libs/model/test/user/user-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,12 @@ describe('User lifecycle', () => {
});

it('should query previous xp logs', async () => {
// 9 events
// 8 events (skipping negative system quest id)
const xps1 = await query(GetXps(), {
actor: admin,
payload: {},
});
expect(xps1!.length).to.equal(9);
expect(xps1!.length).to.equal(8);
xps1?.forEach((xp) => {
expect(xp.quest_id).to.be.a('number');
expect(xp.quest_action_meta_id).to.be.a('number');
Expand All @@ -493,12 +493,12 @@ describe('User lifecycle', () => {
expect(xp.event_name).to.equal('CommentUpvoted');
});

// 5 events after first CommentUpvoted
// 4 events after first CommentUpvoted
const xps3 = await query(GetXps(), {
actor: admin,
payload: { from: xps2!.at(-1)!.created_at },
});
expect(xps3!.length).to.equal(5);
expect(xps3!.length).to.equal(4);

// 4 events for member (ThreadCreated and CommentUpvoted)
const xps4 = await query(GetXps(), {
Expand All @@ -511,16 +511,14 @@ describe('User lifecycle', () => {
.be.true;
});

// 2 events for new actor (joining and sign up flow completed)
// 1 event for new actor (joining)
const xps5 = await query(GetXps(), {
actor: admin,
payload: { user_id: new_actor.user.id },
});
expect(xps5!.length).to.equal(2);
expect(xps5!.length).to.equal(1);
xps5?.forEach((xp) => {
expect(
['SignUpFlowCompleted', 'CommunityJoined'].includes(xp.event_name),
).to.be.true;
expect(['CommunityJoined'].includes(xp.event_name)).to.be.true;
});

// 3 CommentCreated events for admin
Expand Down
Loading