Skip to content

Commit

Permalink
feat: New proposal limits for turbo spaces (#268)
Browse files Browse the repository at this point in the history
* feat: New proposal limits for turbo spaces

* add test cases

* Update proposal.test.ts

* fixes

* Fix test cases
  • Loading branch information
ChaituVR authored Dec 22, 2023
1 parent c3e79e1 commit 384afd0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getProposal(space, id) {
}

export async function getSpace(id: string, includeDeleted = false) {
const query = `SELECT settings, deleted, flagged, verified, hibernated FROM spaces WHERE id = ? AND deleted in (?) LIMIT 1`;
const query = `SELECT settings, deleted, flagged, verified, turbo, hibernated FROM spaces WHERE id = ? AND deleted in (?) LIMIT 1`;
const spaces = await db.queryAsync(query, [id, includeDeleted ? [0, 1] : [0]]);

if (!spaces[0]) return false;
Expand All @@ -46,7 +46,8 @@ export async function getSpace(id: string, includeDeleted = false) {
deleted: spaces[0].deleted === 1,
verified: spaces[0].verified === 1,
flagged: spaces[0].flagged === 1,
hibernated: spaces[0].hibernated === 1
hibernated: spaces[0].hibernated === 1,
turbo: spaces[0].turbo === 1
};
}

Expand Down
7 changes: 7 additions & 0 deletions src/helpers/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const SPACE_PROPOSAL_MONTH_LIMIT = 15;
export const VERIFIED_SPACE_PROPOSAL_DAY_LIMIT = 20;
export const VERIFIED_SPACE_PROPOSAL_MONTH_LIMIT = 100;

export const TURBO_SPACE_PROPOSAL_DAY_LIMIT = 40;
export const TURBO_SPACE_PROPOSAL_MONTH_LIMIT = 200;

export const ECOSYSTEM_SPACE_PROPOSAL_DAY_LIMIT = 150;
export const ECOSYSTEM_SPACE_PROPOSAL_MONTH_LIMIT = 750;

Expand All @@ -32,6 +35,10 @@ export function getSpaceLimits(space): number[] {
return [ECOSYSTEM_SPACE_PROPOSAL_DAY_LIMIT, ECOSYSTEM_SPACE_PROPOSAL_MONTH_LIMIT];
}

if (space.turbo) {
return [TURBO_SPACE_PROPOSAL_DAY_LIMIT, TURBO_SPACE_PROPOSAL_MONTH_LIMIT];
}

if (space.verified) {
return [VERIFIED_SPACE_PROPOSAL_DAY_LIMIT, VERIFIED_SPACE_PROPOSAL_MONTH_LIMIT];
}
Expand Down
1 change: 1 addition & 0 deletions src/writer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function validateSpaceSettings(originalSpace: any) {
delete space.deleted;
delete space.flagged;
delete space.verified;
delete space.turbo;
delete space.hibernated;
delete space.id;

Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const spacesSqlFixtures: Record<string, any>[] = [
flagged: 0,
deleted: 0,
hibernated: 0,
turbo: 0,
created: 1649844547,
updated: 1649844547,
settings: {
Expand All @@ -24,6 +25,7 @@ export const spacesSqlFixtures: Record<string, any>[] = [
flagged: 0,
deleted: 0,
hibernated: 0,
turbo: 0,
created: 1649844547,
updated: 1649844547,
settings: {
Expand Down Expand Up @@ -95,5 +97,6 @@ export const spacesGetSpaceFixtures: Record<string, any> = {
},
flagged: 0,
verified: 0,
hibernated: 0
hibernated: 0,
turbo: 0
};
2 changes: 2 additions & 0 deletions test/integration/helpers/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('helpers/actions', () => {
flagged: false,
deleted: false,
hibernated: false,
turbo: false,
name: 'Test Space',
admins: ['0xFC01614d28595d9ea5963daD9f44C0E0F0fE10f0'],
symbol: 'TEST',
Expand All @@ -53,6 +54,7 @@ describe('helpers/actions', () => {
flagged: false,
deleted: true,
hibernated: false,
turbo: false,
name: 'Test Space',
admins: ['0xFC01614d28595d9ea5963daD9f44C0E0F0fE10f0'],
symbol: 'TEST',
Expand Down
2 changes: 2 additions & 0 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ CREATE TABLE spaces (
deleted INT NOT NULL DEFAULT '0',
flagged INT NOT NULL DEFAULT '0',
hibernated INT NOT NULL DEFAULT '0',
turbo INT NOT NULL DEFAULT '0',
created BIGINT NOT NULL,
updated BIGINT NOT NULL,
PRIMARY KEY (id),
INDEX name (name),
INDEX verified (verified),
INDEX flagged (flagged),
INDEX hibernated (hibernated),
INDEX turbo (turbo),
INDEX deleted (deleted),
INDEX created (created),
INDEX updated (updated)
Expand Down
6 changes: 5 additions & 1 deletion test/unit/writer/proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
SPACE_PROPOSAL_MONTH_LIMIT,
VERIFIED_SPACE_PROPOSAL_MONTH_LIMIT,
ECOSYSTEM_SPACES,
ACTIVE_PROPOSAL_BY_AUTHOR_LIMIT
ACTIVE_PROPOSAL_BY_AUTHOR_LIMIT,
TURBO_SPACE_PROPOSAL_DAY_LIMIT,
TURBO_SPACE_PROPOSAL_MONTH_LIMIT
} from '../../../src/helpers/limits';

const FLAGGED_ADDRESSES = ['0x0'];
Expand Down Expand Up @@ -328,6 +330,7 @@ describe('writer/proposal', () => {
['flagged', FLAGGED_SPACE_PROPOSAL_DAY_LIMIT, 'flagged', true],
['verified', VERIFIED_SPACE_PROPOSAL_DAY_LIMIT, 'verified', true],
['ecosystem', ECOSYSTEM_SPACE_PROPOSAL_DAY_LIMIT, 'id', ECOSYSTEM_SPACES[0]],
['turbo', TURBO_SPACE_PROPOSAL_DAY_LIMIT, 'turbo', true],
['normal', SPACE_PROPOSAL_DAY_LIMIT, null, null]
])(
'rejects if the %s space has exceeded the proposal daily post limit',
Expand All @@ -352,6 +355,7 @@ describe('writer/proposal', () => {
['flagged', FLAGGED_SPACE_PROPOSAL_MONTH_LIMIT, 'flagged', true],
['verified', VERIFIED_SPACE_PROPOSAL_MONTH_LIMIT, 'verified', true],
['ecosystem', ECOSYSTEM_SPACE_PROPOSAL_MONTH_LIMIT, 'id', ECOSYSTEM_SPACES[0]],
['turbo', TURBO_SPACE_PROPOSAL_MONTH_LIMIT, 'turbo', true],
['normal', SPACE_PROPOSAL_MONTH_LIMIT, null, null]
])(
'rejects if the %s space has exceeded the proposal monthly post limit',
Expand Down

0 comments on commit 384afd0

Please sign in to comment.