Skip to content

Commit

Permalink
Fix create verified campaign for givethio projects without image and …
Browse files Browse the repository at this point in the history
…description

related to Giveth/giveth-dapp#2546
  • Loading branch information
mohammadranjbarz committed Sep 26, 2021
1 parent 512390a commit 94aa639
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/services/campaigns/campaigns.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 15 additions & 4 deletions src/services/verifiedCampaigns/verifiedCampaigns.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
});
Expand Down

0 comments on commit 94aa639

Please sign in to comment.