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 4 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 0 additions & 24 deletions cypress/tests/integration/organizations/[organizationid].cy.js

This file was deleted.

34 changes: 34 additions & 0 deletions cypress/tests/integration/stakeholder/[stakeholderid].cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import stakeholder from '../../../../doc/examples/organizations/1.json';
import { prepareNocks, clearNocks } from '../nockRoutes';

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

describe('Organizations', () => {
const imageFixturePath = `images/organization.png`;
return it(`organization 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',
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would use

path: `/query/v2/stakeholder/${stakeholder.id}`,

instead of

path: '/query/v2/stakeholder/1',

to populate the stakeholder id in path dynamically. And this should apply to all other paths in this test file if you are modifying any of them.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @yunchipang , thanks for your suggestion! I've just changed it. I agree it will make my code look cleaner.

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.visit(path, {
failOnStatusCode: false,
});

cy.url().should('include', '/stakeholder');
cy.contains(stakeholder.name);
cy.screenshot();
});
});
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.

2 changes: 1 addition & 1 deletion src/models/apiPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const apiPaths = {
planters: (id = '') => urlJoin(host, `planters/${id}`),
stakeHolders: (id = '') => urlJoin(hostStakeholder, `/stakeholders/${id}`),
species: urlJoin(host, '/species'),
organization: (id = '') => urlJoin(host, `/organizations/${id}`),
organization: (id = '') => urlJoin(host, `/stakeholder/${id}`),
wallets: (id = '') => urlJoin(host, `/wallets/${id}`),
filterSpeciesByWalletId: (id = '') =>
urlJoin(host, `/species?wallet_id=${id}`),
Expand Down
2 changes: 1 addition & 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { getOrganizationById, getOrgLinks } from 'models/api';
import * as pathResolver from 'models/pathResolver';
import { getLocationString, getContinent, wrapper } from 'models/utils';

export default function Organization(props) {
export default function Stakeholder(props) {
log.warn('props for org page:', props);
const { organization, nextExtraIsEmbed } = props;
const mapContext = useMapContext();
Expand Down Expand Up @@ -504,7 +504,9 @@ export default function Organization(props) {
}

async function serverSideData(params) {
const id = params.organizationid;
console.log('serverSideData');
console.log(params);
const id = params.stakeholderid;
const organization = await getOrganizationById(id);
const orgLinks = await getOrgLinks(organization.links);
const props = {
Expand Down
Loading