Skip to content

Commit

Permalink
#4 fix breaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Mar 25, 2020
1 parent f244fa9 commit 81db604
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/__tests__/CSISHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import apiResponseStudy from './../__fixtures__/study.json';
import apiResponseDataPackage from './../__fixtures__/dataPackage.json';
import apiResponseResources from './../__fixtures__/resources.json';
import studyArea from './../__fixtures__/studyArea.json';
// see https://github.com/clarity-h2020/simple-table-component/issues/4#issuecomment-595115802
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

const app = express();
var server;

beforeAll(() => {
// required because of https://github.com/clarity-h2020/simple-table-component/issues/4#issuecomment-603834161
axios.defaults.adapter = require('axios/lib/adapters/http');

app.get('/jsonapi/group/study', function (req, res) {
res.json(apiResponseStudy);
});
Expand All @@ -31,13 +37,20 @@ beforeAll(() => {
res.json(apiResponseResources);
});

server = app.listen(31336, () => log.debug('Example app listening on port 31336!'))
server = app.listen(0, () => log.debug(`Example app listening on http://${server.address().address}:${server.address().port}`));
log.debug(`Example app listening on http://${server.address().address}:${server.address().port}`);
});


/**
* duplicate content
* we have exactly the same tests in map-component but we cannot reuse them in another project. :-(
*/
test('test extract study area from study json', async (done) => {
expect.assertions(5);
const response = await axios.get('http://localhost:31336/jsonapi/group/study?filter[id][condition][path]=id&filter[id][condition][operator]=%3D&filter[id][condition][value]=c3609e3e-f80f-482b-9e9f-3a26226a6859');
const url = `http://localhost:${server.address().port}/jsonapi/group/study?filter[id][condition][path]=id&filter[id][condition][operator]=%3D&filter[id][condition][value]=c3609e3e-f80f-482b-9e9f-3a26226a6859`;
// unbelievable: does not print to console. See https://github.com/facebook/jest/issues/2441
log.info(url);
const response = await axios.get(url);
expect(response).toBeDefined();
expect(response.data).toBeDefined();
expect(response.data.data).toBeDefined();
Expand Down
9 changes: 7 additions & 2 deletions src/__tests__/CSISRemoteHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
* ***************************************************
*/

// OMG: Nee to duplicate tests, since we cannot export them
// See https://github.com/p-a-s-c-a-l
// OMG: Need to duplicate tests, since we cannot export them


import axios from 'axios';
import log from 'loglevel';

// see https://github.com/clarity-h2020/simple-table-component/issues/4#issuecomment-595115802
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

import { CSISRemoteHelpers, CSISHelpers} from 'csis-helpers-js';

import apiResponseStudy from './../__fixtures__/study.json';
Expand All @@ -24,6 +28,7 @@ log.enableAll();
* Set auth headers for live API test
*/
beforeAll(async (done) => {
axios.defaults.adapter = require('axios/lib/adapters/http');
//axios.defaults.withCredentials = true;
if (process.env.COOKIE && process.env.ORIGIN) {
log.info('headers.js fixture found, executing remote API tests');
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/CSISResource.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import CSISResource from '../classes/CSISResource';
// see https://github.com/clarity-h2020/simple-table-component/issues/4#issuecomment-595115802
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

import apiResponseResources from './../__fixtures__/resources.json';

Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/EMIKATHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import ReactDOM from 'react-dom';
import {EMIKATHelpers} from 'csis-helpers-js';
import GenericEmikatTable from './../components/commons/GenericEmikatTable';

// see https://github.com/clarity-h2020/simple-table-component/issues/4#issuecomment-595115802
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

//import {create, router, defaults, rewriter} from 'json-server';
import express from 'express'
import populationExposure from './../__fixtures__/tab.CLY_EL_POPULATION_INTERPOLATED.2016.json';
Expand All @@ -23,12 +27,13 @@ var server;

beforeAll(() => {
console.log('beforeAll');
axios.defaults.adapter = require('axios/lib/adapters/http');
// respond with "hello world" when a GET request is made to the homepage
app.get('/EmiKatTst/api/scenarios/2846/feature/tab.CLY_EL_POPULATION_INTERPOLATED.2016/table/data', function (req, res) {
res.json(populationExposure);
})

server = app.listen(31337, () => console.log('Example app listening on port 3000!'))
server = app.listen(31337, () => console.log('Example app listening on port 31337!'))
});

it ('tests JSON API', async (done) => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/GenericEmikatClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('EMIKAT API tests with authentication', () => {
const div = document.createElement('div');
ReactDOM.render(
<GenericEmikatClient
emikatUrl={'https://service.emikat.at/EmiKatTst/api/scenarios/2846/feature/tab.CLY_EL_POPULATION_INTERPOLATED.2016/table/data?rownum=100'}
emikatUrl={'https://service.emikat.at/EmiKatTst/api/scenarios/2846/feature/tab.CLY_EL_POPULATION_INTERPOLATED.2016/table/data?rownum=1000'}
emikatCredentials={process.env.EMIKAT_CREDENTIALS}
render={GenericEmikatTable}>
</GenericEmikatClient>
Expand Down

0 comments on commit 81db604

Please sign in to comment.