Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create verified campaign for givethio projects without image and description #617

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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