[setup][m]: created basis for mocks and config module.
- Added minimal mock for 'package_search' CKAN API. - 'config' module is based on frontend-v2.
This commit is contained in:
parent
9bb98ce6d3
commit
b477a3aace
26
config/index.js
Normal file
26
config/index.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const nconf = require('nconf')
|
||||||
|
require('dotenv').config({path: process.env.DOTENV_PATH || '.env'})
|
||||||
|
|
||||||
|
nconf.argv()
|
||||||
|
.env()
|
||||||
|
|
||||||
|
nconf.use('memory')
|
||||||
|
|
||||||
|
const dms = (process.env.DMS || 'http://mock.ckan').replace(/\/?$/, '')
|
||||||
|
const cms = (process.env.CMS || 'http://mock.cms').replace(/\/?$/, '')
|
||||||
|
|
||||||
|
// This is the object that you want to override in your own local config
|
||||||
|
nconf.defaults({
|
||||||
|
env: process.env.NODE_ENV || 'development',
|
||||||
|
debug: process.env.DEBUG || false,
|
||||||
|
DMS: dms,
|
||||||
|
CMS: cms,
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
get: nconf.get.bind(nconf),
|
||||||
|
set: nconf.set.bind(nconf),
|
||||||
|
reset: nconf.reset.bind(nconf)
|
||||||
|
}
|
||||||
32
mocks/index.js
Normal file
32
mocks/index.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
const nock = require('nock')
|
||||||
|
|
||||||
|
module.exports.initMocks = function() {
|
||||||
|
// Uncomment this line if you want to record API calls
|
||||||
|
// nock.recorder.rec()
|
||||||
|
|
||||||
|
|
||||||
|
// "package_search" mocks
|
||||||
|
nock('http://mock.ckan/api/3/action')
|
||||||
|
.get('/package_search')
|
||||||
|
.reply(200, {
|
||||||
|
"success": true,
|
||||||
|
"result": {
|
||||||
|
"count": 2,
|
||||||
|
"sort": "score desc, metadata_modified desc",
|
||||||
|
"facets": {},
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"name": "gdp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "population"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"search_facets": {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// "package_show" mocks
|
||||||
|
|
||||||
|
// "organization_show" mocks
|
||||||
|
}
|
||||||
@ -21,7 +21,10 @@
|
|||||||
"@types/jest": "^25.2.3",
|
"@types/jest": "^25.2.3",
|
||||||
"@types/react": "^16.9.35",
|
"@types/react": "^16.9.35",
|
||||||
"babel-jest": "^26.0.1",
|
"babel-jest": "^26.0.1",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
"jest": "^26.0.1",
|
"jest": "^26.0.1",
|
||||||
|
"nconf": "^0.10.0",
|
||||||
|
"nock": "^12.0.3",
|
||||||
"postcss-preset-env": "^6.7.0",
|
"postcss-preset-env": "^6.7.0",
|
||||||
"react-test-renderer": "^16.13.1",
|
"react-test-renderer": "^16.13.1",
|
||||||
"tailwindcss": "^1.4.6",
|
"tailwindcss": "^1.4.6",
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
/* istanbul ignore file */
|
/* istanbul ignore file */
|
||||||
import '../styles/index.css'
|
import '../styles/index.css'
|
||||||
|
|
||||||
|
// Setup mocks
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
const mocks = require('../mocks')
|
||||||
|
mocks.initMocks()
|
||||||
|
console.warn('You have activated the mocks.')
|
||||||
|
}
|
||||||
|
|
||||||
export default function MyApp({ Component, pageProps }) {
|
export default function MyApp({ Component, pageProps }) {
|
||||||
return <Component {...pageProps} />
|
return <Component {...pageProps} />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user