From 94aa639b57449cad427c02911a16122c73b8c4de Mon Sep 17 00:00:00 2001 From: Mohammad Ranjbar Z Date: Sun, 26 Sep 2021 21:35:37 +0330 Subject: [PATCH] Fix create verified campaign for givethio projects without image and description related to Giveth/giveth-dapp#2546 --- .../campaigns/campaigns.service.test.js | 13 +++++++++++++ .../verifiedCampaigns.service.js | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/services/campaigns/campaigns.service.test.js b/src/services/campaigns/campaigns.service.test.js index a4445a10..1a12f461 100644 --- a/src/services/campaigns/campaigns.service.test.js +++ b/src/services/campaigns/campaigns.service.test.js @@ -38,6 +38,19 @@ function postCampaignTestCases() { assert.equal(response.body.ownerAddress, SAMPLE_DATA.CREATE_CAMPAIGN_DATA.ownerAddress); }); + it('should create campaign with less than 10 character', async () => { + const descriptionWithLEssThan10Character = '123456'; + const response = await request(baseUrl) + .post(relativeUrl) + .send({ + ...SAMPLE_DATA.CREATE_CAMPAIGN_DATA, + description: descriptionWithLEssThan10Character, + }) + .set({ Authorization: getJwt(SAMPLE_DATA.CREATE_CAMPAIGN_DATA.ownerAddress) }); + assert.equal(response.statusCode, 201); + assert.equal(response.body.description, descriptionWithLEssThan10Character); + }); + it('should create campaign successfully, should not set coownerAddress by default', async () => { const response = await request(baseUrl) .post(relativeUrl) diff --git a/src/services/verifiedCampaigns/verifiedCampaigns.service.js b/src/services/verifiedCampaigns/verifiedCampaigns.service.js index ac544d74..51610ce1 100644 --- a/src/services/verifiedCampaigns/verifiedCampaigns.service.js +++ b/src/services/verifiedCampaigns/verifiedCampaigns.service.js @@ -12,7 +12,13 @@ module.exports = function verifiedCampaigns() { async create(data, params) { const { txHash, url, slug } = data; const projectInfo = await givethIoAdapter.getProjectInfoBySLug(slug); - const { id: givethIoProjectId, title, description, image } = projectInfo; + const { + id: givethIoProjectId, + title, + description: givethIoDescription, + image: givethIoImage, + } = projectInfo; + const defaultImage = '/ipfs/QmeVDkwp9nrDsbAxLXY9yNW853C2F4CECC7wdvEJrroTqA'; const owner = await givethIoAdapter.getUserByUserId(projectInfo.admin); if (params.user.address.toLowerCase() !== owner.address.toLowerCase()) { throw new errors.Forbidden('The owner of project in givethIo is not you'); @@ -21,16 +27,21 @@ module.exports = function verifiedCampaigns() { if (campaign) { throw new errors.BadRequest('Campaign with this givethIo projectId exists'); } - const imageIpfsPath = image.match(/\/ipfs\/.*/); + const imageIpfsPath = givethIoImage.match(/\/ipfs\/.*/); campaign = await app.service('campaigns').create({ title, url, slug, reviewerAddress: config.givethIoProjectsReviewerAddress, - description, + + // because description in givethio is optional but in giveth trace is required + description: givethIoDescription || title, verified: true, txHash, - image: imageIpfsPath ? imageIpfsPath[0] : image, + + // if givethIo image is undefined or is a number + // (givethIo project with default image have numbers as image) I set the our default image for them + image: imageIpfsPath ? imageIpfsPath[0] : defaultImage, ownerAddress: owner.address, givethIoProjectId, });