Skip to content

Commit

Permalink
Merge branch 'Greenstand:master' into subwallet-trust-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti authored Sep 14, 2024
2 parents c8fd5e8 + 92acdbb commit a502aba
Show file tree
Hide file tree
Showing 23 changed files with 520 additions and 216 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/treetracker-wallet-api-build-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
github.event_name == 'push' &&
github.repository == 'Greenstand/treetracker-wallet-api'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '20.x'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/treetracker-wallet-api-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
if: |
github.repository == 'Greenstand/treetracker-wallet-api'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.git-tag }}
- name: get-npm-version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/treetracker-wallet-api-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
if: |
github.repository == 'Greenstand/treetracker-wallet-api'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.git-tag }}
- name: get-npm-version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
if: |
github.repository == 'Greenstand/treetracker-wallet-api'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: v1.10
- name: get-npm-version
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/treetracker-wallet-api-pull-request-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
build:
name: Run all tests
runs-on: ubuntu-latest
container: node:10.18-jessie
container: node:20.16.0-alpine3.20

# Service containers to run with `container-job`
services:
Expand All @@ -35,11 +35,11 @@ jobs:
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v1
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '16.x'
node-version: '20.x'
- name: npm clean install
run: npm ci
working-directory: ${{ env.project-directory }}
Expand Down
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
# [1.39.0](https://github.com/Greenstand/treetracker-wallet-api/compare/v1.38.5...v1.39.0) (2024-09-10)


### Bug Fixes

