Skip to content

Commit cde415b

Browse files
Merge pull request #318 from daostack/CM-266-common-creation-min-contribution
CM-266 - common creation min contribution
2 parents a9adb5d + 24eec90 commit cde415b

File tree

8 files changed

+96
-20
lines changed

8 files changed

+96
-20
lines changed

packages/firebase/__tests__/funtions/__snapshots__/common.test.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Array [
55
"You must provide a valid URL",
66
"image is a required field",
77
"byline is a required field",
8-
"fundingGoalDeadline is a required field",
98
"contributionAmount is a required field",
109
]
1110
`;

packages/firebase/__tests__/funtions/common.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const validCommonCreationPayload = {
2121
description: 'hey there, am i descriptive',
2222
contributionType: 'one-time',
2323
contributionAmount: 6500,
24-
fundingGoalDeadline: new Date().getTime()
24+
zeroContribution: true,
2525
};
2626

2727
describe('Common Related Cloud Functions', () => {

packages/firebase/__tests__/funtions/proposal.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ const validFundingData = (commonId: string) => ({
3838
title: 'I need money'
3939
});
4040

41+
const validJoinDataZeroContribution = (commonId: string) => ({
42+
commonId,
43+
description: 'I wanna be a part, but without paying',
44+
funding: 0,
45+
cardId: `test-card-id-for-common-${commonId}`
46+
});
47+
48+
const invalidJoinDataZeroContribution = (commonId: string) => ({
49+
commonId,
50+
description: 'I wanna be a part, but pay less that $5',
51+
funding: 300,
52+
cardId: `test-card-id-for-common-${commonId}`
53+
});
54+
4155
describe('Proposal Related Cloud Functions', () => {
4256
afterAll(async () => {
4357
await test.cleanup();
@@ -168,6 +182,70 @@ describe('Proposal Related Cloud Functions', () => {
168182
expect(response.body.type).toBe('join');
169183
expect(response.body.commonId).toBe(common.id);
170184
});
185+
186+
it('should make a join request when funding = 0 and 0 contribution is allowed', async () => {
187+
// Setup
188+
const joinerId = v4();
189+
const founderId = v4();
190+
191+
const authToken = await getTestAuthToken(joinerId);
192+
const common = await createTestCommon(founderId);
193+
194+
const response = await proposalsApp
195+
.post(joinEndpoint)
196+
.send(validJoinDataZeroContribution(common.id))
197+
.set({
198+
Authorization: authToken
199+
});
200+
201+
expect(response.body.message).toBe('Join request successfully created!');
202+
expect(response.body.proposerId).toBe(joinerId);
203+
expect(response.body.type).toBe('join');
204+
expect(response.body.commonId).toBe(common.id);
205+
206+
});
207+
208+
it('should not make a join request when 0 < funding < 5 and 0 contribution is allowed', async () => {
209+
// Setup
210+
const joinerId = v4();
211+
const founderId = v4();
212+
213+
const authToken = await getTestAuthToken(joinerId);
214+
const common = await createTestCommon(founderId);
215+
216+
const response = await proposalsApp
217+
.post(joinEndpoint)
218+
.send(invalidJoinDataZeroContribution(common.id))
219+
.set({
220+
Authorization: authToken
221+
});
222+
223+
expect(response.body.error.includes(`The funding cannot be less than the minimum required funding`)).toBeTruthy();
224+
expect(response.body.errorCode).toBe('GenericError');
225+
expect(response.body.errorMessage).toBe('Your join request cannot be created, because the min fee to join is $65.00, but you provided $3.00');
226+
expect(response.status).toBe(400);
227+
});
228+
229+
it('should not make a join request when funding = 0 and 0 contribution is not allowed', async () => {
230+
// Setup
231+
const joinerId = v4();
232+
const founderId = v4();
233+
234+
const authToken = await getTestAuthToken(joinerId);
235+
const common = await createTestCommon(founderId, false); //@askAlexI if he's ok with that (having a second argument for zeroContribution) :)
236+
237+
const response = await proposalsApp
238+
.post(joinEndpoint)
239+
.send(validJoinDataZeroContribution(common.id))
240+
.set({
241+
Authorization: authToken
242+
});
243+
244+
expect(response.body.error.includes(`The funding cannot be less than the minimum required funding`)).toBeTruthy();
245+
expect(response.body.errorCode).toBe('GenericError');
246+
expect(response.body.errorMessage).toBe('Your join request cannot be created, because the min fee to join is $65.00, but you provided $0.00');
247+
expect(response.status).toBe(400);
248+
});
171249
});
172250

173251
describe('Funding Proposal Creation', () => {

packages/firebase/__tests__/helpers/createTestCommon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { ICommonEntity } from '@common/types';
33
import { commonApp } from './supertests';
44
import { getTestAuthToken } from './auth';
55

6-
export const createTestCommon = async (userId = 'test-user'): Promise<ICommonEntity> => {
6+
export const createTestCommon = async (userId = 'test-user', zeroContribution = true): Promise<ICommonEntity> => {
77
const payload = {
88
name: 'Common Test',
99
image: 'https://llandscapes-10674.kxcdn.com/wp-content/uploads/2019/07/lighting.jpg',
1010
byline: 'basically this is a test common',
1111
description: 'hey there, am i descriptive',
1212
contributionType: 'one-time',
1313
contributionAmount: 6500,
14-
fundingGoalDeadline: new Date().getTime() / 1000
14+
zeroContribution,
1515
};
1616

1717
const authToken = await getTestAuthToken(userId);

packages/firebase/functions/src/common/business/createCommon.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const createCommonDataValidationScheme = yup.object({
2727

2828
description: yup.string().required(),
2929

30-
fundingGoalDeadline: yup.number().required(),
31-
3230
contributionAmount: yup.number().min(0).required(),
3331

3432
contributionType: yup
@@ -39,7 +37,9 @@ const createCommonDataValidationScheme = yup.object({
3937

4038
rules: yup.array(commonRuleValidationSchema).optional(),
4139

42-
links: yup.array(linkValidationSchema).optional()
40+
links: yup.array(linkValidationSchema).optional(),
41+
42+
zeroContribution: yup.boolean(),
4343
});
4444

4545
type CreateCommonPayload = yup.InferType<typeof createCommonDataValidationScheme>;
@@ -73,15 +73,14 @@ export const createCommon = async (
7373
description,
7474
contributionType,
7575
contributionAmount,
76-
fundingGoalDeadline
76+
zeroContribution,
7777
} = payload;
7878

7979
// @todo Check if user exists
8080

8181
const common = await commonDb.add({
8282
name,
8383
image,
84-
fundingGoalDeadline,
8584

8685
rules: (rules as ICommonRule[]) || [],
8786
links: (links as ICommonLink[]) || [],
@@ -97,7 +96,8 @@ export const createCommon = async (
9796
contributionType,
9897

9998
founderId: userId,
100-
minFeeToJoin: contributionAmount
99+
minFeeToJoin: contributionAmount,
100+
zeroContribution,
101101
},
102102

103103
register: 'na'

packages/firebase/functions/src/proposals/business/createJoinRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export const createJoinRequest = async (payload: CreateRequestToJoinPayload): Pr
7373
);
7474
}
7575

76-
// Check if the request is funded with less than required amount
77-
if (common.metadata.minFeeToJoin > payload.funding) {
76+
if (common.metadata.minFeeToJoin > payload.funding
77+
&& (!common.metadata.zeroContribution || payload.funding !== 0)) {
7878
throw new CommonError('The funding cannot be less than the minimum required funding', {
7979
userMessage: `Your join request cannot be created, because the min fee to join is $${(common.metadata.minFeeToJoin / 100)
8080
.toFixed(2)}, but you provided $${(payload.funding / 100).toFixed(2)}`,

packages/firebase/functions/src/util/tests/helpers/mockers/commons/getCommon.mocker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ jest.mock('../../../../../common/database/getCommon', () =>
1818
return {
1919
links: [],
2020
image: 'https://firebasestorage.googleapis.com/v0/b/common-staging-50741.appspot.com/o/public_img%2Fimg_1605603725987.jpg?alt=media&token=4fc5ab99-8f38-49f0-8d6e-83a94b30db60',
21-
fundingGoalDeadline: 1606206379,
2221
metadata: {
2322
minFeeToJoin: 700,
2423
description: 'testetest',
2524
founderId: 'Xlun3Ux94Zfc73axkiuVdkktOWf1',
2625
byline: 'testtestetstetst',
27-
contributionType: contributionType
26+
contributionType: contributionType,
27+
zeroContribution: true,
2828
},
2929
raised: 0,
3030
rules: [

packages/types/src/entities/ICommonEntity.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ export interface ICommonEntity extends IBaseEntity {
2727
*/
2828
raised: number;
2929

30-
/**
31-
* The timestamp after witch you are able to
32-
* create funding proposals
33-
*/
34-
fundingGoalDeadline: number;
35-
3630
/**
3731
* List of all users, that are members of this common
3832
*/
@@ -111,6 +105,11 @@ export interface ICommonMetadata {
111105
* or only when they join
112106
*/
113107
contributionType: ContributionType;
108+
109+
/**
110+
* Allow users to join common with zero contribution
111+
*/
112+
zeroContribution: boolean;
114113
}
115114

116115
export interface ICommonUpdate {

0 commit comments

Comments
 (0)