Skip to content

Commit

Permalink
Added round number generator
Browse files Browse the repository at this point in the history
  • Loading branch information
aminlatifi committed Sep 29, 2024
1 parent 78ddc0d commit 632dbee
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
15 changes: 9 additions & 6 deletions src/repositories/earlyAccessRoundRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
findActiveEarlyAccessRound,
fillMissingTokenPriceInEarlyAccessRounds,
} from './earlyAccessRoundRepository';
import { saveEARoundDirectlyToDb } from '../../test/testUtils';
import {
generateEARoundNumber,
saveEARoundDirectlyToDb,
} from '../../test/testUtils';
import { CoingeckoPriceAdapter } from '../adapters/price/CoingeckoPriceAdapter';
import { QACC_DONATION_TOKEN_COINGECKO_ID } from '../constants/qacc';

Expand Down Expand Up @@ -37,7 +40,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {

it('should save a new Early Access Round directly to the database', async () => {
const roundData = {
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
};
Expand All @@ -57,12 +60,12 @@ describe('EarlyAccessRound Repository Test Cases', () => {
it('should find all Early Access Rounds', async () => {
// Save a couple of rounds first
await saveEARoundDirectlyToDb({
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
});
await saveEARoundDirectlyToDb({
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-06'),
endDate: new Date('2024-09-10'),
});
Expand All @@ -77,13 +80,13 @@ describe('EarlyAccessRound Repository Test Cases', () => {

it('should find the active Early Access Round', async () => {
const activeRoundData = {
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date(new Date().setDate(new Date().getDate() - 1)), // yesterday
endDate: new Date(new Date().setDate(new Date().getDate() + 1)), // tomorrow
};

const inactiveRoundData = {
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: new Date(new Date().getDate() + 1),
endDate: new Date(new Date().getDate() + 2),
};
Expand Down
12 changes: 7 additions & 5 deletions src/repositories/projectRoundRecordRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect } from 'chai';
import {
createDonationData,
createProjectData,
generateEARoundNumber,
generateQfRoundNumber,
saveDonationDirectlyToDb,
saveProjectDirectlyToDb,
SEED_DATA,
Expand Down Expand Up @@ -52,17 +54,17 @@ describe('ProjectRoundRecord test cases', () => {

const earlyAccessRounds = await EarlyAccessRound.create([
{
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date('2000-01-01'),
endDate: new Date('2000-01-02'),
},
{
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: new Date('2000-01-02'),
endDate: new Date('2000-01-03'),
},
{
roundNumber: 3,
roundNumber: generateEARoundNumber(),
startDate: new Date('2000-01-03'),
endDate: new Date('2000-01-04'),
},
Expand All @@ -72,7 +74,7 @@ describe('ProjectRoundRecord test cases', () => {
earlyAccessRounds;

qfRound1 = await QfRound.create({
roundNumber: 1,
roundNumber: generateQfRoundNumber(),
isActive: true,
name: new Date().toString() + ' - 1',
allocatedFund: 100,
Expand All @@ -82,7 +84,7 @@ describe('ProjectRoundRecord test cases', () => {
endDate: new Date('2001-01-03'),
}).save();
qfRound2 = await QfRound.create({
roundNumber: 2,
roundNumber: generateQfRoundNumber(),
isActive: true,
name: new Date().toString() + ' - 2',
allocatedFund: 100,
Expand Down
5 changes: 3 additions & 2 deletions src/repositories/projectUserRecordRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import moment from 'moment';
import {
createDonationData,
createProjectData,
generateEARoundNumber,
generateQfRoundNumber,
generateRandomEtheriumAddress,
saveDonationDirectlyToDb,
Expand Down Expand Up @@ -132,12 +133,12 @@ describe('projectUserRecordRepository', () => {

it('should return correct ea and qf donation amounts', async () => {
const ea1 = await saveEARoundDirectlyToDb({
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
});
const ea2 = await saveEARoundDirectlyToDb({
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-06'),
endDate: new Date('2024-09-10'),
});
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/projectResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ function getProjectRoundRecordsTestCases() {
// Create Early Access Round (Assuming you have such an entity)
earlyAccessRoundId = (
await EarlyAccessRound.create({
roundNumber: 1,
roundNumber: generateQfRoundNumber(),
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
}).save()
Expand Down
17 changes: 11 additions & 6 deletions src/resolvers/roundsResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { assert } from 'chai';
import moment from 'moment';
import axios from 'axios';
import { AppDataSource } from '../orm';
import { graphqlUrl } from '../../test/testUtils';
import {
generateEARoundNumber,
generateQfRoundNumber,
graphqlUrl,
} from '../../test/testUtils';
import { QfRound } from '../entities/qfRound';
import { EarlyAccessRound } from '../entities/earlyAccessRound';
import { generateRandomString } from '../utils/utils';
Expand Down Expand Up @@ -52,13 +56,13 @@ function fetchAllRoundsTestCases() {
it('should return all rounds (QF Rounds and Early Access Rounds)', async () => {
// Create Early Access Rounds
const earlyAccessRound1 = await EarlyAccessRound.create({
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date(),
endDate: moment().add(3, 'days').toDate(),
}).save();

const earlyAccessRound2 = await EarlyAccessRound.create({
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: moment().add(4, 'days').toDate(),
endDate: moment().add(7, 'days').toDate(),
}).save();
Expand All @@ -67,6 +71,7 @@ function fetchAllRoundsTestCases() {
const qfRound1 = await QfRound.create({
name: 'QF Round 1',
slug: generateRandomString(10),
roundNumber: generateQfRoundNumber(),
allocatedFund: 100000,
minimumPassportScore: 8,
beginDate: new Date(),
Expand Down Expand Up @@ -145,7 +150,7 @@ function fetchActiveRoundTestCases() {
it('should return the currently active Early Access round and no active QF round', async () => {
// Create an active Early Access Round
const activeEarlyAccessRound = await EarlyAccessRound.create({
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: moment().subtract(1, 'days').toDate(),
endDate: moment().add(2, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -179,7 +184,7 @@ function fetchActiveRoundTestCases() {
it('should return the currently active QF round and no active Early Access round', async () => {
// Create a non-active Early Access Round
await EarlyAccessRound.create({
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: moment().add(10, 'days').toDate(),
endDate: moment().add(20, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -210,7 +215,7 @@ function fetchActiveRoundTestCases() {
it('should return null when there are no active rounds', async () => {
// Create a non-active Early Access Round
await EarlyAccessRound.create({
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: moment().add(10, 'days').toDate(),
endDate: moment().add(20, 'days').toDate(),
}).save();
Expand Down
10 changes: 6 additions & 4 deletions src/resolvers/userResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { User } from '../entities/user';
import {
createDonationData,
createProjectData,
generateQfRoundNumber,
generateEARoundNumber,
generateRandomEtheriumAddress,
generateTestAccessToken,
graphqlUrl,
Expand Down Expand Up @@ -1315,22 +1315,24 @@ function projectUserTotalDonationAmountTestCases() {
const project = await saveProjectDirectlyToDb(createProjectData());

const ea1 = await saveEARoundDirectlyToDb({
roundNumber: 1,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
});
const ea2 = await saveEARoundDirectlyToDb({
roundNumber: 2,
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-06'),
endDate: new Date('2024-09-10'),
});

const qfRoundNumber = generateEARoundNumber();
const qfRound = await QfRound.create({
isActive: true,
name: 'test qf ',
allocatedFund: 100,
minimumPassportScore: 8,
slug: 'QF - 2024-09-10 - ' + generateQfRoundNumber(),
slug: 'QF - 2024-09-10 - ' + qfRoundNumber,
roundNumber: qfRoundNumber,
beginDate: moment('2024-09-10').add(1, 'days').toDate(),
endDate: moment('2024-09-10').add(10, 'days').toDate(),
}).save();
Expand Down
4 changes: 4 additions & 0 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2070,3 +2070,7 @@ let nextQfRoundNumber = 1000;
export function generateQfRoundNumber(): number {
return nextQfRoundNumber++;
}
let nextEARoundNumber = 1000;
export function generateEARoundNumber(): number {
return nextEARoundNumber++;
}

0 comments on commit 632dbee

Please sign in to comment.