Skip to content

Commit

Permalink
Return all foreign Id arrays as integers, not strings
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Apr 15, 2020
1 parent 974bd77 commit 1190bc8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"chai-arrays": "^2.0.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"eth-sig-util": "^2.5.3",
Expand Down
5 changes: 5 additions & 0 deletions backend/src/controllers/PollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ async function generateFancyId(title) {

function convertPollToJSON(poll) {
let jsonPoll = poll.toJSON();

jsonPoll.end_date = Math.floor(jsonPoll.end_date.valueOf() / 1000);
jsonPoll.start_date = Math.floor(jsonPoll.start_date.valueOf() / 1000);

jsonPoll.valid_event_ids = jsonPoll.valid_event_ids.map(event_id => {
return parseInt(event_id);
});

delete jsonPoll.createdAt;
delete jsonPoll.updatedAt;

Expand Down
4 changes: 4 additions & 0 deletions backend/src/controllers/VoteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function convertVoteToJSON(vote) {
delete jsonVote.createdAt;
delete jsonVote.updatedAt;

jsonVote.token_ids = jsonVote.token_ids.map(token_id => {
return parseInt(token_id);
});

jsonVote.date_cast = Math.floor(jsonVote.date_cast.valueOf() / 1000);

return jsonVote;
Expand Down
17 changes: 11 additions & 6 deletions backend/test/endpoint-smoke-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import chai from 'chai';
import chatHttp from 'chai-http';
import assertArrays from 'chai-arrays';
import 'chai/register-should';
import app from '../src/index';

chai.use(chatHttp);
chai.use(assertArrays);

const { expect } = chai;

Expand Down Expand Up @@ -67,15 +69,15 @@ describe('Smoke Testing Endpoints', () => {
expect(result.status).to.equal(201);
expect(result.body).to.include({
id: 1,
title: 'The first cool poll',
end_date: 1745137203,
fancy_id: 'the-first-cool-poll',
title: 'The first cool poll',
polltaker_account: '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b',
description: 'This could be a very, very long amount of text if we wanted it to be I guess',
end_date: 1745137203,
attestation: 'dca1a1c59b1626c356e2a343775b573a92b3e26f2960086dd33685c4983eacb938367f83ef2fb794b58d69e940ae3c45298cab62932f0258b56c9d00605a9e461c',
});
expect(result.body.poll_options.length).to.equal(2);
expect(result.body.valid_event_ids.length).to.equal(6);
expect(result.body.valid_event_ids).to.be.equalTo([128, 124, 127, 123, 126, 125]);

done();
});
Expand Down Expand Up @@ -130,9 +132,11 @@ describe('Smoke Testing Endpoints', () => {
expect(result.status).to.equal(201);
expect(result.body).to.include({
id: 1,
voter_account: "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF",
poll_option_id: 1,
});
expect(typeof result.body.date_cast).to.equal('number');
expect(result.body.token_ids).to.be.equalTo([10, 2, 27,]);

done();
});
Expand Down Expand Up @@ -209,13 +213,14 @@ describe('Smoke Testing Endpoints', () => {
expect(result.status).to.equal(201);
expect(result.body).to.include({
id: 3,
title: 'The first cool poll',
end_date: 1745137203,
fancy_id: 'the-first-cool-poll-1',
polltaker_account: '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b',
title: 'The first cool poll',
description: 'This is actually the second first cool poll',
polltaker_account: '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b',
end_date: 1745137203,
attestation: '3d43cf29564ca3047550e956009bb819305805ab4a40842d0136b8b23fa955192796f62995f606e6f189b55b651acb99cc352bb168ec331f47d6e6114d2d2bc91b',
});
expect(result.body.valid_event_ids).to.be.equalTo([128, 124, 127, 123, 126, 125]);
expect(result.body.poll_options.length).to.equal(3);

done();
Expand Down

0 comments on commit 1190bc8

Please sign in to comment.