Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorsoft committed Jan 9, 2025
1 parent 7d462b4 commit 9b81bbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions libs/model/src/user/UserReferrals.projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ export function UserReferrals(): Projection<typeof inputs> {
transaction,
});
if (referrerUser)
await referrerUser.increment('referral_count', {
by: 1,
transaction,
});
await referrerUser.update(
{
referral_count: models.sequelize.literal(
'coalesce(referral_count, 0) + 1',
),
},
{ transaction },
);

// set the referred_by_address of the address to the address that referred them
await models.Address.update(
Expand Down
8 changes: 4 additions & 4 deletions libs/model/test/referral/referral-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Actor, command, dispose, query } from '@hicommonwealth/core';
import { EvmEventSignatures } from '@hicommonwealth/evm-protocols';
import * as schemas from '@hicommonwealth/schemas';
import { ZERO_ADDRESS } from '@hicommonwealth/shared';
import { JoinCommunity } from 'model/src/community';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { z } from 'zod';
import { JoinCommunity } from '../../src/community';
import { models } from '../../src/database';
import { ChainEventPolicy } from '../../src/policies';
import { seed } from '../../src/tester';
Expand Down Expand Up @@ -152,9 +152,9 @@ describe('Referral lifecycle', () => {
});
expect(referrals).toMatchObject(expectedReferrals);

// member user joins the community using referrals
// nonMember joins the community using referrals
await command(JoinCommunity(), {
actor: member,
actor: nonMember,
payload: {
community_id,
referrer_address: admin.address,
Expand All @@ -170,7 +170,7 @@ describe('Referral lifecycle', () => {
expect(referrerUser?.referral_count).toBe(1);

const refereeAddress = await models.Address.findOne({
where: { user_id: member.user.id, community_id },
where: { user_id: nonMember.user.id, community_id },
});
expect(refereeAddress?.referred_by_address).toBe(admin.address);

Expand Down
3 changes: 3 additions & 0 deletions libs/model/test/utils/community-seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export async function seedCommunity({
profile: { name: role },
isAdmin: role === 'admin',
is_welcome_onboard_flow_complete: false,
referral_count: 0,
referral_eth_earnings: 0,
xp_points: 0,
}));

// seed base community
Expand Down

0 comments on commit 9b81bbb

Please sign in to comment.