{"size": 3869, "ext": "js", "max_stars_repo_path": "context/app/static/js/components/detailPage/provenance/ProvVis/__tests__/ProvData.spec.js", "max_stars_repo_name": "mccalluc/flask-data-portal", "max_stars_repo_stars_event_min_datetime": "2020-04-14T16:39:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T19:30:55.000Z", "max_issues_repo_path": "context/app/static/js/components/detailPage/provenance/ProvVis/__tests__/ProvData.spec.js", "max_issues_repo_name": "mccalluc/flask-data-portal", "max_issues_repo_issues_event_min_datetime": "2019-10-17T19:00:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:48:59.000Z", "max_forks_repo_path": "context/app/static/js/components/detailPage/provenance/ProvVis/__tests__/ProvData.spec.js", "max_forks_repo_name": "mccalluc/flask-data-portal", "max_forks_repo_forks_event_min_datetime": "2020-07-01T15:20:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-20T15:16:07.000Z"}
{"max_stars_count": 13, "max_issues_count": 1727, "max_forks_count": 4, "avg_line_length": 24.18125, "max_line_length": 113, "alphanum_fraction": 0.4706642543}
import ProvData, { makeCwlInput, makeCwlOutput } from '../ProvData';

import * as fixtures from './fixtures';

console.warn = (...args) => {
  if (args[0] !== 'HORZ') {
    // TODO: Remove when upstream PR is merged: https://github.com/4dn-dcic/react-workflow-viz/pull/7
    console.warn(...args);
  }
};

// TODO: Hitting validation errors.
// describe('Prov fixtures', () => {
//   Object.entries(fixtures).forEach(([k, v]) => {
//     it(`converts ${k} W3C JSON to 4DN CWL`, () => {
//       const cwl = new ProvData(v.prov, v.getNameForActivity, v.getNameForEntity).toCwl();
//       expect(cwl).toEqual(v.cwl, `Mismatch (full after diff):\n${JSON.stringify(cwl, null, 2)}`);
//     });
//   });
// });

describe('ProvData errors', () => {
  it('has expected error message', () => {
    let message;
    try {
      new ProvData({}); // eslint-disable-line no-new
    } catch (e) {
      message = e.message;
    }
    expect(message).toContain("should have required property 'prefix'");
  });
});

describe('ProvData methods', () => {
  const prov = new ProvData(fixtures.complex.prov);

  it('getParentEntityNames', () => {
    expect(prov.getParentEntityNames('hubmap:act-4')).toEqual(['hubmap:ent-1', 'hubmap:ent-3', 'hubmap:ent-4']);
  });

  it('getChildEntityNames', () => {
    expect(prov.getChildEntityNames('hubmap:act-2')).toEqual(['hubmap:ent-4', 'hubmap:ent-7']);
  });

  it('getParentActivityNames', () => {
    expect(prov.getParentActivityNames('hubmap:ent-6')).toEqual(['hubmap:act-4']);
  });

  it('getChildActivityNames', () => {
    expect(prov.getChildActivityNames('hubmap:ent-1')).toEqual(['hubmap:act-1', 'hubmap:act-2', 'hubmap:act-4']);
  });
});

// No such function: Maybe version mismatch?
//
// describe('PROV expansion', () => {
//   it('should expand prefixes', () => {
//     expect(
//       expand(
//         {
//           'do:C': { 're:D': 'mi:E' },
//           're:D': { 're:D': 'not-expanded' },
//         },
//         {
//           do: 'deer#',
//           re: 'drop-of-golden-sun#',
//           mi: 'name-i-call-myself#',
//         },
//       ),
//     ).toEqual({
//       'deer#C': { 'drop-of-golden-sun#D': 'name-i-call-myself#E' },
//       'drop-of-golden-sun#D': { 'drop-of-golden-sun#D': 'not-expanded' },
//     });
//   });
// });

describe('CWL utils', () => {
  it('makeCwlInput reference', () => {
    expect(makeCwlInput('name1', [], { extras: 'go here!' }, true)).toEqual({
      meta: {
        global: true,
        in_path: true,
        type: 'reference file',
      },
      name: 'name1',
      run_data: {
        file: [
          {
            '@id': 'name1',
          },
        ],
      },
      source: [
        {
          for_file: 'name1',
          name: 'name1',
        },
      ],
      prov: {
        extras: 'go here!',
      },
    });
  });

  it('makeCwlInput with step', () => {
    expect(makeCwlInput('name1', ['step1'], { extras: 'go here!' })).toEqual({
      meta: {
        global: true,
        in_path: true,
        type: 'data file',
      },
      name: 'name1',
      run_data: {
        file: [
          {
            '@id': 'name1',
          },
        ],
      },
      source: [
        {
          for_file: 'name1',
          name: 'name1',
          step: 'step1',
        },
      ],
      prov: {
        extras: 'go here!',
      },
    });
  });

  it('makeCwlOutput', () => {
    expect(makeCwlOutput('name1', ['step1'], { extras: 'go here!' })).toEqual({
      meta: {
        global: true,
        in_path: true,
        type: 'data file',
      },
      name: 'name1',
      run_data: {
        file: [
          {
            '@id': 'name1',
          },
        ],
      },
      target: [
        {
          name: 'name1',
          step: 'step1',
        },
      ],
      prov: {
        extras: 'go here!',
      },
    });
  });
});
