|
1 | 1 | import omit from 'lodash/omit';
|
2 |
| -import * as writer from '../../../src/writer/proposal'; |
3 |
| -import input from '../../fixtures/writer-payload/proposal.json'; |
4 |
| -import { spacesGetSpaceFixtures } from '../../fixtures/space'; |
5 | 2 | import {
|
| 3 | + ACTIVE_PROPOSAL_BY_AUTHOR_LIMIT, |
6 | 4 | ECOSYSTEM_SPACE_PROPOSAL_DAY_LIMIT,
|
7 |
| - FLAGGED_SPACE_PROPOSAL_DAY_LIMIT, |
8 |
| - SPACE_PROPOSAL_DAY_LIMIT, |
9 |
| - VERIFIED_SPACE_PROPOSAL_DAY_LIMIT, |
10 | 5 | ECOSYSTEM_SPACE_PROPOSAL_MONTH_LIMIT,
|
| 6 | + FLAGGED_SPACE_PROPOSAL_DAY_LIMIT, |
11 | 7 | FLAGGED_SPACE_PROPOSAL_MONTH_LIMIT,
|
12 |
| - SPACE_PROPOSAL_MONTH_LIMIT, |
13 |
| - VERIFIED_SPACE_PROPOSAL_MONTH_LIMIT, |
14 | 8 | MAINNET_ECOSYSTEM_SPACES,
|
15 |
| - ACTIVE_PROPOSAL_BY_AUTHOR_LIMIT, |
| 9 | + SPACE_PROPOSAL_DAY_LIMIT, |
| 10 | + SPACE_PROPOSAL_MONTH_LIMIT, |
16 | 11 | TURBO_SPACE_PROPOSAL_DAY_LIMIT,
|
17 |
| - TURBO_SPACE_PROPOSAL_MONTH_LIMIT |
| 12 | + TURBO_SPACE_PROPOSAL_MONTH_LIMIT, |
| 13 | + VERIFIED_SPACE_PROPOSAL_DAY_LIMIT, |
| 14 | + VERIFIED_SPACE_PROPOSAL_MONTH_LIMIT |
18 | 15 | } from '../../../src/helpers/limits';
|
| 16 | +import * as writer from '../../../src/writer/proposal'; |
| 17 | +import { spacesGetSpaceFixtures } from '../../fixtures/space'; |
| 18 | +import input from '../../fixtures/writer-payload/proposal.json'; |
19 | 19 |
|
20 | 20 | const FLAGGED_ADDRESSES = ['0x0'];
|
21 | 21 |
|
@@ -69,6 +69,12 @@ mockGetProposalsCount.mockResolvedValue([
|
69 | 69 | }
|
70 | 70 | ]);
|
71 | 71 |
|
| 72 | +function updateInputPayload(input: any, payload: any) { |
| 73 | + const msg = JSON.parse(input.msg); |
| 74 | + |
| 75 | + return { ...input, msg: JSON.stringify({ ...msg, payload: { ...msg.payload, ...payload } }) }; |
| 76 | +} |
| 77 | + |
72 | 78 | describe('writer/proposal', () => {
|
73 | 79 | afterEach(jest.clearAllMocks);
|
74 | 80 |
|
@@ -294,6 +300,116 @@ describe('writer/proposal', () => {
|
294 | 300 | expect(mockSnapshotUtilsValidate).toHaveBeenCalledTimes(0);
|
295 | 301 | });
|
296 | 302 | });
|
| 303 | + |
| 304 | + describe('when the space is using ANY privacy', () => { |
| 305 | + beforeEach(() => { |
| 306 | + mockGetSpace.mockResolvedValueOnce({ |
| 307 | + ...spacesGetSpaceFixtures, |
| 308 | + voting: { privacy: 'any' } |
| 309 | + }); |
| 310 | + }); |
| 311 | + |
| 312 | + it('accepts a proposal with shutter privacy', () => { |
| 313 | + return expect( |
| 314 | + writer.verify(updateInputPayload(input, { privacy: 'shutter' })) |
| 315 | + ).resolves.toBeUndefined(); |
| 316 | + }); |
| 317 | + |
| 318 | + it('accepts a proposal with undefined privacy', () => { |
| 319 | + return expect( |
| 320 | + writer.verify(updateInputPayload(input, { privacy: undefined })) |
| 321 | + ).resolves.toBeUndefined(); |
| 322 | + }); |
| 323 | + |
| 324 | + it('accepts a proposal with no privacy', () => { |
| 325 | + return expect( |
| 326 | + writer.verify(updateInputPayload(input, { privacy: '' })) |
| 327 | + ).resolves.toBeUndefined(); |
| 328 | + }); |
| 329 | + }); |
| 330 | + |
| 331 | + // Fallback as if { privacy: 'any' } |
| 332 | + describe('when the space is missing the privacy settings', () => { |
| 333 | + beforeEach(() => { |
| 334 | + mockGetSpace.mockResolvedValueOnce({ |
| 335 | + ...spacesGetSpaceFixtures, |
| 336 | + voting: undefined |
| 337 | + }); |
| 338 | + }); |
| 339 | + |
| 340 | + it('accepts a proposal with shutter privacy', () => { |
| 341 | + return expect( |
| 342 | + writer.verify(updateInputPayload(input, { privacy: 'shutter' })) |
| 343 | + ).resolves.toBeUndefined(); |
| 344 | + }); |
| 345 | + |
| 346 | + it('accepts a proposal with undefined privacy', () => { |
| 347 | + return expect( |
| 348 | + writer.verify(updateInputPayload(input, { privacy: undefined })) |
| 349 | + ).resolves.toBeUndefined(); |
| 350 | + }); |
| 351 | + |
| 352 | + it('accepts a proposal with no privacy', () => { |
| 353 | + return expect( |
| 354 | + writer.verify(updateInputPayload(input, { privacy: '' })) |
| 355 | + ).resolves.toBeUndefined(); |
| 356 | + }); |
| 357 | + }); |
| 358 | + |
| 359 | + describe('when the space is using NO privacy', () => { |
| 360 | + beforeEach(() => { |
| 361 | + mockGetSpace.mockResolvedValueOnce({ |
| 362 | + ...spacesGetSpaceFixtures, |
| 363 | + voting: { privacy: '' } |
| 364 | + }); |
| 365 | + }); |
| 366 | + |
| 367 | + it('rejects a proposal with shutter privacy', () => { |
| 368 | + return expect( |
| 369 | + writer.verify(updateInputPayload(input, { privacy: 'shutter' })) |
| 370 | + ).rejects.toMatch('not allowed to set privacy'); |
| 371 | + }); |
| 372 | + |
| 373 | + it('accepts a proposal with undefined privacy', () => { |
| 374 | + return expect( |
| 375 | + writer.verify(updateInputPayload(input, { privacy: undefined })) |
| 376 | + ).resolves.toBeUndefined(); |
| 377 | + }); |
| 378 | + |
| 379 | + it('accepts a proposal with no privacy', () => { |
| 380 | + return expect( |
| 381 | + writer.verify(updateInputPayload(input, { privacy: '' })) |
| 382 | + ).resolves.toBeUndefined(); |
| 383 | + }); |
| 384 | + }); |
| 385 | + |
| 386 | + describe('when the space is using SHUTTER privacy', () => { |
| 387 | + beforeEach(() => { |
| 388 | + mockGetSpace.mockResolvedValueOnce({ |
| 389 | + ...spacesGetSpaceFixtures, |
| 390 | + voting: { privacy: 'shutter' } |
| 391 | + }); |
| 392 | + }); |
| 393 | + |
| 394 | + it('accepts a proposal with shutter privacy', () => { |
| 395 | + return expect( |
| 396 | + writer.verify(updateInputPayload(input, { privacy: 'shutter' })) |
| 397 | + ).resolves.toBeUndefined(); |
| 398 | + }); |
| 399 | + |
| 400 | + it('accepts a proposal with undefined privacy', () => { |
| 401 | + return expect( |
| 402 | + writer.verify(updateInputPayload(input, { privacy: undefined })) |
| 403 | + ).resolves.toBeUndefined(); |
| 404 | + }); |
| 405 | + |
| 406 | + it('rejects a proposal with privacy empty string', async () => { |
| 407 | + expect.assertions(1); |
| 408 | + await expect(writer.verify(updateInputPayload(input, { privacy: '' }))).rejects.toMatch( |
| 409 | + 'not allowed to set privacy' |
| 410 | + ); |
| 411 | + }); |
| 412 | + }); |
297 | 413 | });
|
298 | 414 |
|
299 | 415 | it('rejects if the snapshot is in the future', async () => {
|
|
0 commit comments