diff --git a/example.env b/example.env index 9e8ace083a..90d4ebe4a4 100644 --- a/example.env +++ b/example.env @@ -87,7 +87,8 @@ OSM_REGISTER_URL=https://www.openstreetmap.org/user/new # API base URL and token(used to retrieve user stats only) for ohsomeNow Stats # -OHSOME_STATS_BASE_URL=https://stats.now.ohsome.org/api +OHSOME_STATS_BASE_URL=https://stats.now.ohsome.org +OHSOME_STATS_API_URL=https://stats.now.ohsome.org/api OHSOME_STATS_TOKEN=testSuperSecretTestToken # Secret (required) diff --git a/frontend/src/api/stats.ts b/frontend/src/api/stats.ts index 59c5701760..2f16faf1cb 100644 --- a/frontend/src/api/stats.ts +++ b/frontend/src/api/stats.ts @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'; import { fetchExternalJSONAPI } from '../network/genericJSONRequest'; import api from './apiClient'; -import { OHSOME_STATS_BASE_URL, defaultChangesetComment } from '../config'; +import { OHSOME_STATS_API_URL, defaultChangesetComment } from '../config'; const ohsomeProxyAPI = (url: string) => { const token = localStorage.getItem('token'); @@ -11,9 +11,7 @@ const ohsomeProxyAPI = (url: string) => { }; export const useSystemStatisticsQuery = () => { - const fetchSystemStats = ({ signal }: { - signal: AbortSignal; - }) => { + const fetchSystemStats = ({ signal }: { signal: AbortSignal }) => { return api().get(`system/statistics/`, { signal, }); @@ -27,9 +25,7 @@ export const useSystemStatisticsQuery = () => { }; export const useProjectStatisticsQuery = (projectId: string) => { - const fetchProjectStats = ({ signal }: { - signal: AbortSignal; - }) => { + const fetchProjectStats = ({ signal }: { signal: AbortSignal }) => { return api().get(`projects/${projectId}/statistics/`, { signal, }); @@ -43,10 +39,8 @@ export const useProjectStatisticsQuery = (projectId: string) => { }; export const useOsmStatsQuery = () => { - const fetchOsmStats = ({ signal }: { - signal: AbortSignal; - }) => { - return api().get(`${OHSOME_STATS_BASE_URL}/stats/${defaultChangesetComment}-%2A`, { + const fetchOsmStats = ({ signal }: { signal: AbortSignal }) => { + return api().get(`${OHSOME_STATS_API_URL}/stats/${defaultChangesetComment}-%2A`, { signal, }); }; @@ -60,10 +54,8 @@ export const useOsmStatsQuery = () => { }; export const useOsmHashtagStatsQuery = (defaultComment: string) => { - const fetchOsmStats = ({ signal }: { - signal: AbortSignal; - }) => { - return api().get(`${OHSOME_STATS_BASE_URL}/stats/${defaultComment[0].replace('#', '')}`, { + const fetchOsmStats = ({ signal }: { signal: AbortSignal }) => { + return api().get(`${OHSOME_STATS_API_URL}/stats/${defaultComment[0].replace('#', '')}`, { signal, }); }; @@ -80,7 +72,7 @@ export const useOsmHashtagStatsQuery = (defaultComment: string) => { export const useUserOsmStatsQuery = (id: string) => { const fetchUserOsmStats = () => { return ohsomeProxyAPI( - `${OHSOME_STATS_BASE_URL}/topic/poi,highway,building,waterway/user?userId=${id}`, + `${OHSOME_STATS_API_URL}/topic/poi,highway,building,waterway/user?userId=${id}`, ); }; @@ -96,7 +88,7 @@ export const useUserOsmStatsQuery = (id: string) => { export const useOsmStatsMetadataQuery = () => { const fetchOsmStatsMetadata = () => { - return fetchExternalJSONAPI(`${OHSOME_STATS_BASE_URL}/metadata`); + return fetchExternalJSONAPI(`${OHSOME_STATS_API_URL}/metadata`); }; return useQuery({ diff --git a/frontend/src/components/partners/partnersActivity.jsx b/frontend/src/components/partners/partnersActivity.jsx index 1a645ce636..e58019b073 100644 --- a/frontend/src/components/partners/partnersActivity.jsx +++ b/frontend/src/components/partners/partnersActivity.jsx @@ -4,7 +4,7 @@ import ReactPlaceholder from 'react-placeholder'; import PartnersProgresBar from './partnersProgresBar'; import messages from './messages'; -import { OHSOME_STATS_BASE_URL } from '../../config'; +import { OHSOME_STATS_API_URL } from '../../config'; export const Activity = ({ partner }) => { const [data, setData] = useState(null); @@ -22,7 +22,7 @@ export const Activity = ({ partner }) => { ?.map((tag) => tag.trim().replace('#', '').toLowerCase()) ?.join(','); const response = await fetch( - OHSOME_STATS_BASE_URL + `/stats/hashtags/${primaryHashtag},${secondaryHashtags}`, + OHSOME_STATS_API_URL + `/stats/hashtags/${primaryHashtag},${secondaryHashtags}`, ); if (response.ok) { diff --git a/frontend/src/components/partners/partnersProgresBar.jsx b/frontend/src/components/partners/partnersProgresBar.jsx index d79689d8d1..0e3a0d348b 100644 --- a/frontend/src/components/partners/partnersProgresBar.jsx +++ b/frontend/src/components/partners/partnersProgresBar.jsx @@ -17,7 +17,7 @@ const ProgressBar = ({ className, firstBarValue, secondBarValue = 0, data }) => target={'_blank'} rel="noreferrer" className="white no-underline" - href={OHSOME_STATS_BASE_URL + '/dashboard#hashtags=' + data.primary} + href={OHSOME_STATS_BASE_URL + '/dashboard#hashtag=' + data.primary} > {'#' + data.primary}{' '} diff --git a/frontend/src/components/teamsAndOrgs/featureStats.jsx b/frontend/src/components/teamsAndOrgs/featureStats.jsx index 5522e0f66a..a0467c26e9 100644 --- a/frontend/src/components/teamsAndOrgs/featureStats.jsx +++ b/frontend/src/components/teamsAndOrgs/featureStats.jsx @@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl'; import messages from './messages'; import userDetailMessages from '../userDetail/messages'; -import { OHSOME_STATS_BASE_URL, defaultChangesetComment } from '../../config'; +import { OHSOME_STATS_API_URL, defaultChangesetComment } from '../../config'; import { RoadIcon, HomeIcon, WavesIcon, MarkerIcon } from '../svgIcons'; import { StatsCard } from '../statsCard'; import StatsInfoFooter from '../statsInfoFooter'; @@ -14,7 +14,7 @@ export const FeatureStats = () => { const getStats = async () => { try { const response = await axios.get( - `${OHSOME_STATS_BASE_URL}/stats/${defaultChangesetComment}-%2A`, + `${OHSOME_STATS_API_URL}/stats/${defaultChangesetComment}-%2A`, ); const { edits, buildings, roads } = response.data.result; setStats({ diff --git a/frontend/src/config/index.ts b/frontend/src/config/index.ts index 10830d26cc..24055dcd2e 100644 --- a/frontend/src/config/index.ts +++ b/frontend/src/config/index.ts @@ -4,7 +4,9 @@ export const API_URL = import.meta.env.REACT_APP_API_URL ? new URL('/api/' + API_VERSION + '/', import.meta.env.REACT_APP_API_URL) : 'http://127.0.0.1:5000/api/' + API_VERSION + '/'; export const OHSOME_STATS_BASE_URL = - import.meta.env.REACT_APP_OHSOME_STATS_BASE_URL || 'https://stats.now.ohsome.org/api'; + import.meta.env.REACT_APP_OHSOME_STATS_BASE_URL || 'https://stats.now.ohsome.org'; +export const OHSOME_STATS_API_URL = + import.meta.env.REACT_APP_OHSOME_STATS_API_URL || 'https://stats.now.ohsome.org/api'; // APPLICATION SETTINGS export const DEFAULT_LOCALE = import.meta.env.REACT_APP_DEFAULT_LOCALE || 'en'; export const ENVIRONMENT = import.meta.env.REACT_APP_ENVIRONMENT || ''; @@ -12,7 +14,8 @@ export const PROJECTCARD_CONTRIBUTION_SHOWN_THRESHOLD = import.meta.env.REACT_APP_PROJECTCARD_CONTRIBUTION_SHOWN_THRESHOLD || 5; export const INTERMEDIATE_LEVEL_COUNT = Number(import.meta.env.REACT_APP_TM_MAPPER_LEVEL_INTERMEDIATE) || 250; -export const ADVANCED_LEVEL_COUNT = Number(import.meta.env.REACT_APP_TM_MAPPER_LEVEL_ADVANCED) || 500; +export const ADVANCED_LEVEL_COUNT = + Number(import.meta.env.REACT_APP_TM_MAPPER_LEVEL_ADVANCED) || 500; export const MAPBOX_TOKEN = import.meta.env.REACT_APP_MAPBOX_TOKEN || ''; export const ENABLE_SERVICEWORKER = import.meta.env.REACT_APP_ENABLE_SERVICEWORKER || 0; export const MAX_AOI_AREA = Number(import.meta.env.REACT_APP_MAX_AOI_AREA) || 5000; @@ -57,7 +60,8 @@ export const ID_EDITOR_URL = export const POTLATCH2_EDITOR_URL = import.meta.env.REACT_APP_POTLATCH2_EDITOR_URL || 'https://www.openstreetmap.org/edit?editor=potlatch2'; -export const RAPID_EDITOR_URL = import.meta.env.REACT_APP_RAPID_EDITOR_URL || 'https://mapwith.ai/rapid'; +export const RAPID_EDITOR_URL = + import.meta.env.REACT_APP_RAPID_EDITOR_URL || 'https://mapwith.ai/rapid'; export const EXPORT_TOOL_S3_URL = import.meta.env.REACT_APP_EXPORT_TOOL_S3_URL || ''; export const ENABLE_EXPORT_TOOL = import.meta.env.REACT_APP_ENABLE_EXPORT_TOOL || ''; @@ -173,7 +177,8 @@ export const MAP_STYLE = MAPBOX_TOKEN export const MAPBOX_RTL_PLUGIN_URL = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js'; -export const UNDERPASS_URL = import.meta.env.REACT_APP_UNDERPASS_URL || 'https://underpass.hotosm.org'; +export const UNDERPASS_URL = + import.meta.env.REACT_APP_UNDERPASS_URL || 'https://underpass.hotosm.org'; export const DROPZONE_SETTINGS = { accept: { diff --git a/frontend/src/config/tests/config.test.js b/frontend/src/config/tests/config.test.js index 67e100878f..1d3330ec11 100644 --- a/frontend/src/config/tests/config.test.js +++ b/frontend/src/config/tests/config.test.js @@ -7,8 +7,8 @@ it('exports API_URL', () => { it('exports API_VERSION', () => { expect(['object', 'string']).toContain(typeof config.API_VERSION); }); -it('exports OHSOME_STATS_BASE_URL', () => { - expect(typeof config.OHSOME_STATS_BASE_URL).toBe('string'); +it('exports OHSOME_STATS_API_URL', () => { + expect(typeof config.OHSOME_STATS_API_URL).toBe('string'); }); it('exports ORG_URL', () => { expect(typeof config.ORG_URL).toBe('string'); diff --git a/frontend/src/network/tests/server-handlers.js b/frontend/src/network/tests/server-handlers.js new file mode 100644 index 0000000000..7abc498457 --- /dev/null +++ b/frontend/src/network/tests/server-handlers.js @@ -0,0 +1,433 @@ +import { rest } from 'msw'; + +import { + getProjectSummary, + getProjectStats, + projects, + projectDetail, + userTouchedProjects, + projectComments, + userFavorite, + favoritePost, + activities, + taskDetail, + stopMapping, + stopValidation, + similarProjects, +} from './mockData/projects'; +import { featuredProjects } from './mockData/featuredProjects'; +import { + newUsersStats, + userStats, + osmStatsProject, + userLockedTasksDetails, + ohsomeNowUserStats, +} from './mockData/userStats'; +import { projectContributions, projectContributionsByDay } from './mockData/contributions'; +import { + usersList, + levelUpdationSuccess, + roleUpdationSuccess, + userQueryDetails, +} from './mockData/userList'; +import { + license, + licenseCreationSuccess, + licenseDeletionSuccess, + organisations, + organisation, + organisationUpdationSuccess, + organisationCreationSuccess, + organisationDeletionSuccess, + campaigns, + campaignCreationSuccess, + campaign, + campaignUpdationSuccess, + campaignDeletionSuccess, + interests, + interest, + interestCreationSuccess, + interestUpdationSuccess, + interestDeletionSuccess, + licenses, + licenseAccepted, +} from './mockData/management'; +import { + teams, + team, + teamCreationSuccess, + teamUpdationSuccess, + teamDeletionSuccess, +} from './mockData/teams'; +import { userTasks } from './mockData/tasksStats'; +import { homepageStats } from './mockData/homepageStats'; +import { + banner, + countries, + josmRemote, + systemStats, + ohsomeNowMetadata, +} from './mockData/miscellaneous'; +import tasksGeojson from '../../utils/tests/snippets/tasksGeometry'; +import { API_URL, OHSOME_STATS_API_URL, defaultChangesetComment } from '../../config'; +import { notifications, ownCountUnread } from './mockData/notifications'; +import { authLogin, setUser, userRegister } from './mockData/auth'; +import { + extendTask, + lockForMapping, + lockForValidation, + splitTask, + submitMappingTask, + submitValidationTask, + userLockedTasks, +} from './mockData/taskHistory'; + +const handlers = [ + rest.get(API_URL + 'projects/:id/queries/summary/', async (req, res, ctx) => { + return res(ctx.json(getProjectSummary(Number(req.params.id)))); + }), + rest.get(API_URL + 'projects/:id/activities/latest/', async (req, res, ctx) => { + return res(ctx.json(activities(Number(req.params.id)))); + }), + rest.get(API_URL + 'projects/:id/queries/priority-areas/', async (req, res, ctx) => { + return res(ctx.json([])); + }), + rest.get(API_URL + 'projects/', async (req, res, ctx) => { + return res(ctx.json(projects)); + }), + rest.get(API_URL + 'projects/', async (req, res, ctx) => { + return res(ctx.json(projects)); + }), + rest.get(API_URL + 'projects/:id/contributions/', async (req, res, ctx) => { + return res(ctx.json(projectContributions)); + }), + rest.get(API_URL + 'projects/:id/', async (req, res, ctx) => { + return res(ctx.json(projectDetail)); + }), + rest.get(API_URL + 'projects/:id/comments/', async (req, res, ctx) => { + return res(ctx.json(projectComments)); + }), + rest.post(API_URL + 'projects/:id/comments/', async (req, res, ctx) => { + return res(ctx.json({ message: 'Comment posted' })); + }), + rest.delete(API_URL + 'projects/:projectId/comments/:commentId/', async (req, res, ctx) => { + return res(ctx.json({ message: 'Message deleted' })); + }), + rest.get(API_URL + 'projects/:id/favorite/', async (req, res, ctx) => { + return res(ctx.json(userFavorite)); + }), + rest.post(API_URL + 'projects/:id/favorite/', async (req, res, ctx) => { + return res(ctx.json(favoritePost(req.params.id))); + }), + rest.get(API_URL + 'projects/:id/statistics/', async (req, res, ctx) => { + const { id } = req.params; + return res(ctx.json(getProjectStats(id))); + }), + rest.get(API_URL + 'projects/:id/contributions/queries/day/', async (req, res, ctx) => { + return res(ctx.json(projectContributionsByDay)); + }), + rest.get(API_URL + 'projects/:id/tasks', async (req, res, ctx) => { + return res(ctx.json(tasksGeojson)); + }), + rest.get(API_URL + 'projects/queries/featured/', async (req, res, ctx) => { + return res(ctx.json(featuredProjects)); + }), + rest.get(API_URL + 'projects/queries/:username/touched', async (req, res, ctx) => { + return res(ctx.json(userTouchedProjects)); + }), + rest.get(API_URL + 'projects/:projectId/tasks/:taskId/', async (req, res, ctx) => { + return res(ctx.json(taskDetail(Number(req.params.taskId)))); + }), + rest.post( + API_URL + 'projects/:projectId/tasks/actions/stop-mapping/:taskId/', + async (req, res, ctx) => { + return res(ctx.json(stopMapping)); + }, + ), + rest.post( + API_URL + 'projects/:projectId/tasks/actions/stop-validation/', + async (req, res, ctx) => { + return res(ctx.json(stopValidation)); + }, + ), + rest.get(API_URL + 'projects/queries/:projectId/similar-projects/', async (req, res, ctx) => { + return res(ctx.json(similarProjects)); + }), + // AUTHENTICATION + rest.get(API_URL + 'system/authentication/login/', async (req, res, ctx) => { + return res(ctx.json(authLogin)); + }), + rest.post(API_URL + 'users/actions/register/', async (req, res, ctx) => { + return res(ctx.json(userRegister)); + }), + rest.patch(API_URL + 'users/me/actions/set-user/', async (req, res, ctx) => { + return res(ctx.json(setUser)); + }), + // NOTIFICATIONS + rest.get(API_URL + 'notifications', async (req, res, ctx) => { + return res(ctx.json(notifications)); + }), + rest.get(API_URL + 'notifications/:id', async (req, res, ctx) => { + return res(ctx.json(notifications.userMessages[0])); + }), + rest.get(API_URL + 'notifications/queries/own/count-unread/', async (req, res, ctx) => { + return res(ctx.json(ownCountUnread)); + }), + rest.delete(API_URL + 'notifications/:id/', async (req, res, ctx) => { + return res(ctx.json({ Success: 'Message deleted' })); + }), + rest.delete(API_URL + 'notifications/delete-all/', async (req, res, ctx) => { + return res(ctx.json({ Success: 'Message deleted' })); + }), + rest.delete(API_URL + 'notifications/delete-all/:types', async (req, res, ctx) => { + return res(ctx.json({ Success: 'Message deleted' })); + }), + rest.delete(API_URL + 'notifications/delete-multiple/', async (req, res, ctx) => { + return res(ctx.json({ Success: 'Message deleted' })); + }), + rest.post(API_URL + 'notifications/queries/own/post-unread/', async (req, res, ctx) => { + return res(ctx.json(null)); + }), + rest.post(API_URL + 'notifications/mark-as-read-all/', async (req, res, ctx) => { + return res(ctx.json(null)); + }), + rest.post(API_URL + 'notifications/mark-as-read-all/:types', async (req, res, ctx) => { + return res(ctx.json(null)); + }), + rest.post(API_URL + 'notifications/mark-as-read-multiple/', async (req, res, ctx) => { + return res(ctx.json(null)); + }), + // USER + rest.get(API_URL + 'users/statistics/', async (req, res, ctx) => { + return res(ctx.json(newUsersStats)); + }), + rest.get(API_URL + 'tasks/statistics/', async (req, res, ctx) => { + return res(ctx.json(newUsersStats)); + }), + rest.get(API_URL + 'users/queries/:username', async (req, res, ctx) => { + return res(ctx.json(userQueryDetails)); + }), + rest.get(API_URL + 'users', async (req, res, ctx) => { + return res(ctx.json(usersList)); + }), + rest.patch(API_URL + 'users/:username/actions/set-level/:level', (req, res, ctx) => { + return res(ctx.json(levelUpdationSuccess)); + }), + rest.patch(API_URL + 'users/:username/actions/set-role/:role', (req, res, ctx) => { + return res(ctx.json(roleUpdationSuccess)); + }), + rest.get(API_URL + 'users/:userId/tasks/', async (req, res, ctx) => { + return res(ctx.json(userTasks)); + }), + rest.get(API_URL + 'users/:username/statistics/', async (req, res, ctx) => { + return res(ctx.json(userStats)); + }), + rest.get(API_URL + 'users/queries/tasks/locked/details/', async (req, res, ctx) => { + return res(ctx.json(userLockedTasksDetails)); + }), + // ORGANIZATIONS + rest.get(API_URL + 'organisations', (req, res, ctx) => { + return res(ctx.json(organisations)); + }), + rest.get(API_URL + 'organisations/:id/', (req, res, ctx) => { + return res(ctx.json(organisation)); + }), + rest.post(API_URL + 'organisations', (req, res, ctx) => { + return res(ctx.json(organisationCreationSuccess)); + }), + rest.patch(API_URL + 'organisations/:id/', (req, res, ctx) => { + return res(ctx.json(organisationUpdationSuccess)); + }), + rest.delete(API_URL + 'organisations/:id', (req, res, ctx) => { + return res(ctx.json(organisationDeletionSuccess)); + }), + // TEAMS + rest.get(API_URL + 'teams', (req, res, ctx) => { + return res(ctx.json(teams)); + }), + rest.get(API_URL + 'teams/:id/', (req, res, ctx) => { + return res(ctx.json(team)); + }), + rest.post(API_URL + 'teams', (req, res, ctx) => { + return res(ctx.json(teamCreationSuccess)); + }), + rest.patch(API_URL + 'teams/:id/', (req, res, ctx) => { + return res(ctx.json(teamUpdationSuccess)); + }), + rest.delete(API_URL + 'teams/:id', (req, res, ctx) => { + return res(ctx.json(teamDeletionSuccess)); + }), + // LICENSES + rest.get(API_URL + 'licenses', (req, res, ctx) => { + return res(ctx.json(licenses)); + }), + rest.get(API_URL + 'licenses/:id/', (req, res, ctx) => { + return res(ctx.json(license)); + }), + rest.patch(API_URL + 'licenses/:id', (req, res, ctx) => { + return res(ctx.json(req.body)); + }), + rest.delete(API_URL + 'licenses/:id', (req, res, ctx) => { + return res(ctx.json(licenseDeletionSuccess)); + }), + rest.post(API_URL + 'licenses', (req, res, ctx) => { + return res(ctx.json(licenseCreationSuccess)); + }), + rest.post(API_URL + 'licenses/:id/actions/accept-for-me/', (req, res, ctx) => { + return res(ctx.json(licenseAccepted)); + }), + // CAMPAIGNS + rest.get(API_URL + 'campaigns', (req, res, ctx) => { + return res(ctx.json(campaigns)); + }), + rest.post(API_URL + 'campaigns', (req, res, ctx) => { + return res(ctx.json(campaignCreationSuccess)); + }), + rest.get(API_URL + 'campaigns/:id', (req, res, ctx) => { + return res(ctx.json(campaign)); + }), + rest.patch(API_URL + 'campaigns/:id', (req, res, ctx) => { + return res(ctx.json(campaignUpdationSuccess)); + }), + rest.delete(API_URL + 'campaigns/:id', (req, res, ctx) => { + return res(ctx.json(campaignDeletionSuccess)); + }), + // INTERESTS + rest.get(API_URL + 'interests', (req, res, ctx) => { + return res(ctx.json(interests)); + }), + rest.get(API_URL + 'interests/:id/', (req, res, ctx) => { + return res(ctx.json(interest)); + }), + rest.patch(API_URL + 'interests/:id', (req, res, ctx) => { + return res(interestUpdationSuccess(req.body.name)); + }), + rest.delete(API_URL + 'interests/:id', (req, res, ctx) => { + return res(ctx.json(interestDeletionSuccess)); + }), + rest.post(API_URL + 'interests', (req, res, ctx) => { + return res(ctx.json(interestCreationSuccess(req.body.name))); + }), + rest.get(API_URL + 'countries', (req, res, ctx) => { + return res(ctx.json(countries)); + }), + rest.get(API_URL + 'system/banner/', (req, res, ctx) => { + return res(ctx.json(banner)); + }), + //TASKS + rest.post( + API_URL + 'projects/:projectId/tasks/actions/lock-for-mapping/:taskId', + (req, res, ctx) => { + return res(ctx.json(lockForMapping)); + }, + ), + rest.post(API_URL + 'projects/:projectId/tasks/actions/lock-for-validation/', (req, res, ctx) => { + return res(ctx.json(lockForValidation)); + }), + rest.post( + API_URL + 'projects/:projectId/tasks/actions/unlock-after-mapping/:taskId', + (req, res, ctx) => { + return res(ctx.json(submitMappingTask)); + }, + ), + rest.post( + API_URL + 'projects/:projectId/tasks/actions/unlock-after-validation/', + (req, res, ctx) => { + return res(ctx.json(submitValidationTask)); + }, + ), + rest.get(API_URL + 'users/queries/tasks/locked/', (req, res, ctx) => { + return res(ctx.json(userLockedTasks)); + }), + rest.post(API_URL + 'projects/:projectId/tasks/actions/split/:taskId/', (req, res, ctx) => { + return res(ctx.json(splitTask)); + }), + rest.post(API_URL + 'projects/:projectId/tasks/actions/extend/', (req, res, ctx) => { + return res(ctx.json(extendTask)); + }), + rest.get(API_URL + 'system/statistics/', (req, res, ctx) => { + return res(ctx.json(systemStats)); + }), + // EXTERNAL API + rest.get(`${OHSOME_STATS_API_URL}/stats/${defaultChangesetComment}-%2A`, (req, res, ctx) => { + return res(ctx.json(homepageStats)); + }), + rest.get(`${OHSOME_STATS_API_URL}/hot-tm-user`, (req, res, ctx) => { + return res(ctx.json(ohsomeNowUserStats)); + }), + rest.get(`${OHSOME_STATS_API_URL}/stats/:projectId`, (req, res, ctx) => { + return res(ctx.json(osmStatsProject)); + }), + rest.get(`${OHSOME_STATS_API_URL}/metadata`, (req, res, ctx) => { + return res(ctx.json(ohsomeNowMetadata)); + }), + rest.get('http://127.0.0.1:8111/version', (req, res, ctx) => { + return res(ctx.json(josmRemote)); + }), + rest.get('http://127.0.0.1:8111/load_data', (req, res, ctx) => { + return res(ctx.text('OK')); + }), + rest.get('http://127.0.0.1:8111/load_and_zoom', (req, res, ctx) => { + return res(ctx.text('OK')); + }), + rest.get('http://127.0.0.1:8111/import', (req, res, ctx) => { + return res(ctx.text('OK')); + }), +]; + +const failedToConnectError = (req, res, ctx) => { + return res.networkError('Failed to connect'); +}; + +const faultyHandlers = [ + rest.get(API_URL + 'projects/:id/', async (req, res, ctx) => { + return res.once( + ctx.status(403), + ctx.json({ + SubCode: `PrivateProject`, + }), + ); + }), + rest.get(API_URL + 'projects/:id/', async (req, res, ctx) => { + return res.once( + ctx.status(403), + ctx.json({ + SubCode: `Project Not Found`, + }), + ); + }), + rest.get('http://127.0.0.1:8111/version', failedToConnectError), + rest.post( + API_URL + 'projects/:projectId/tasks/actions/lock-for-mapping/:taskId', + failedToConnectError, + ), + rest.post( + API_URL + 'projects/:projectId/tasks/actions/lock-for-validation', + failedToConnectError, + ), + rest.post(API_URL + 'projects/:projectId/tasks/actions/extend/', failedToConnectError), + rest.post(API_URL + 'projects/:projectId/tasks/actions/split/:taskId/', failedToConnectError), + rest.get(API_URL + 'projects/queries/:projectId/similar-projects/', failedToConnectError), + rest.post(API_URL + 'licenses', failedToConnectError), + rest.patch(API_URL + 'licenses/:id', failedToConnectError), + rest.post(API_URL + 'interests', failedToConnectError), + rest.post(API_URL + 'campaigns', failedToConnectError), + rest.patch(API_URL + 'campaigns/:id', failedToConnectError), + rest.delete(API_URL + 'campaigns/:id', failedToConnectError), + rest.post(API_URL + 'teams', failedToConnectError), + rest.patch(API_URL + 'teams/:id/', failedToConnectError), + rest.delete(API_URL + 'teams/:id', failedToConnectError), + rest.post(API_URL + 'organisations', failedToConnectError), + rest.delete(API_URL + 'notifications/delete-multiple/', failedToConnectError), + rest.delete(API_URL + 'notifications/delete-all/', failedToConnectError), + rest.delete(API_URL + 'notifications/delete-all/:types', failedToConnectError), + rest.post(API_URL + 'notifications/mark-as-read-all/', failedToConnectError), + rest.post(API_URL + 'notifications/mark-as-read-all/:types', failedToConnectError), + rest.post(API_URL + 'notifications/mark-as-read-multiple/', failedToConnectError), + rest.get(API_URL + 'notifications/:id/', failedToConnectError), + rest.delete(API_URL + 'notifications/:id/', failedToConnectError), + rest.patch(API_URL + 'users/:username/actions/set-level/:level', failedToConnectError), + rest.patch(API_URL + 'users/:username/actions/set-role/:role', failedToConnectError), +]; + +export { handlers, faultyHandlers }; diff --git a/frontend/src/views/partnersStats.jsx b/frontend/src/views/partnersStats.jsx index fd3fbb98bc..8a247394eb 100644 --- a/frontend/src/views/partnersStats.jsx +++ b/frontend/src/views/partnersStats.jsx @@ -9,7 +9,7 @@ import { useFetch } from '../hooks/UseFetch'; import { Leaderboard } from '../components/partners/leaderboard'; import { PartnersMapswipeStats } from './partnersMapswipeStats'; import { Resources } from '../components/partners/partnersResources'; -import { OHSOME_STATS_BASE_URL } from '../config'; +import { OHSOME_STATS_API_URL } from '../config'; import { Button } from '../components/button'; import { TwitterIcon, FacebookIcon, InstagramIcon } from '../components/svgIcons'; @@ -45,7 +45,7 @@ export const PartnersStats = () => { hashtag = hashtag.slice(1); } hashtag = hashtag.toLowerCase(); - const response = await fetch(OHSOME_STATS_BASE_URL + '/stats/hashtags/' + hashtag); + const response = await fetch(OHSOME_STATS_API_URL + '/stats/hashtags/' + hashtag); if (response.ok) { const jsonData = await response.json(); if (jsonData.result !== undefined && Object.keys(jsonData.result).length !== 0)