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

Feat: add integration test for the stakeholder #1774

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions cypress/fixtures/940.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": 940,
"first_name": "Sebastian ",
"last_name": "Gaertner",
"image_url": "https://treetracker-dev-images.s3.eu-central-1.amazonaws.com/2020.10.19.09.47.53_-5.508107173727935_38.981361706266256_39f0cc9d-0f13-4547-8142-150f15cabb67_IMG_20201019_094513_6614320100195503436.jpg",
"trees_planted": 4,
"about": "Greenway is a Youth-Driven Environmental Protection Organization providing alternative solutions to single-use plastic and planting carbon-sucking trees for socio-economic development and reducing climate crisis. Our social work includes reforestation, landscape restoration, climate education, awareness campaign, conducting research, outreach activities, and collaborating with key stakeholders to implement sustainable solutions.",
"mission": "To combat climate change, desertification, land degradation, carbon emission by inspiring healthier communities affected by severe climate disorder and modestly reducing pollution by 2050.",
"created_time": "2018-01-01",
"country": "Tanzania",
"links": {
"featured_trees": "/trees?planter_id=940&limit=4",
"associated_organizations": "/organizations?planter_id=940",
"species": "/species?planter_id=940"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('Organizations', () => {
prepareNocks({ organization: { ...org, photo_url } });
});

cy.visit(path);
cy.visit(path, {
failOnStatusCode: false,
});

cy.url().should('include', '/organizations');
cy.contains(org.name);
Expand Down
60 changes: 60 additions & 0 deletions cypress/tests/integration/stakeholder/[stakeholderid].cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import species from '../../../../doc/examples/species/1.json';
import stakeholder from '../../../../doc/examples/stakeholders/180Earth.json';
import planter from '../../../fixtures/940.json';
import exampleTreeData from '../../../fixtures/tree186734.json';
import { prepareNocks, clearNocks } from '../nockRoutes';

beforeEach(() => {
clearNocks();
});

describe('Stakeholder', () => {
const imageFixturePath = `images/organization.png`;
return it(`stakeholder test`, () => {
const path = `/stakeholder/${stakeholder.id}`;
cy.fixture(imageFixturePath).then((image) => {
const blob = Cypress.Blob.base64StringToBlob(image, 'images/png');
const photo_url = Cypress.Blob.createObjectURL(blob);
prepareNocks({ stakeholder: { ...stakeholder, photo_url } });
});

cy.task('nockIntercept', {
hostname: 'https://dev-k8s.treetracker.org',
method: 'get',
path: '/query/v2/stakeholder/1',
statusCode: 200,
body: stakeholder,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The organization mock json is deprecated, please create a new fixture (under fixture folder) json file for stakeholder , the spec of stakeholder is defined in our query api doc here:
https://github.com/Greenstand/treetracker-query-api/blob/fa194cb4a274ee688c2b26b58596147368d08b9e/docs/api/spec/query-api.yaml#L1542-L1559

});

cy.task('nockIntercept', {
hostname: 'https://dev-k8s.treetracker.org',
method: 'get',
path: '/query/v2/trees?stakeholder_id=1',
statusCode: 200,
body: { total: 1, offset: 0, limit: 4, trees: [exampleTreeData] },
});

cy.task('nockIntercept', {
hostname: 'https://dev-k8s.treetracker.org',
method: 'get',
path: '/query/v2/planters?stakeholder_id=1',
statusCode: 200,
body: { total: 1, offset: 0, limit: 4, planters: [planter] },
});

cy.task('nockIntercept', {
hostname: 'https://dev-k8s.treetracker.org',
method: 'get',
path: '/query/v2/species?stakeholder_id=1',
statusCode: 200,
body: { total: 1, offset: 0, limit: 4, species: [species] },
});

cy.visit(path, {
failOnStatusCode: false,
});

cy.url().should('include', '/stakeholder');
cy.screenshot();
});
});
17 changes: 17 additions & 0 deletions doc/examples/stakeholders/180Earth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": 1,
"type": "organization",
"org_name": "180Earth",
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"phone": "1234567890",
"website": "www.180earth.com",
"logo_url": "https://180.earth/wp-content/uploads/2020/01/Asset-1.png",
"map": "Shirimatunda, Tanzania",
"created_at": "November 11, 2019",
"updated_at": "April 1, 2024",
"active": "true",
"entity_id": 1
}

4 changes: 2 additions & 2 deletions package-lock.json

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

14 changes: 14 additions & 0 deletions src/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,17 @@ export async function getTokenById(id) {
throw err;
}
}

export async function getStakeholderById(id) {
try {
const url = apiPaths.stakeholder(id);
const begin = Date.now();
const res = await axios.get(url);
const data = await res.data;
log.warn('url:', url, 'took:', Date.now() - begin);
return data;
} catch (err) {
log.error(err);
throw err;
}
}
1 change: 1 addition & 0 deletions src/models/apiPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const apiPaths = {
filterSpeciesByWalletId: (id = '') =>
urlJoin(host, `/species?wallet_id=${id}`),
tokens: (id = '') => urlJoin(host, `/tokens/${id}`),
stakeholder: (id = '') => urlJoin(host, `/stakeholder/${id}`),
};

export default apiPaths;
4 changes: 1 addition & 3 deletions src/pages/organizations/[organizationid].js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ export default function Organization(props) {
</Typography>
<FeaturedTreesSlider
trees={featuredTrees.trees}
link={(item) =>
`/organizations/${organization.id}/trees/${item.id}`
}
link={(item) => `/trees/${item.id}`}
/>
<Grid
container
Expand Down
4 changes: 3 additions & 1 deletion src/pages/planters/[planterid].js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export default function Planter(props) {
entityName={org.name}
entityType="Planting Organization"
buttonText="Meet the Organization"
link={`/organizations/${org.id}`}
link={`/stakeholder/${org.id}`}
cardImageSrc={org?.logo_url}
/>
<Box sx={{ mt: [6, 12] }} />
Expand Down Expand Up @@ -525,6 +525,8 @@ export default function Planter(props) {
}

async function serverSideData(params) {
console.log('serverSideData');
console.log(params);
const id = params.planterid;
const planter = await getPlanterById(id);
const data = await getOrgLinks(planter.links);
Expand Down
Loading
Loading