Skip to content

Commit

Permalink
feat(ad content): do not credit users with TabCoins for creating ads
Browse files Browse the repository at this point in the history
Prevent the crediting of TabCoins to the user if the "type" of the new content is not "content".
  • Loading branch information
aprendendofelipe committed Jul 11, 2024
1 parent 5f8db02 commit ee3bd8c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions models/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ async function creditOrDebitTabCoins(oldContent, newContent, options = {}) {
});
}

// We should not credit TabCoins to the user if the "type" is not "content".
if (newContent.type !== 'content') {
userEarnings = 0;
}

// We should not credit if the content has little or no value.
if (newContent.body.split(/[a-z]{5,}/i, 6).length < 6) return;

Expand Down
28 changes: 28 additions & 0 deletions tests/integration/api/v1/contents/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3061,6 +3061,34 @@ describe('POST /api/v1/contents', () => {
expect(Date.parse(responseBody.created_at)).not.toBeNaN();
expect(Date.parse(responseBody.updated_at)).not.toBeNaN();
});

test('Should not credit TabCoins to the user', async () => {
const contentsRequestBuilder = new RequestBuilder('/api/v1/contents');
const usersRequestBuilder = new RequestBuilder('/api/v1/users');
const defaultUser = await contentsRequestBuilder.buildUser();
await orchestrator.createPrestige(defaultUser.id, { rootPrestigeNumerator: 2, rootPrestigeDenominator: 10 });

orchestrator.createBalance({
balanceType: 'user:tabcash',
recipientId: defaultUser.id,
amount: defaultTabCashForAdCreation,
});

const { response: contentResponse, responseBody: contentResponseBody } = await contentsRequestBuilder.post({
title: 'Title',
body: 'Relevant text needs to contain a good amount of words',
status: 'published',
type: 'ad',
});

const { responseBody: userResponseBody } = await usersRequestBuilder.get(`/${defaultUser.username}`);

expect.soft(contentResponse.status).toBe(201);
expect(contentResponseBody.tabcoins).toBe(1);
expect(contentResponseBody.type).toBe('ad');
expect(userResponseBody.tabcoins).toBe(0);
expect(userResponseBody.tabcash).toBe(0);
});
});

describe('With invalid "type"', () => {
Expand Down

0 comments on commit ee3bd8c

Please sign in to comment.