<commit_before>defineTest('gcp-dlp-wrapper.js', function() {
  const assert = require('chai').assert;
  let rewire = require('rewire');
  let DlpWrapper = rewire('../lib/gcp-dlp-wrapper.js');

  it('[integration] should return non-strings', function() {
    let original = "Hey it's <NAME> with ACME Corp. My SSN is 123-45-6789.";
    let expected = "Hey it's PERSON_NAME with ACME Corp. My SSN is US_SOCIAL_SECURITY_NUMBER.";
    let dlpRedactor = DlpWrapper();

    DlpWrapper.__set__('dlp', {
      getProjectId: () => Promise.resolve('mock-project'),
      projectPath: () => 'projects/mock-project',
      inspectContent: () =>
        Promise.resolve([
          {
            result: {
              findings: [
                { quote: '<NAME>', infoType: { name: 'PERSON_NAME' } },
                { quote: 'David', infoType: { name: 'FIRST_NAME' } },
                { quote: 'Johnson', infoType: { name: 'LAST_NAME' } },
                { quote: '<NAME>', infoType: { name: 'MALE_NAME' } },
                { quote: '123-45-6789', infoType: { name: 'US_SOCIAL_SECURITY_NUMBER' } }
              ]
            }
          }
        ])
    });

    dlpRedactor.redactText(original).then(res => {
      assert.equal(res, expected);
    });
  });
});<commit_msg>Add tests for regex bug fix and DLP findings priority<commit_after>defineTest('gcp-dlp-wrapper.js', function () {
  const assert = require('chai').assert;
  let rewire = require('rewire');
  let DlpWrapper = rewire('../lib/gcp-dlp-wrapper.js');

  it('[integration] should return non-strings', function (done) {
    this.timeout(2000);

    let original = "Hey it's <NAME> with ACME Corp. My SSN is 123-45-6789.";
    let expected = "Hey it's PERSON_NAME with ACME Corp. My SSN is US_SOCIAL_SECURITY_NUMBER.";
    let dlpRedactor = DlpWrapper();

    DlpWrapper.__set__('dlp', {
      getProjectId: () => Promise.resolve('mock-project'),
      projectPath: () => 'projects/mock-project',
      inspectContent: () =>
        Promise.resolve([
          {
            result: {
              findings: [
                {quote: '<NAME>', infoType: {name: 'PERSON_NAME'}},
                {quote: 'David', infoType: {name: 'FIRST_NAME'}},
                {quote: 'Johnson', infoType: {name: 'LAST_NAME'}},
                {quote: '<NAME>', infoType: {name: 'MALE_NAME'}},
                {quote: '123-45-6789', infoType: {name: 'US_SOCIAL_SECURITY_NUMBER'}}
              ]
            }
          }
        ])
    });

    dlpRedactor.redactText(original).then(res => {
      assert.equal(res, expected);
      done();
    }).catch((e) => {
      done(e);
    });
  });

  it('[integration] should not treat input as regex', function (done) {
    this.timeout(2000);

    let original = "Just call (646) 846-1111 or (646) 846-3663 or (646) 846-3663.";
    let expected = "Just call PHONE_NUMBER or PHONE_NUMBER or PHONE_NUMBER.";
    let dlpRedactor = DlpWrapper();

    DlpWrapper.__set__('dlp', {
      getProjectId: () => Promise.resolve('mock-project'),
      projectPath: () => 'projects/mock-project',
      inspectContent: () =>
        Promise.resolve([
          {
            result: {
              findings: [
                {quote: '(646) 846-1111', infoType: {name: 'PHONE_NUMBER'}},
                {quote: '(646) 846-3663', infoType: {name: 'PHONE_NUMBER'}},
                {quote: '(646) 846-3663', infoType: {name: 'PHONE_NUMBER'}},
              ]
            }
          }
        ])
    });

    dlpRedactor.redactText(original).then(res => {
      assert.equal(res, expected);
      done();
    }).catch((e) => {
      done(e);
    });

  });

  it('[integration] should prefer more likely matches', function (done) {
    this.timeout(2000);

    let original = "Just call (646) 846-FOOD or (646) 846-3663.";
    let expected = "Just call PHONE_NUMBER or PHONE_NUMBER.";
    let dlpRedactor = DlpWrapper();

    DlpWrapper.__set__('dlp', {
      getProjectId: () => Promise.resolve('mock-project'),
      projectPath: () => 'projects/mock-project',
      inspectContent: () =>
        Promise.resolve([
          {
            result: {
              findings: [
                {likelihood: 'POSSIBLE', quote: '(646) 846-FOOD', infoType: {name: 'LOCATION'}},
                {likelihood: 'VERY_LIKELY', quote: '(646) 846-FOOD', infoType: {name: 'PHONE_NUMBER'}},
                {likelihood: 'VERY_LIKELY', quote: '(646) 846-3663', infoType: {name: 'PHONE_NUMBER'}},
                {likelihood: 'POSSIBLE', quote: '(646) 846-3663', infoType: {name: 'LOCATION'}},
              ]
            }
          }
        ])
    });

    dlpRedactor.redactText(original).then(res => {
      assert.equal(res, expected);
      done();
    }).catch((e) => {
      done(e);
    });
  });
});
{'fraction_non_alphanumeric': 0.16890192791282482, 'fraction_numerical': 0.03269069572506287, 'mean_word_length': 2.22936400541272, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '626983', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1519, 'n_words': 316}