Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tescher committed Oct 25, 2022
1 parent a762164 commit 68fac4c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/react-app/tests/integration/api/bounty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import bountiesHandler from '@app/pages/api/bounties';
import bountyHandler from '@app/pages/api/bounties/[id]';
import { testBounty } from '@tests/stubs/bounty.stub';
import bounties from '@tests/stubs/bounties.stub.json';
import { testUser } from '@tests/stubs/user.stub';
import PAID_STATUS from '@app/constants/paidStatus';
import User from '@app/models/User';

describe('Testing the bounty API', () => {
let connection: Connection;
Expand Down Expand Up @@ -40,6 +42,7 @@ describe('Testing the bounty API', () => {
afterEach(async () => {
jest.clearAllMocks();
await Bounty.deleteMany();
await User.deleteMany();
});

describe('CRUD operations through the API', () => {
Expand Down Expand Up @@ -369,5 +372,37 @@ describe('Testing the bounty API', () => {
});
expect(data).toEqual(sortedByRewardDesc);
});

it('API returns no payee data if Bounty is claimed and user is not registered', async () => {
req.method = 'GET';
req.query = {
asc: 'false',
sortBy: 'reward',
};
await bountiesHandler(req, res);
const { data }: { data: BountyCollection[] } = res._getJSONData();
const claimedBounty : any = data.find(bounty => bounty._id == '10f6585b453e70eed340e8e3');
expect(claimedBounty).toBeDefined();
expect(claimedBounty?.claimedBy.discordId).toEqual('324423432343239764');
expect(claimedBounty?.payeeData?.userDiscordId).toBeUndefined();
});

it('API returns payee data if Bounty is claimed and user is registered', async () => {
await User.insertMany(testUser);

req.method = 'GET';
req.query = {
asc: 'false',
sortBy: 'reward',
};
await bountiesHandler(req, res);
const { data }: { data: BountyCollection[] } = res._getJSONData();
const claimedBounty : any = data.find(bounty => bounty._id == '10f6585b453e70eed340e8e3');
expect(claimedBounty).toBeDefined();
expect(claimedBounty?.claimedBy.discordId).toEqual('324423432343239764');
expect(claimedBounty?.payeeData?.userDiscordId).toEqual('324423432343239764');
expect(claimedBounty?.payeeData?.walletAddress).toEqual('0xb57a97cDbEc1B71E9F0E33e76f7334984375cfdf');
});

});
});
6 changes: 6 additions & 0 deletions packages/react-app/tests/stubs/user.stub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { UserProps } from '../../src/models/User';

export const testUser: UserProps = {
userDiscordId : '324423432343239764',
walletAddress : '0xb57a97cDbEc1B71E9F0E33e76f7334984375cfdf',
};

0 comments on commit 68fac4c

Please sign in to comment.