Skip to content

Commit 9f4e2f6

Browse files
committed
fix: fix tests
1 parent f2a2ca1 commit 9f4e2f6

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

src/writer/proposal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function getSpaceProposalsLimits(
1717
space: { verified: boolean; turbo: boolean; flagged: boolean; id: string },
1818
interval: 'day' | 'month'
1919
): Promise<number> {
20-
return getLimit(`space.${getSpaceType(space, true)}.proposal_limit_per_${interval}`);
20+
return getLimit(`space.${await getSpaceType(space, true)}.proposal_limit_per_${interval}`);
2121
}
2222

2323
export const getProposalsCount = async (space, author) => {
@@ -209,12 +209,12 @@ export async function verify(body): Promise<any> {
209209
return Promise.reject('failed to check proposals limit');
210210
}
211211

212-
const bodyLengthLimit = await getLimit(`space.${getSpaceType(space)}.body_limit`);
212+
const bodyLengthLimit = await getLimit(`space.${await getSpaceType(space)}.body_limit`);
213213
if (msg.payload.body.length > bodyLengthLimit) {
214214
return Promise.reject(`proposal body length can not exceed ${bodyLengthLimit} characters`);
215215
}
216216

217-
const choicesLimit = await getLimit(`space.${getSpaceType(space)}.choices_limit`);
217+
const choicesLimit = await getLimit(`space.${await getSpaceType(space)}.choices_limit`);
218218
if (msg.payload.choices.length > choicesLimit) {
219219
return Promise.reject(`number of choices can not exceed ${choicesLimit}`);
220220
}

src/writer/settings.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import isEqual from 'lodash/isEqual';
44
import { addOrUpdateSpace, getSpace } from '../helpers/actions';
55
import log from '../helpers/log';
66
import db from '../helpers/mysql';
7-
import { getLimit } from '../helpers/options';
7+
import { getLimit, getSpaceType } from '../helpers/options';
88
import { clearStampCache, DEFAULT_NETWORK, jsonParse } from '../helpers/utils';
99

1010
const SNAPSHOT_ENV = process.env.NETWORK || 'testnet';
@@ -74,9 +74,7 @@ export async function verify(body): Promise<any> {
7474
return Promise.reject(e);
7575
}
7676

77-
const strategiesLimit = await getLimit(
78-
`space.${space.turbo ? 'turbo' : 'default'}.strategies_limit`
79-
);
77+
const strategiesLimit = await getLimit(`space.${await getSpaceType(space)}.strategies_limit`);
8078

8179
if (msg.payload.strategies.length > strategiesLimit) {
8280
return Promise.reject(`max number of strategies is ${strategiesLimit}`);

test/unit/writer/proposal.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,29 @@ const LIMITS = {
99
'space.active_proposal_limit_per_author': 20,
1010
'space.ecosystem.proposal_limit_per_day': 150,
1111
'space.ecosystem.proposal_limit_per_month': 750,
12+
'space.ecosystem.choices_limit': 20,
13+
'space.ecosystem.body_length': 10000,
14+
'space.ecosystem.strategies_limit': 8,
1215
'space.flagged.proposal_limit_per_day': 5,
1316
'space.flagged.proposal_limit_per_month': 7,
17+
'space.flagged.choices_limit': 20,
18+
'space.flagged.body_length': 10000,
19+
'space.flagged.strategies_limit': 8,
1420
'space.default.proposal_limit_per_day': 10,
1521
'space.default.proposal_limit_per_month': 150,
22+
'space.default.choices_limit': 20,
23+
'space.default.body_length': 10000,
24+
'space.default.strategies_limit': 8,
1625
'space.turbo.proposal_limit_per_day': 40,
1726
'space.turbo.proposal_limit_per_month': 200,
27+
'space.turbo.choices_limit': 1000,
28+
'space.turbo.body_length': 40000,
29+
'space.turbo.strategies_limit': 8,
1830
'space.verified.proposal_limit_per_day': 20,
1931
'space.verified.proposal_limit_per_month': 100,
32+
'space.verified.choices_limit': 20,
33+
'space.verified.body_length': 10000,
34+
'space.verified.strategies_limit': 6,
2035
'user.default.follow.limit': 25
2136
};
2237
const ECOSYSTEM_LIST = ['test.eth', 'snapshot.eth'];

test/unit/writer/settings.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,52 @@ function randomStrategies(count = 1) {
1818
}));
1919
}
2020

21+
const LIMITS = {
22+
'space.active_proposal_limit_per_author': 20,
23+
'space.ecosystem.proposal_limit_per_day': 150,
24+
'space.ecosystem.proposal_limit_per_month': 750,
25+
'space.ecosystem.choices_limit': 20,
26+
'space.ecosystem.body_length': 10000,
27+
'space.ecosystem.strategies_limit': 8,
28+
'space.flagged.proposal_limit_per_day': 5,
29+
'space.flagged.proposal_limit_per_month': 7,
30+
'space.flagged.choices_limit': 20,
31+
'space.flagged.body_length': 10000,
32+
'space.flagged.strategies_limit': 8,
33+
'space.default.proposal_limit_per_day': 10,
34+
'space.default.proposal_limit_per_month': 150,
35+
'space.default.choices_limit': 20,
36+
'space.default.body_length': 10000,
37+
'space.default.strategies_limit': 8,
38+
'space.turbo.proposal_limit_per_day': 40,
39+
'space.turbo.proposal_limit_per_month': 200,
40+
'space.turbo.choices_limit': 1000,
41+
'space.turbo.body_length': 40000,
42+
'space.turbo.strategies_limit': 10,
43+
'space.verified.proposal_limit_per_day': 20,
44+
'space.verified.proposal_limit_per_month': 100,
45+
'space.verified.choices_limit': 20,
46+
'space.verified.body_length': 10000,
47+
'space.verified.strategies_limit': 6,
48+
'user.default.follow.limit': 25
49+
};
50+
const ECOSYSTEM_LIST = ['test.eth', 'snapshot.eth'];
51+
52+
jest.mock('../../../src/helpers/options', () => {
53+
const originalModule = jest.requireActual('../../../src/helpers/options');
54+
55+
return {
56+
__esModule: true,
57+
...originalModule,
58+
getList: () => {
59+
return ECOSYSTEM_LIST;
60+
},
61+
getLimit: (key: string) => {
62+
return LIMITS[key];
63+
}
64+
};
65+
});
66+
2167
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2268
const mockGetSpace = jest.fn((_): any => {
2369
return spacesGetSpaceFixtures;

0 commit comments

Comments
 (0)