{"size": 1254, "ext": "js", "max_stars_repo_path": "src/components/bpmnlint/test/spec/test-rule-spec.js", "max_stars_repo_name": "Liuhuang814/SQM", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/bpmnlint/test/spec/test-rule-spec.js", "max_issues_repo_name": "Liuhuang814/SQM", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/bpmnlint/test/spec/test-rule-spec.js", "max_forks_repo_name": "Liuhuang814/SQM", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.7164179104, "max_line_length": 65, "alphanum_fraction": 0.6084529506}
import testRule from '../../lib/test-rule';

import { expect, createRule, readModdle } from '../helper';

import { is } from 'bpmnlint-utils';


describe('test-rule', function() {

  let moddleRoot;

  beforeEach(async function() {
    const result = await readModdle(__dirname + '/diagram.bpmn');

    moddleRoot = result.root;
  });

  it('should return reported messages', () => {

    // given
    const expectedMessages = [
      {
        id: 'sid-38422fae-e03e-43a3-bef4-bd33b32041b2',
        message: 'Definitions detected'
      }
    ];
    const messages = testRule({
      moddleRoot,
      rule: createRule(fakeRuleWithReports)
    });

    // then
    expect(messages).to.eql(expectedMessages);
  });


  it('should empty messages', () => {

    // given
    const expectedMessages = [];

    // when
    const messages = testRule({
      moddleRoot,
      rule: createRule(fakeRuleWithoutReports)
    });

    // then
    expect(messages).to.eql(expectedMessages);
  });

});

function fakeRuleWithReports() {
  function check(node, reporter) {
    if (is(node, 'Definitions')) {
      reporter.report(node.id, 'Definitions detected');
    }
  }

  return { check };
}

function fakeRuleWithoutReports() {
  return { check: () => {} };
}
