Skip to content

Commit

Permalink
chore: undo api endpoints change
Browse files Browse the repository at this point in the history
  • Loading branch information
yunchipang committed Nov 6, 2024
1 parent 2d717da commit 60a7083
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NEXT_PUBLIC_API=https://dev-k8s.treetracker.org/query/
NEXT_PUBLIC_API_V2=https://dev-k8s.treetracker.org/query/v2
NEXT_PUBLIC_API=https://dev-k8s.treetracker.org/query/v2
NEXT_PUBLIC_API_V2=https://dev-k8s.treetracker.org/query/
NEXT_PUBLIC_STAKEHOLDER_API=https://dev-k8s.treetracker.org/stakeholder
NEXT_PUBLIC_TILE_SERVER_URL=https://{s}.treetracker.org/tiles/
NEXT_PUBLIC_TILE_SERVER_SUBDOMAINS=dev-k8s
Expand Down
File renamed without changes.
32 changes: 28 additions & 4 deletions cypress/tests/integration/captures/[captureid].cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import capture from '../../../../doc/examples/captures/0c2d6e3a-d02a-4edf-bcdc-893e1f7a4817.json';
import { prepareNocks, clearNocks } from '../nockRoutes';
import capture from '../../../fixtures/capture.json';

beforeEach(() => {
clearNocks();
if (Cypress.env('nock')) {
cy.task('clearNock');
}
});

describe('Captures', () => {});
it('getStaticProps returns mock data for capture', () => {
const path = `/captures/${capture.id}`;

if (Cypress.env('nock')) {
cy.task('nock', {
hostname: Cypress.env('NEXT_PUBLIC_API'),
method: 'GET',
path: `/query/v2/captures/${capture.id}`,
statusCode: 200,
body: capture,
});
}

cy.visit(path);

// Assertions
cy.contains(`Capture #${capture.id}`);
cy.contains(capture.species_name || 'Unknown Species');
cy.contains(
`Captured on ${new Date(capture.created_at).toLocaleDateString()}`,
);
cy.contains(capture.token_id ? 'Token issued' : 'Token not issued');
cy.contains(capture.wallet_name || 'No wallet owns it');
});
6 changes: 5 additions & 1 deletion src/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ export async function getTreeById(id) {
}
}

export async function getCaptureById(id) {
export async function getCapturesById(id) {
try {
const url = apiPaths.captures(id);

// debug
log.warn('---------- getCapturesById url: ', url);

const begin = Date.now();
const res = await axios.get(url);
const { data } = res;
Expand Down
10 changes: 5 additions & 5 deletions src/models/apiPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ const hostV2 = process.env.NEXT_PUBLIC_API_V2 || '';
const hostStakeholder = process.env.NEXT_PUBLIC_STAKEHOLDER_API || '';
const apiPaths = {
featuredTrees: urlJoin(host, 'trees/featured'),
featuredGrowers: urlJoin(hostV2, 'growers/featured'),
getCaptures: urlJoin(hostV2, 'captures'),
featuredGrowers: urlJoin(host, 'growers/featured'),
getCaptures: urlJoin(host, 'captures'),
countriesLatLon: (lat = '', lon = '') =>
urlJoin(host, `/countries?lat=${lat}&lon=${lon}`),
leaders: urlJoin(host, '/countries/leaderboard'),
trees: (id = '') => urlJoin(host, `/trees/${id}`),
getCapturesByTreeId: (treeid = '') =>
urlJoin(hostV2, `/captures?tree_id=${treeid}`),
captures: (id = '') => urlJoin(hostV2, `captures/${id}`),
growers: (id = '') => urlJoin(hostV2, `growers/${id}`),
urlJoin(host, `/captures?tree_id=${treeid}`),
captures: (id = '') => urlJoin(host, `captures/${id}`),
growers: (id = '') => urlJoin(host, `growers/${id}`),
stakeHolders: (id = '') => urlJoin(hostStakeholder, `/stakeholders/${id}`),
species: urlJoin(host, '/species'),
organization: (id = '') => urlJoin(host, `/organizations/${id}`),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/captures/[captureid].js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import SearchIcon from 'images/search.svg';
import { useMapContext } from 'mapContext';
import {
getStakeHolderById,
getCaptureById,
getCapturesById,
getGrowerById,
getCountryByLatLon,
} from 'models/api';
Expand Down Expand Up @@ -739,7 +739,7 @@ export default function Capture({

async function serverSideData(params) {
const { captureid } = params;
const capture = await getCaptureById(captureid);
const capture = await getCapturesById(captureid);
const { planting_organization_id, grower_account_id, lat, lon } = capture;

// fetch grower and country information
Expand Down

0 comments on commit 60a7083

Please sign in to comment.