* fix commit error ([ed7557b](https://github.com/Greenstand/treetracker-wallet-api/commit/ed7557b226adb5c350b49cdc011a49bc2e6e13b2))
* fix cors in delete in the production ([32294f9](https://github.com/Greenstand/treetracker-wallet-api/commit/32294f9e8d08e4306889e36e517003542cbe60b3))
* fix get trusts for managed wallets ([3eac2df](https://github.com/Greenstand/treetracker-wallet-api/commit/3eac2df7ece9d1391d14e8264e4af3ef84972590))
* fix merge conflicts ([0cd39dd](https://github.com/Greenstand/treetracker-wallet-api/commit/0cd39dda9a903ebc411777e7eb42b6249f24034d))
* fix tests ([01b99aa](https://github.com/Greenstand/treetracker-wallet-api/commit/01b99aa712be7bdbc7abf0485fc35a3f8cea5830))
* fix tests ([5ebf6eb](https://github.com/Greenstand/treetracker-wallet-api/commit/5ebf6ebea0830400b4ade855788142b88056ecb4))
* fix tests ([82bfd74](https://github.com/Greenstand/treetracker-wallet-api/commit/82bfd745c71ce436d483456639b384f451da0a0c))
* fix tests ([bc67ab4](https://github.com/Greenstand/treetracker-wallet-api/commit/bc67ab44715ccd7278920833a8772c141733dcd7))
* fix tests by removing redundant trust count logic ([d015018](https://github.com/Greenstand/treetracker-wallet-api/commit/d0150189fc9e837369af5c36822fa4254b0381df))
* fix typo ([102e231](https://github.com/Greenstand/treetracker-wallet-api/commit/102e23119eb46dc61f494497e553f584afca0a8b))
* fix typos ([9683518](https://github.com/Greenstand/treetracker-wallet-api/commit/9683518dfaae96a687dc6a7251913dddda48cba3))
* fix typos ([e394fa0](https://github.com/Greenstand/treetracker-wallet-api/commit/e394fa0a679ec4a4c6109512ace2656b5f076940))
* remove unwanted logic ([55e815b](https://github.com/Greenstand/treetracker-wallet-api/commit/55e815b49ac2993b5b5a38ab5e654d62e841851e))
* resolve conflicts ([81fc709](https://github.com/Greenstand/treetracker-wallet-api/commit/81fc7098c9700ff5bd2106c05bc6cfd6a18fcd65))


### Features

* implement pagination and sort in get /wallet/trusts ([f1eb0b4](https://github.com/Greenstand/treetracker-wallet-api/commit/f1eb0b468d276e2d68614cb2b8d4f514c290825b))

## [1.38.5](https://github.com/Greenstand/treetracker-wallet-api/compare/v1.38.4...v1.38.5) (2024-09-03)


### Bug Fixes

* github actions ([879ccc6](https://github.com/Greenstand/treetracker-wallet-api/commit/879ccc65bf52553ca639afafe9eb7adbabdb9f17))

## [1.38.4](https://github.com/Greenstand/treetracker-wallet-api/compare/v1.38.3...v1.38.4) (2024-06-05)


### Bug Fixes

* get trust relationships issue ([585b2be](https://github.com/Greenstand/treetracker-wallet-api/commit/585b2be0c298f0532768e96e7fdb1a5f3c29ecc0))
* tests ([dfd41c8](https://github.com/Greenstand/treetracker-wallet-api/commit/dfd41c885ed91016f0324e805501bc1220d05028))
* tests ([c3ac5fd](https://github.com/Greenstand/treetracker-wallet-api/commit/c3ac5fda54bd862c467e1d6efe897131de375671))
* unit test ([2901ee9](https://github.com/Greenstand/treetracker-wallet-api/commit/2901ee957664f937ffcbe418e510680a6eb4cf6b))

## [1.38.3](https://github.com/Greenstand/treetracker-wallet-api/compare/v1.38.2...v1.38.3) (2024-05-20)


### Bug Fixes

* add delete endpoint to cors ([1784882](https://github.com/Greenstand/treetracker-wallet-api/commit/178488236f850862ee1f249e5d4791e64344ce05))
* lock files ([17d87b0](https://github.com/Greenstand/treetracker-wallet-api/commit/17d87b0bd057f7043e5a86260cf062c6c736fb96))

## [1.38.2](https://github.com/Greenstand/treetracker-wallet-api/compare/v1.38.1...v1.38.2) (2024-05-20)


### Bug Fixes

* subwallets trust relationship validation ([f87c84a](https://github.com/Greenstand/treetracker-wallet-api/commit/f87c84ab4f13e6cd254aac458654dbcabd665f73))

## [1.38.1](https://github.com/Greenstand/treetracker-wallet-api/compare/v1.38.0...v1.38.1) (2024-05-07)


Expand Down
2 changes: 1 addition & 1 deletion deployment/overlays/development/mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
cors:
origins: '*'
methods: GET, POST, PATCH, OPTIONS
methods: GET, POST, PATCH, DELETE, OPTIONS
headers:
- content-type
- authorization
Expand Down
2 changes: 1 addition & 1 deletion deployment/overlays/production/mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
cors:
origins: 'https://prod-wallet-admin.treetracker.org'
methods: GET, POST, PATCH, OPTIONS
methods: GET, POST, PATCH, DELETE, OPTIONS
headers:
- content-type
- authorization
Expand Down
2 changes: 1 addition & 1 deletion deployment/overlays/test/mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
cors:
origins: '*'
methods: GET, POST, PATCH, OPTIONS
methods: GET, POST, PATCH, DELETE, OPTIONS
headers:
- content-type
- authorization
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "treetracker",
"version": "1.38.1",
"version": "1.39.0",
"description": "https://documenter.getpostman.com/view/10112806/SWTD8H5x?version=latest",
"private": true,
"main": "server/server.js",
Expand Down
2 changes: 1 addition & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ app.get('*', function (req, res) {
res.status(200).send(version);
});

module.exports = app;
module.exports = app;
81 changes: 36 additions & 45 deletions server/handlers/trustHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const TrustService = require('../services/TrustService');
const JWTService = require('../services/JWTService');
const TrustRelationshipEnums = require('../utils/trust-enums');


describe('trustRouter', () => {
let app;
const authenticatedWalletId = uuid.v4();
Expand Down Expand Up @@ -193,48 +192,41 @@ describe('trustRouter', () => {
expect(res.body.message).match(/request_type.*one.*of/);
});

it('successfully', async () => {
const limit = 10;
const offset = 0;
const count = 1;
const orderBy = 'created_at';
const order = 'desc';

const getAllTrustRelationshipsStub = sinon
.stub(TrustService.prototype, 'getAllTrustRelationships')
.resolves({
result: [{ id: trustId }],
count
it('successfully', async () => {
const limit = 10;
const offset = 0;
const orderBy = 'created_at';
const order = 'desc';

const getAllTrustRelationshipsStub = sinon
.stub(TrustService.prototype, 'getAllTrustRelationships')
.resolves([{ id: trustId }]);

const res = await request(app).get(
`/trust_relationships?type=${TrustRelationshipEnums.ENTITY_TRUST_TYPE.send}&request_type=${TrustRelationshipEnums.ENTITY_TRUST_REQUEST_TYPE.send}&state=${TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.trusted}&limit=${limit}&offset=${offset}&order=${order}&sort_by=${orderBy}`,
);

expect(res).property('statusCode').eq(200);
expect(res.body.trust_relationships).to.have.lengthOf(1);
expect(res.body.trust_relationships[0]).to.eql({ id: trustId });

expect(getAllTrustRelationshipsStub).to.have.been.calledWith({
state: TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.trusted,
type: TrustRelationshipEnums.ENTITY_TRUST_TYPE.send,
request_type: TrustRelationshipEnums.ENTITY_TRUST_REQUEST_TYPE.send,
limit,
offset,
order,
sort_by: orderBy,
walletId: authenticatedWalletId,
});

const res = await request(app).get(
`/trust_relationships?type=${TrustRelationshipEnums.ENTITY_TRUST_TYPE.send}&request_type=${TrustRelationshipEnums.ENTITY_TRUST_REQUEST_TYPE.send}&state=${TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.trusted}&limit=${limit}&offset=${offset}&order=${order}&sort_by=${orderBy}`,
);

expect(res).property('statusCode').eq(200);
expect(res.body.trust_relationships).to.have.lengthOf(1);
expect(res.body.trust_relationships[0]).to.eql({ id: trustId });

expect(getAllTrustRelationshipsStub).to.have.been.calledWith({
state: TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.trusted,
type: TrustRelationshipEnums.ENTITY_TRUST_TYPE.send,
request_type: TrustRelationshipEnums.ENTITY_TRUST_REQUEST_TYPE.send,
limit,
offset,
order,
sort_by: orderBy,
walletId: authenticatedWalletId,
});
});
});




describe('get /trust_relationships/:id', () => {
it('missed parameters -- relationshipId must be a guid', async () => {
const res = await request(app).get(
`/trust_relationships/trustRelationshipId`,
`/trust_relationships/trustRelationshipId`,
);
expect(res).property('statusCode').eq(422);
expect(res.body.message).match(/trustRelationshipId.*GUID/);
Expand All @@ -244,21 +236,20 @@ describe('trustRouter', () => {
const trustRelationshipId = uuid.v4();

const trustRelationshipGetByIdStub = sinon
.stub(TrustService.prototype, 'trustRelationshipGetById')
.resolves({id: trustRelationshipId});
.stub(TrustService.prototype, 'trustRelationshipGetById')
.resolves({ id: trustRelationshipId });

const res = await request(app).get(
`/trust_relationships/${trustRelationshipId}`,
`/trust_relationships/${trustRelationshipId}`,
);

expect(res).property('statusCode').eq(200);
expect(
trustRelationshipGetByIdStub.calledOnceWithExactly({
walletLoginId: authenticatedWalletId,
trustRelationshipId,
}),
trustRelationshipGetByIdStub.calledOnceWithExactly({
walletLoginId: authenticatedWalletId,
trustRelationshipId,
}),
).eql(true);
});

})
});
});
12 changes: 4 additions & 8 deletions server/handlers/trustHandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,28 @@ const trustGet = async (req, res) => {
state,
type,
request_type,
limit,
limit,
offset,
sort_by,
order
order,
} = validatedQuery;

const { wallet_id } = req;
const trustService = new TrustService();
const {
result: trust_relationships,
count: total,
} = await trustService.getAllTrustRelationships({
const trust_relationships = await trustService.getAllTrustRelationships({
walletId: wallet_id,
state,
type,
request_type,
offset,
limit,
sort_by,
order
order,
});

res.status(200).json({
trust_relationships,
query: { limit, offset, sort_by, order, state, type, request_type },
total,
});
};

Expand Down
14 changes: 10 additions & 4 deletions server/handlers/walletHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('walletRouter', () => {
describe('get /wallets', () => {
it('no limit parameter(1000 as default)', async () => {
const res = await request(app).get('/wallets');
expect(res).property('statusCode').eq(200);
});
expect(res).property('statusCode').eq(200);
});

it('successfully', async () => {
const walletId = uuid.v4();
Expand Down Expand Up @@ -105,19 +105,25 @@ describe('walletRouter', () => {
it('successfully', async () => {
const getTrustRelationshipsStub = sinon
.stub(TrustService.prototype, 'getTrustRelationships')
.resolves([{ id: trustRelationshipId }]);
.resolves({result:[{ id: trustRelationshipId }], count: 1});
const res = await request(app).get(
`/wallets/${walletId}/trust_relationships?state=${TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.requested}`,
);
const managedWallets = [];
expect(res).property('statusCode').eq(200);
expect(res.body.trust_relationships).lengthOf(1);
expect(res.body.total).eql(1);
expect(res.body.trust_relationships[0].id).eql(trustRelationshipId);
expect(
getTrustRelationshipsStub.calledOnceWithExactly(authenticatedWalletId, {
getTrustRelationshipsStub.calledOnceWithExactly(authenticatedWalletId, managedWallets, {
walletId,
state: TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.requested,
type: undefined,
request_type: undefined,
limit: 500,
offset: 0,
sort_by: 'created_at',
order: 'desc'
}),
).eql(true);
});
Expand Down
Loading

0 comments on commit a502aba

Please sign in to comment.