Skip to content

Commit 4b15afc

Browse files
wa0x6eChaituVR
andauthored
fix: remove limits depending on space turbo status (#1115)
Co-authored-by: Chaitanya <[email protected]>
1 parent d36e85f commit 4b15afc

7 files changed

+4
-125
lines changed

src/schemas/proposal.json

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
"body": {
1616
"type": "string",
1717
"title": "body",
18-
"minLength": 0,
19-
"maxLengthWithSpaceType": {
20-
"default": 10000,
21-
"turbo": 40000
22-
}
18+
"minLength": 0
2319
},
2420
"discussion": {
2521
"type": "string",
@@ -30,11 +26,7 @@
3026
"choices": {
3127
"type": "array",
3228
"title": "choices",
33-
"minItems": 1,
34-
"maxLengthWithSpaceType": {
35-
"default": 500,
36-
"turbo": 1000
37-
}
29+
"minItems": 1
3830
},
3931
"labels": {
4032
"type": "array",

src/schemas/space.json

-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@
120120
"strategies": {
121121
"type": "array",
122122
"minItems": 1,
123-
"maxItemsWithSpaceType": {
124-
"default": 8,
125-
"turbo": 10
126-
},
127123
"uniqueItems": true,
128124
"items": {
129125
"type": "object",

src/schemas/update-proposal.json

+2-10
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
"body": {
2020
"type": "string",
2121
"title": "body",
22-
"minLength": 0,
23-
"maxLengthWithSpaceType": {
24-
"default": 10000,
25-
"turbo": 20000
26-
}
22+
"minLength": 0
2723
},
2824
"discussion": {
2925
"type": "string",
@@ -34,11 +30,7 @@
3430
"choices": {
3531
"type": "array",
3632
"title": "choices",
37-
"minItems": 1,
38-
"maxLengthWithSpaceType": {
39-
"default": 500,
40-
"turbo": 1000
41-
}
33+
"minItems": 1
4234
},
4335
"labels": {
4436
"type": "array",

src/utils.ts

-42
Original file line numberDiff line numberDiff line change
@@ -194,48 +194,6 @@ ajv.addKeyword({
194194
}
195195
});
196196

197-
ajv.addKeyword({
198-
keyword: 'maxLengthWithSpaceType',
199-
validate: function validate(schema, data) {
200-
// @ts-ignore
201-
const spaceType = this.spaceType || 'default';
202-
const isValid = data.length <= schema[spaceType];
203-
if (!isValid) {
204-
// @ts-ignore
205-
validate.errors = [
206-
{
207-
keyword: 'maxLengthWithSpaceType',
208-
message: `must not have more than ${schema[spaceType]}`,
209-
params: { limit: schema[spaceType] }
210-
}
211-
];
212-
}
213-
return isValid;
214-
},
215-
errors: true
216-
});
217-
218-
ajv.addKeyword({
219-
keyword: 'maxItemsWithSpaceType',
220-
validate: function validate(schema, data) {
221-
// @ts-ignore
222-
const spaceType = this.spaceType || 'default';
223-
const isValid = data.length <= schema[spaceType];
224-
if (!isValid) {
225-
// @ts-ignore
226-
validate.errors = [
227-
{
228-
keyword: 'maxItemsWithSpaceType',
229-
message: `must NOT have more than ${schema[spaceType]} items`,
230-
params: { limit: schema[spaceType] }
231-
}
232-
];
233-
}
234-
return isValid;
235-
},
236-
errors: true
237-
});
238-
239197
// Custom URL format to allow empty string values
240198
// https://github.com/snapshot-labs/snapshot.js/pull/541/files
241199
ajv.addFormat('customUrl', {

test/examples/proposal-maxLengthWithSpaceType-error.json

-20
This file was deleted.

test/examples/space-maxItemsWithSpaceType-error.json

-11
This file was deleted.

test/schema.spec.ts

-28
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import profile from './examples/profile.json';
1010
import statement from './examples/statement.json';
1111
import alias from './examples/alias.json';
1212
import schemas from '../src/schemas';
13-
import proposalMaxLengthWithSpaceTypeError from './examples/proposal-maxLengthWithSpaceType-error.json';
14-
import spaceMaxItemsWithSpaceTypeError from './examples/space-maxItemsWithSpaceType-error.json';
1513

1614
// Tests for default spaces
1715
describe.each([
@@ -49,29 +47,3 @@ describe.each([
4947
expect(isValid).toBe(true);
5048
});
5149
});
52-
53-
// tests for default schema with turbo example, should fail
54-
describe.each([
55-
{
56-
schemaType: 'space',
57-
schema: schemas.space,
58-
example: spaceTurbo,
59-
error: spaceMaxItemsWithSpaceTypeError
60-
},
61-
{
62-
schemaType: 'proposal',
63-
schema: schemas.proposal,
64-
example: proposalTurbo,
65-
error: proposalMaxLengthWithSpaceTypeError
66-
}
67-
])(
68-
`Run validate for default schema with turbo example`,
69-
({ schemaType, schema, example, error }) => {
70-
test(`validating schema ${schemaType} should fail with error`, () => {
71-
const isValid = validateSchema(schema, example, {
72-
snapshotEnv: 'mainnet'
73-
});
74-
expect(isValid).toMatchObject(error);
75-
});
76-
}
77-
);

0 commit comments

Comments
 (0)