Skip to content

Commit

Permalink
Update test cases to reflect API restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
HelNershingThapa committed Oct 3, 2023
1 parent 1c089bb commit fd198ea
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test('FeatureStats renders the correct values and labels', async () => {
expect(screen.getByText('Km waterways mapped')).toBeInTheDocument();
await waitFor(() => expect(screen.getByText('2,380,562')).toBeInTheDocument());
expect(screen.getByText('101,367,027')).toBeInTheDocument();
expect(screen.getByText('183,011')).toBeInTheDocument();
expect(screen.getByText('350,906')).toBeInTheDocument();
// Uncomment the following when POIs and waterways become available
// expect(screen.getByText('183,011')).toBeInTheDocument();
// expect(screen.getByText('350,906')).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ describe('EditsByNumbers card', () => {

it('renders the chart if osmStats data is present', () => {
const stats = {
total_building_count_add: 3282,
total_building_count_mod: 7959,
buildings: 3282,
total_waterway_count_add: 11493,
total_poi_count_add: 10805,
total_road_km_add: 5571.84370201545,
total_road_km_mod: 4203.47860727417,
roads: 5571.84370201545,
total_waterway_km_add: 512.706405358494,
total_road_count_add: 13345,
total_road_count_mod: 51730,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ElementsMapped & TaskStats components', () => {
};
const osmStats = {
total_building_count_add: 10,
total_road_km_add: 229.113,
roads: 229.113,
total_poi_count_add: 15,
total_waterway_count_add: 20,
};
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/config/tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ it('exports API_URL', () => {
it('exports API_VERSION', () => {
expect(['object', 'string']).toContain(typeof config.API_VERSION);
});
it('exports HOMEPAGE_STATS_API_URL', () => {
expect(typeof config.HOMEPAGE_STATS_API_URL).toBe('string');
});
it('exports USER_STATS_API_URL', () => {
expect(typeof config.USER_STATS_API_URL).toBe('string');
it('exports OHSOME_STATS_BASE_URL', () => {
expect(typeof config.OHSOME_STATS_BASE_URL).toBe('string');
});
it('exports ORG_URL', () => {
expect(typeof config.ORG_URL).toBe('string');
Expand Down
21 changes: 8 additions & 13 deletions frontend/src/network/tests/mockData/homepageStats.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
export const homepageStats = {
road_count_add: 5850597,
road_count_mod: 6688860,
building_count_add: 101367027,
building_count_mod: 12680746,
waterway_count_add: 3267982,
poi_count_add: 183011,
poi_count_mod: 251157,
road_km_add: 2380562.9900000077,
road_km_mod: 1499361.339999999,
waterway_km_add: 350906.79999999935,
waterway_km_mod: 199147.73999999985,
edits: 134184186,
users: 493238,
result: {
changesets: 10251848,
users: 493238,
roads: 2380562.9900000077,
buildings: 101367027,
edits: 134184186,
latest: '2023-10-03T15:28:07Z',
},
};
7 changes: 7 additions & 0 deletions frontend/src/network/tests/mockData/miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ export const systemStats = {
totalMappers: 3,
totalProjects: 10,
};

export const ohsomeNowMetadata = {
result: {
max_timestamp: '2023-10-03T15:47:49Z',
min_timestamp: '2009-04-21T20:02:04Z',
},
};
129 changes: 14 additions & 115 deletions frontend/src/network/tests/mockData/userStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,126 +69,25 @@ export const userStats = {
],
};

export const osmStatsProd = {
id: 10291369,
name: 'helnershingthapa',
changesets: '361',
geo_extent: null,
total_building_count_add: 6771,
total_building_count_mod: 786,
total_waterway_count_add: 2,
total_poi_count_add: 81,
total_road_km_add: 29.0827659890004,
total_road_km_mod: 34.4722514676097,
total_waterway_km_add: 0.497270130447684,
total_josm_edit_count: 298,
total_gps_trace_count_add: 0,
total_gps_trace_updated_from_osm: 0,
total_road_count_add: 59,
total_road_count_mod: 250,
total_tm_done_count: 0,
total_tm_val_count: 0,
total_tm_inval_count: 0,
badges: [
{
updated_at: '2020-11-20T12:29:36.265Z',
id: 11,
category: 4,
level: 2,
name: 'The Wright Stuff',
},
{
updated_at: '2021-08-11T13:05:02.367Z',
id: 12,
category: 4,
level: 3,
name: 'The Wright Stuff',
},
{
updated_at: '2022-12-28T08:23:30.755Z',
id: 26,
category: 9,
level: 2,
name: 'World Renown',
},
],
changeset_count: 361,
latest: {
id: '130862065',
road_count_add: 0,
road_count_mod: 1,
building_count_add: 7,
building_count_mod: 2,
waterway_count_add: 0,
poi_count_add: 0,
gpstrace_count_add: 0,
road_km_add: 0,
road_km_mod: 0.00768819386078029,
waterway_km_add: 0,
gpstrace_km_add: 0,
editor: 'JOSM/1.5 (18583 en)',
export const ohsomeNowUserStats = {
result: {
building_count: 2,
road_length: 572.750505196795,
edits: 12618,
user_id: 10291369,
created_at: '2023-01-04T11:15:22.000Z',
countries: [
{
id: 175,
name: 'Nepal',
code: 'NPL',
},
],
hashtags: [
{
id: 4,
hashtag: 'awesome',
},
{
id: 2101,
hashtag: 'hot',
},
{
id: 14913965,
hashtag: 'ootd',
},
{
id: 17849271,
hashtag: 'art',
},
],
},
edit_times: [
'2019-09-11T00:00:00.000Z',
'2019-09-12T00:00:00.000Z',
'2019-11-15T00:00:00.000Z',
'2020-01-27T00:00:00.000Z',
'2020-02-28T00:00:00.000Z',
'2020-11-20T00:00:00.000Z',
'2021-02-01T00:00:00.000Z',
'2021-02-04T00:00:00.000Z',
'2021-02-12T00:00:00.000Z',
'2021-02-14T00:00:00.000Z',
],
country_count: 3,
country_list: {
NPL: 248,
MNG: 28,
IND: 11,
},
hashtags: {
awesome: 139,
hot: 126,
ootd: 97,
art: 78,
object_edits: 291,
},
};

export const osmStatsProject = {
changesets: 987654321,
users: 112,
roads: 5658.62006919192,
buildings: 12923,
edits: 123456789,
latest: '2020-10-05T23:21:22.000Z',
hashtag: `hotosm-project-1`,
result: {
changesets: 987654321,
users: 112,
roads: 5658.62006919192,
buildings: 12923,
edits: 123456789,
latest: '2020-10-05T23:21:22.000Z',
},
};

export const userLockedTasksDetails = {
Expand Down
37 changes: 20 additions & 17 deletions frontend/src/network/tests/server-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import {
import { featuredProjects } from './mockData/featuredProjects';
import {
newUsersStats,
osmStatsProd,
userStats,
osmStatsProject,
userLockedTasksDetails,
userStats,
ohsomeNowUserStats,
} from './mockData/userStats';
import { projectContributions, projectContributionsByDay } from './mockData/contributions';
import {
Expand Down Expand Up @@ -61,9 +61,15 @@ import {
} from './mockData/teams';
import { userTasks } from './mockData/tasksStats';
import { homepageStats } from './mockData/homepageStats';
import { banner, countries, josmRemote, systemStats } from './mockData/miscellaneous';
import {
banner,
countries,
josmRemote,
systemStats,
ohsomeNowMetadata,
} from './mockData/miscellaneous';
import tasksGeojson from '../../utils/tests/snippets/tasksGeometry';
import { API_URL } from '../../config';
import { API_URL, OHSOME_STATS_BASE_URL } from '../../config';
import { notifications, ownCountUnread } from './mockData/notifications';
import { authLogin, setUser, userRegister } from './mockData/auth';
import {
Expand Down Expand Up @@ -343,21 +349,18 @@ const handlers = [
return res(ctx.json(systemStats));
}),
// EXTERNAL API
rest.get('https://osmstats-api.hotosm.org/wildcard', (req, res, ctx) => {
rest.get(`${OHSOME_STATS_BASE_URL}/stats/hotosm-project-%2A`, (req, res, ctx) => {
return res(ctx.json(homepageStats));
}),
rest.get(
'https://osm-stats-production-api.azurewebsites.net/users/:username',
(req, res, ctx) => {
return res(ctx.json(osmStatsProd));
},
),
rest.get(
'https://osm-stats-production-api.azurewebsites.net/stats/:projectId',
(req, res, ctx) => {
return res(ctx.json(osmStatsProject));
},
),
rest.get(`${OHSOME_STATS_BASE_URL}/hot-tm-user`, (req, res, ctx) => {
return res(ctx.json(ohsomeNowUserStats));
}),
rest.get(`${OHSOME_STATS_BASE_URL}/stats/:projectId`, (req, res, ctx) => {
return res(ctx.json(osmStatsProject));
}),
rest.get(`${OHSOME_STATS_BASE_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));
}),
Expand Down

0 comments on commit fd198ea

Please sign in to comment.