Skip to content

Commit

Permalink
Adds v6 to mockserver (#30)
Browse files Browse the repository at this point in the history
* Updates script to create paths and use v6

* Removes mock data for v4 and v5

* Adds mock data for v6

* Updates mockserver to work with v6
  • Loading branch information
madsnedergaard authored Nov 14, 2022
1 parent af9eff7 commit 9b31ec9
Show file tree
Hide file tree
Showing 37 changed files with 57 additions and 5,586 deletions.
48 changes: 35 additions & 13 deletions mockserver/generate_mock_data.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
const axios = require('axios');
const fs = require('fs');

const writeJSON = (fileName, obj, encoding = 'utf8') => fs.writeFileSync(fileName, JSON.stringify(obj), encoding);
const writeJSON = (fileName, obj, encoding = 'utf8') =>
fs.writeFileSync(fileName, JSON.stringify(obj), encoding);

const fetchAndStoreData = async (url, savePath) => axios.get(url).then((res) => writeJSON(savePath, res.data));
const fetchAndStoreData = async (url, savePath) => {
// Create folder for savePath if it doesn't exist
const saveDir = savePath.split('/').slice(0, -1).join('/');
await fs.promises.mkdir(saveDir, { recursive: true }).catch(console.error);

const CORE_URL = 'http://localhost:8001/v5';
return axios.get(url).then((res) => writeJSON(savePath, res.data));
};

const CORE_URL = 'http://localhost:8001/v6';
const timeAggregates = ['hourly', 'daily', 'monthly', 'yearly'];
const historyZones = ['UA', 'DK-DK2'];
const detailsZones = ['UA', 'DK-DK2'];

const generateMockData = async () => {
timeAggregates.forEach(async (agg) => {
try {
await fetchAndStoreData(
`${CORE_URL}/state/${agg}`,
`./public/v6/state/${agg}.json`
);

timeAggregates.forEach(async (agg) => {
await fetchAndStoreData(`${CORE_URL}/state/${agg}`, `./public/v5/state/${agg}.json`);
await fetchAndStoreData(`${CORE_URL}/history/${agg}?countryCode=DE`, `./public/v5/history/${agg}.json`); // default history data
historyZones.forEach(async (zoneId) => {
await fetchAndStoreData(
`${CORE_URL}/history/${agg}?countryCode=${zoneId}`,
`./public/v5/history/${zoneId}/${agg}.json`
);
await fetchAndStoreData(
`${CORE_URL}/details/${agg}/DE`,
`./public/v6/details/${agg}.json`
); // default details data
detailsZones.forEach(async (zoneId) => {
await fetchAndStoreData(
`${CORE_URL}/details/${agg}/${zoneId}`,
`./public/v6/details/${zoneId}/${agg}.json`
);
});
} catch (error) {
console.error(error);
}
});
});
};

generateMockData();
1 change: 0 additions & 1 deletion mockserver/public/v4/history

This file was deleted.

1 change: 0 additions & 1 deletion mockserver/public/v4/history_DK-DK2

This file was deleted.

Loading

0 comments on commit 9b31ec9

Please sign in to comment.