Skip to content

Commit

Permalink
Resolving Endpoint Regression and Codebase Refinement (#21)
Browse files Browse the repository at this point in the history
* Fix swagger overriding other routes

* Add basic tests for choices routes

* Remove node_modules from source

* Simplify testing CI pipeline

* Flesh out swagger & refactor choices tests

* Add daos tests

* Add poll tests

* Add swagger test

* Slight refactor of imports for consistency

* Add tokens tests

* logic for xtz weighted polls

* fixes requested

* last PR fix

---------

Co-authored-by: fabiolalombardim <lombardifabiola@hotmail.com>
Co-authored-by: fabiolalombardim <37227394+fabiolalombardim@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 9, 2024
1 parent e466bc4 commit 2c219f7
Show file tree
Hide file tree
Showing 1,104 changed files with 2,647 additions and 234,516 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: API tests

on:
push:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 21
- run: yarn install
- run: yarn test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node
8 changes: 2 additions & 6 deletions components/choices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const updateChoiceById = async (req, response) => {
dao.daoContract,
token.tokenID,
block,
address
address,
poll.isXTZ
);

if (!total) {
Expand Down Expand Up @@ -151,9 +152,6 @@ const updateChoiceById = async (req, response) => {
try {
await session.withTransaction(async () => {
const coll1 = db_connect.collection("Choices");
const coll2 = db_connect.collection("Polls");

// await coll2.updateOne({_id: poll._id}, { $set: { "votes" : values.length }})
// Important:: You must pass the session to the operations
await coll1.updateOne(
{ _id: ObjectId(oldVote._id) },
Expand Down Expand Up @@ -199,8 +197,6 @@ const updateChoiceById = async (req, response) => {
await session
.withTransaction(async () => {
const coll1 = db_connect.collection("Choices");
const coll2 = db_connect.collection("Polls");

await coll1.updateOne(
{
_id: choice._id,
Expand Down
2 changes: 2 additions & 0 deletions components/polls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const addPoll = async (req, response) => {
externalLink,
endTime,
votingStrategy,
isXTZ
} = values;

const author = getPkhfromPk(publicKey);
Expand Down Expand Up @@ -158,6 +159,7 @@ const addPoll = async (req, response) => {
choices: choicesPoll,
author,
votingStrategy,
isXTZ
};

let data = {
Expand Down
15 changes: 13 additions & 2 deletions components/tokens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ const getVotingPowerAtLevel = async (req, response) => {
daoContract,
tokenID,
level,
userAddress
userAddress,
isXTZ = false
);

response.json({ votingWeight });
const votingXTZWeight = await getUserTotalVotingPowerAtReferenceBlock(
network,
address,
daoContract,
tokenID,
level,
userAddress,
isXTZ = true
);

response.json({ votingWeight, votingXTZWeight });
} catch (error) {
console.log("error: ", error);
response.status(400).send({
Expand Down
4 changes: 2 additions & 2 deletions db/conn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { MongoClient } = require("mongodb");

const dbURI = process.env.ATLAS_URI;
const dbURI = process.env.NODE_ENV === 'test' ? process.env.TEST_MONGO_URI : process.env.ATLAS_URI;

const client = new MongoClient(dbURI, {
useNewUrlParser: true,
Expand Down Expand Up @@ -30,4 +30,4 @@ module.exports = {
connectToServer,
getDb,
getClient,
};
};
9 changes: 9 additions & 0 deletions globalTestSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { MongoMemoryServer } = require('mongodb-memory-server');

module.exports = async () => {
const mongoServer = await MongoMemoryServer.create();
process.env.TEST_MONGO_URI = mongoServer.getUri();

// Store the MongoMemoryServer instance in a global variable
global.__MONGOSERVER__ = mongoServer;
};
5 changes: 5 additions & 0 deletions globalTestTeardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = async () => {
if (global.__MONGOSERVER__) {
await global.__MONGOSERVER__.stop();
}
};
16 changes: 0 additions & 16 deletions node_modules/@types/node/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions node_modules/@types/node/assert/strict.d.ts

This file was deleted.

Loading

0 comments on commit 2c219f7

Please sign in to comment.