Skip to content

Commit

Permalink
feat: remove/replace references to planter entities
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-rice committed Apr 11, 2024
1 parent 7b367d4 commit 3bb97e4
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 696 deletions.
52 changes: 0 additions & 52 deletions cypress/tests/integration/nockRoutes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import grower100 from '../../../doc/examples/growers/100.json';
import organization1 from '../../../doc/examples/organizations/1.json';
import planter940 from '../../../doc/examples/planters/940.json';
import { defaultConfig } from '../../../src/context/configContext';
import capture1 from '../../fixtures/capture.json';
import leader from '../../fixtures/countries/leader.json';
Expand All @@ -10,31 +9,21 @@ export function getNockRoutes(
props = {
tree: {},
organization: {},
planter: {},
grower: {},
capture: {},
},
) {
const organization = { ...organization1, ...props.organization };
const planter = { ...planter940, ...props.planter };
const grower = { ...grower100, ...props.grower };
const tree = { ...tree186734, ...props.tree };
const capture = { ...capture1, ...props.capture };
return [
{
method: 'GET',
path: `/planters/${planter.id}`,
statusCode: 200,
body: planter,
},

{
method: 'GET',
path: `/growers/${grower.id}`,
statusCode: 200,
body: grower,
},

{
method: 'GET',
path: '/trees/featured',
Expand All @@ -43,58 +32,24 @@ export function getNockRoutes(
trees: [tree],
},
},

{
method: 'GET',
path: `/trees/${tree.id}`,
statusCode: 200,
body: tree,
},

{
method: 'GET',
path: `/planters/${planter.planter_id}`,
statusCode: 200,
body: planter,
},

{
method: 'GET',
path: `/growers/${grower.grower_id}`,
statusCode: 200,
body: grower,
},

{
method: 'GET',
path: `/organizations/${organization.id}`,
statusCode: 200,
body: organization,
},

{
method: 'GET',
path: planter.links.species,
statusCode: 200,
body: {
species: [tree],
},
},
{
method: 'GET',
path: planter.links.associated_organizations,
statusCode: 200,
body: { organizations: [organization] },
},
{
method: 'GET',
path: planter.links.featured_trees,
statusCode: 200,
body: {
trees: [tree],
},
},

{
method: 'GET',
path: grower.links.species,
Expand All @@ -117,7 +72,6 @@ export function getNockRoutes(
trees: [tree],
},
},

{
method: 'GET',
path: organization.links.species,
Expand All @@ -126,12 +80,6 @@ export function getNockRoutes(
species: [tree],
},
},
{
method: 'GET',
path: organization.links.associated_planters,
statusCode: 200,
body: { planters: [planter] },
},
{
method: 'GET',
path: organization.links.associated_growers,
Expand Down
16 changes: 0 additions & 16 deletions cypress/tests/integration/planters/[planterid].cy.js

This file was deleted.

16 changes: 0 additions & 16 deletions doc/examples/planters/940.json

This file was deleted.

Empty file.
6 changes: 0 additions & 6 deletions doc/examples/planters/940/trees.json

This file was deleted.

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: 9 additions & 5 deletions src/mocks/handlers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { rest } from 'msw';
import mockTree from '../../cypress/fixtures/tree186734.json';
import leader from '../../doc/examples/countries/leader.json';
import grower from '../../doc/examples/growers/100.json';
import organization from '../../doc/examples/organizations/1.json';
import planter from '../../doc/examples/planters/940.json';
import species from '../../doc/examples/species/1.json';

const trees = { trees: [mockTree, mockTree, mockTree] };
Expand All @@ -20,18 +20,20 @@ const handlers = [
rest.get(`${host}/trees*`, (req, res, ctx) =>
res(ctx.status(200, 'success'), ctx.json(trees)),
),
rest.get(`${host}/planters/featured`, (req, res, ctx) =>

rest.get(`${host}/growers/featured`, (req, res, ctx) =>
res(
ctx.status(200, 'success'),
ctx.json({
planters: [planter, planter, planter],
growers: [grower, grower, grower],
}),
),
),

rest.get(`${host}/planters/:id`, (req, res, ctx) =>
res(ctx.status(200, 'success'), ctx.json(planter)),
rest.get(`${host}/growers/:id`, (req, res, ctx) =>
res(ctx.status(200, 'success'), ctx.json(grower)),
),

rest.get(`${host}/organizations/featured`, (req, res, ctx) =>
res(
ctx.status(200, 'success'),
Expand All @@ -40,6 +42,7 @@ const handlers = [
}),
),
),

rest.get(`${host}/organizations/:id`, (req, res, ctx) =>
res(ctx.status(200, 'success'), ctx.json(organization)),
),
Expand All @@ -57,4 +60,5 @@ const handlers = [
res(ctx.status(200, 'success'), ctx.json(leader)),
),
];

export default handlers;
14 changes: 0 additions & 14 deletions src/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,6 @@ export async function getCountryByLatLon(lat, lon) {
}
}

export async function getPlanterById(id) {
try {
const url = apiPaths.planters(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.message);
throw err;
}
}

export async function getGrowerById(id) {
try {
const url = apiPaths.growers(id);
Expand Down
9 changes: 7 additions & 2 deletions src/models/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import {
getFeaturedTrees,
getOrganizationById,
getOrgLinks,
getPlanterById,
getGrowerById,
getTreeById,
} from './api';
import organization from '../../doc/examples/organizations/1.json';
import mockPlanter from '../../doc/examples/planters/940.json';

it('should get grower by id', async () => {
const grower = await getGrowerById(100);
expect(grower).toBeDefined();
expect(grower.first_name).toBeDefined();
});

it('should get featured trees', async () => {
const trees = await getFeaturedTrees();
Expand Down
4 changes: 2 additions & 2 deletions src/models/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const optimizeThemeFonts = (theme) => {
return temp;
};

function getPlanterName(firstName, lastName) {
function getGrowerName(firstName, lastName) {
return `${firstName} ${(lastName && lastName.slice(0, 1)) || ''}`;
}

Expand Down Expand Up @@ -322,7 +322,7 @@ export {
debounce,
loadFonts,
optimizeThemeFonts,
getPlanterName,
getGrowerName,
convertFontObjToFontArr,
nextPathBaseDecode,
nextPathBaseEncode,
Expand Down
18 changes: 6 additions & 12 deletions src/pages/growers/[growerid].js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Icon from 'components/common/CustomIcon';
import Info from 'components/common/Info';
import { useDrawerContext } from 'context/DrawerContext';
import { useMobile } from 'hooks/globalHooks';
import planterBackground from 'images/background.png';
import growerBackground from 'images/background.png';
import CalendarIcon from 'images/icons/calendar.svg';
import LocationIcon from 'images/icons/location.svg';
import PeopleIcon from 'images/icons/people.svg';
Expand All @@ -34,7 +34,7 @@ import { useMapContext } from 'mapContext';
import { getGrowerById, getOrgLinks } from 'models/api';
import { makeStyles } from 'models/makeStyles';
import * as pathResolver from 'models/pathResolver';
import { getLocationString, getPlanterName, wrapper } from 'models/utils';
import { getLocationString, getGrowerName, wrapper } from 'models/utils';

// make styles for component with material-ui
const useStyles = makeStyles()((theme) => ({
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function Grower(props) {
// try to find first tree image or default image return
const backgroundPic =
grower?.featuredTrees?.trees?.[0]?.image_url ||
`${router.basePath}${planterBackground}`;
`${router.basePath}${growerBackground}`;

useEffect(() => {
setTitlesData({
Expand Down Expand Up @@ -135,10 +135,7 @@ export default function Grower(props) {
return (
<>
<HeadTag
title={`${getPlanterName(
grower.first_name,
grower.last_name,
)} - Grower`}
title={`${getGrowerName(grower.first_name, grower.last_name)} - Grower`}
/>
<Box
sx={[
Expand Down Expand Up @@ -176,10 +173,7 @@ export default function Grower(props) {
},
{
icon: grower.image_url,
name: `${getPlanterName(
grower.first_name,
grower.last_name,
)}`,
name: `${getGrowerName(grower.first_name, grower.last_name)}`,
},
]}
/>
Expand Down Expand Up @@ -228,7 +222,7 @@ export default function Grower(props) {
}}
>
<Typography variant="h2">
{getPlanterName(grower.first_name, grower.last_name)}
{getGrowerName(grower.first_name, grower.last_name)}
</Typography>
<Box sx={{ mt: 2 }}>
<Info
Expand Down
Loading

0 comments on commit 3bb97e4

Please sign in to comment.