const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const expect = chai.expect;
chai.use(chaiAsPromised);
chai.should();

const { mockFetch } = require('../../../util');
// const { generateEnrichmentNetworkJson } = require('../../../../src/server/routes/enrichment/visualization');
const { generateEnrichmentNetworkJson } = require('../../../../src/server/routes/enrichment/visualization');

const ENRICHMENT_NETWORK_JSON = require('./enrichment-network-json.json');

//generateGraphInfo( pathways, similarityCutoff, jaccardOverlapWeight);

describe('Test generateGraphInfo - Enrichment Vizualization Service', function () {
  it('parameters: all valid', async () => {
    global.fetch = mockFetch( { text: () => 'http://identifiers.org/name/id' } );
    const res = await generateEnrichmentNetworkJson([
      {
        "id": "GO:0006354",
        "data": {
          "name": "DNA-templated transcription, elongation",
          "p_value": "1.29e-03",
          "intersection": [
            "PAF1",
            "ZMYND11",
            "POLR2B",
            "AFF4",
            "SUPT16H",
            "ELP4",
            "GTF2H1",
            "BRD4",
            "SSRP1",
            "SETD2"
          ]
        }
      },
      {
        "id": "GO:0006368",
        "data": {
          "name": "transcription elongation from RNA polymerase II promoter",
          "p_value": "1.29e-03",
          "intersection": [
            "PAF1",
            "ZMYND11",
            "POLR2B",
            "AFF4",
            "SUPT16H",
            "ELP4",
            "GTF2H1",
            "BRD4",
            "SSRP1",
            "SETD2"
          ]
        }
      }
    ], 0.3, 0.55 );
    expect( res ).to.deep.equal( ENRICHMENT_NETWORK_JSON );
  });

  it('parameters: invalid similarityCutoff', () => {
    const result = generateEnrichmentNetworkJson({ "GO:0006354": { "p_value": 1 }, "GO:0006368": { "intersection": ["AFF4"] }}, 3.55 );
    return result.should.be.rejectedWith(Error);
  });

  it('parameters: invalid jaccardOverlapWeight', function () {
    const result =  generateEnrichmentNetworkJson({ "GO:0006354": { "p_value": 1 }, "GO:0006368": { "intersection": ["AFF4"] }}, .55, 75 );
    return result.should.be.rejectedWith(Error);
  });

});
@@ -413,16 +413,129 @@
 ation');
+%0Aconst %7B getPathwayInfoTable %7D = require('../../../../src/server/routes/enrichment/visualization/pathway-table');
 %0A%0Aconst 
@@ -801,24 +801,72 @@
 ync () =%3E %7B%0A
+    const table = await getPathwayInfoTable();%0A%0A
     global.f
@@ -987,16 +987,23 @@
 orkJson(
+table, 
 %5B%0A      
@@ -1980,23 +1980,81 @@
 utoff', 
-() =%3E %7B
+async function()%7B%0A    const table = await getPathwayInfoTable();%0A
 %0A    con
@@ -2087,32 +2087,39 @@
 mentNetworkJson(
+table, 
 %7B %22GO:0006354%22: 
@@ -2185,24 +2185,25 @@
 %7D%7D, 3.55 );%0A
+%0A
     return r
@@ -2294,16 +2294,22 @@
 Weight',
+ async
  functio
@@ -2315,16 +2315,64 @@
 on () %7B%0A
+    const table = await getPathwayInfoTable();%0A%0A
     cons
@@ -2413,16 +2413,23 @@
 orkJson(
+table, 
 %7B %22GO:00
@@ -2506,24 +2506,25 @@
  .55, 75 );%0A
+%0A
     return r

Fix tests