From 9d609e64614b8244169190efb701020b62500f72 Mon Sep 17 00:00:00 2001 From: Konstantin Mamalakis Date: Mon, 5 Mar 2018 23:57:30 +0200 Subject: [PATCH] Some more parsing tests --- tests/ofac/parsing.js | 271 ++++++++++++++++++++++++++++++------------ 1 file changed, 198 insertions(+), 73 deletions(-) diff --git a/tests/ofac/parsing.js b/tests/ofac/parsing.js index 8920a246..a18fb873 100644 --- a/tests/ofac/parsing.js +++ b/tests/ofac/parsing.js @@ -33,78 +33,106 @@ const partIds = new Map([ const getId = part => partIds.get(part.partName) const makePart = part => '' + - '\n\t\t\t\t\t' + - `\n\t\t\t\t\t\t` + - part.value + - '' + - '\n\t\t\t\t\t' +` + ${part.value} + ` const makeAlias = alias => '' + - '\n\t\t\t' + - `\n\t\t\t\t` + - _.map(makePart, alias.parts) + - '\n\t\t\t\t' + - '\n\t\t\t' +` + +${_.map(makePart, alias.parts)} + + ` const makePartGroup = part => '' + - '\n\t\t\t\t' + - '\n\t\t\t\t\t` + - '\n\t\t\t\t' +` + + ` const makePartGroups = alias => mapLines(makePartGroup, alias.parts) const makeBirthDate = birthDate => '' + - '\n\t\t' + - '\n\t\t\t' + - '\n\t\t\t\t' + - '\n\t\t\t\t\t' + - '\n\t\t\t\t\t\t' + - `\n\t\t\t\t\t\t\t${birthDate.start.year}` + - `\n\t\t\t\t\t\t\t${birthDate.start.month}` + - `\n\t\t\t\t\t\t\t${birthDate.start.day}` + - '\n\t\t\t\t\t\t' + - '\n\t\t\t\t\t\t' + - `\n\t\t\t\t\t\t\t${birthDate.start.year}` + - `\n\t\t\t\t\t\t\t${birthDate.start.month}` + - `\n\t\t\t\t\t\t\t${birthDate.start.day}` + - '\n\t\t\t\t\t\t' + - '\n\t\t\t\t\t' + - '\n\t\t\t\t\t' + - '\n\t\t\t\t\t\t' + - `\n\t\t\t\t\t\t\t${birthDate.end.year}` + - `\n\t\t\t\t\t\t\t${birthDate.end.month}` + - `\n\t\t\t\t\t\t\t${birthDate.end.day}` + - '\n\t\t\t\t\t\t' + - '\n\t\t\t\t\t\t' + - `\n\t\t\t\t\t\t\t${birthDate.end.year}` + - `\n\t\t\t\t\t\t\t${birthDate.end.month}` + - `\n\t\t\t\t\t\t\t${birthDate.end.day}` + - '\n\t\t\t\t\t\t' + - '\n\t\t\t\t\t' + - '\n\t\t\t\t' + - '\n\t\t\t' + - '\n\t\t' +` + + + + + ${birthDate.start.year} + ${birthDate.start.month} + ${birthDate.start.day} + + + ${birthDate.start.year} + ${birthDate.start.month} + ${birthDate.start.day} + + + + + ${birthDate.end.year} + ${birthDate.end.month} + ${birthDate.end.day} + + + ${birthDate.end.year} + ${birthDate.end.month} + ${birthDate.end.day} + + + + + ` const makeProfile = profile => { - console.log(profile.birthDates) + console.log(profile.birthDatePeriods) return '' + - `\n\t` + - '\n\t\t' + - mapLines(makeAlias, profile.aliases) + - '\n\t\t\t' + - mapLines(makePartGroups, profile.aliases) + - '\n\t\t\t' + - '\n\t\t' + - mapLines(makeBirthDate, profile.birthDates) + - '\n\t' +` + +${mapLines(makeAlias, profile.aliases)} + +${mapLines(makePartGroups, profile.aliases)} + + +${mapLines(makeBirthDate, profile.birthDatePeriods)} + ` } -const makeXml = profiles => '' + - '\n' + - mapLines(makeProfile, profiles) + - '\n' +const makeXml = profiles => '' + +` + +${mapLines(makeProfile, profiles)} +` + + +const individualA = {id: '9', aliases: [{id: '5', + parts: [ + {partName: 'firstName', value: 'john'}, + {partName: 'lastName', value: 'doe'}], + fullName: 'john doe', + words: [ + {value: 'john', phonetics: ['JN', 'AN']}, + {value: 'doe', phonetics: ['T']}]}], + birthDatePeriods: [{ + start: {year: 1955, month: 10, day: 5, date: new Date(1955, 9, 5)}, + end: {year: 1955, month: 10, day: 5, date: new Date(1955, 9, 5)}}] +} + +const individualB = {id: '11', aliases: [{id: '15', + parts: [ + {partName: 'firstName', value: 'john'}, + {partName: 'middleName', value: 'de'}, + {partName: 'lastName', value: 'gaul'}], + fullName: 'john de gaul', + words: [ + {value: 'john', phonetics: ['JN', 'AN']}, + {value: 'de', phonetics: ['T']}, + {value: 'gaul', phonetics: ['KL']}]}], + birthDatePeriods: [{ + start: {year: 1965, month: 11, day: 20, date: new Date(1965, 10, 20)}, + end: {year: 1965, month: 11, day: 20, date: new Date(1965, 10, 20)}}] +} describe('OFAC', function () { @@ -124,45 +152,142 @@ describe('OFAC', function () { }) it('should return the expected structs', function () { - const xml = makeXml([{ - id: '1', aliases: [{ - id: '1', - parts: [ - {partName: 'firstName', value: 'John'}, - {partName: 'lastName', value: 'Doe'}] - }], - birthDates: [{ - start: {year: 1955, month: 10, day: 5}, - end: {year: 1955, month: 10, day: 5} - }] - }]) + const xml = makeXml([individualA]) + return makeDataFiles([xml]).then(parser.parse) .then(structs => { const {individuals} = structs assert.ok(Array.isArray(individuals)) assert.equal(individuals.length, 1) + assert.deepEqual(individuals[0], individualA) const {individualsMap} = structs assert.ok(individualsMap instanceof Map) assert.equal(individualsMap.size, 1) + assert.ok(individualsMap.has('9')) + assert.deepEqual(individualsMap.get('9'), individualA) const {aliasToIndividual} = structs assert.ok(aliasToIndividual instanceof Map) assert.equal(aliasToIndividual.size, 1) + assert.ok(aliasToIndividual.has('5')) + assert.strictEqual(aliasToIndividual.get('5'), '9') const {phoneticMap} = structs assert.ok(phoneticMap instanceof Map) assert.equal(phoneticMap.size, 3) + assert.ok(phoneticMap.has('JN')) + assert.deepEqual(phoneticMap.get('JN'), [{value: 'john', aliasId: '5'}]) + assert.ok(phoneticMap.has('AN')) + assert.deepEqual(phoneticMap.get('AN'), [{value: 'john', aliasId: '5'}]) + assert.ok(phoneticMap.has('T')) + assert.deepEqual(phoneticMap.get('T'), [{value: 'doe', aliasId: '5'}]) const {wordList} = structs assert.ok(Array.isArray(wordList)) assert.equal(wordList.length, 2) + assert.deepEqual(wordList[0], {value: 'john', aliasIds: ['5']}) + assert.deepEqual(wordList[1], {value: 'doe', aliasIds: ['5']}) }) }) - it('should be able to parse multiple sources') + it('should be able to combine multiple sources', function () { + const xmlA = makeXml([individualA]) + const xmlB = makeXml([individualB]) - it('should remove duplicates from multiple sources') + return makeDataFiles([xmlA, xmlB]).then(parser.parse) + .then(structs => { + const {individuals} = structs + assert.ok(Array.isArray(individuals)) + assert.equal(individuals.length, 2) + assert.deepEqual(individuals[0], individualA) + assert.deepEqual(individuals[1], individualB) + + const {individualsMap} = structs + assert.ok(individualsMap instanceof Map) + assert.equal(individualsMap.size, 2) + assert.ok(individualsMap.has('9')) + assert.deepEqual(individualsMap.get('9'), individualA) + assert.ok(individualsMap.has('11')) + assert.deepEqual(individualsMap.get('11'), individualB) + + const {aliasToIndividual} = structs + assert.ok(aliasToIndividual instanceof Map) + assert.equal(aliasToIndividual.size, 2) + assert.ok(aliasToIndividual.has('5')) + assert.strictEqual(aliasToIndividual.get('5'), '9') + assert.ok(aliasToIndividual.has('15')) + assert.strictEqual(aliasToIndividual.get('15'), '11') + + const {phoneticMap} = structs + assert.ok(phoneticMap instanceof Map) + assert.equal(phoneticMap.size, 4) + assert.ok(phoneticMap.has('JN')) + assert.deepEqual(phoneticMap.get('JN'), [ + {value: 'john', aliasId: '5'}, + {value: 'john', aliasId: '15'} + ]) + assert.ok(phoneticMap.has('AN')) + assert.deepEqual(phoneticMap.get('AN'), [ + {value: 'john', aliasId: '5'}, + {value: 'john', aliasId: '15'} + ]) + assert.ok(phoneticMap.has('T')) + assert.deepEqual(phoneticMap.get('T'), [ + {value: 'doe', aliasId: '5'}, + {value: 'de', aliasId: '15'} + ]) + + const {wordList} = structs + assert.ok(Array.isArray(wordList)) + assert.equal(wordList.length, 4) + assert.deepEqual(wordList[0], {value: 'john', aliasIds: ['5', '15']}) + assert.deepEqual(wordList[1], {value: 'doe', aliasIds: ['5']}) + assert.deepEqual(wordList[2], {value: 'de', aliasIds: ['15']}) + assert.deepEqual(wordList[3], {value: 'gaul', aliasIds: ['15']}) + }) + }) + + it('should remove duplicates from multiple sources', function () { + const xmlA1 = makeXml([individualA, individualA]) + const xmlA2 = makeXml([individualA]) + + return makeDataFiles([xmlA1, xmlA2]).then(parser.parse) + .then(structs => { + const {individuals} = structs + assert.ok(Array.isArray(individuals)) + assert.equal(individuals.length, 1) + assert.deepEqual(individuals[0], individualA) + + const {individualsMap} = structs + assert.ok(individualsMap instanceof Map) + assert.equal(individualsMap.size, 1) + assert.ok(individualsMap.has('9')) + assert.deepEqual(individualsMap.get('9'), individualA) + + const {aliasToIndividual} = structs + assert.ok(aliasToIndividual instanceof Map) + assert.equal(aliasToIndividual.size, 1) + assert.ok(aliasToIndividual.has('5')) + assert.strictEqual(aliasToIndividual.get('5'), '9') + + const {phoneticMap} = structs + assert.ok(phoneticMap instanceof Map) + assert.equal(phoneticMap.size, 3) + assert.ok(phoneticMap.has('JN')) + assert.deepEqual(phoneticMap.get('JN'), [{value: 'john', aliasId: '5'}]) + assert.ok(phoneticMap.has('AN')) + assert.deepEqual(phoneticMap.get('AN'), [{value: 'john', aliasId: '5'}]) + assert.ok(phoneticMap.has('T')) + assert.deepEqual(phoneticMap.get('T'), [{value: 'doe', aliasId: '5'}]) + + const {wordList} = structs + assert.ok(Array.isArray(wordList)) + assert.equal(wordList.length, 2) + assert.deepEqual(wordList[0], {value: 'john', aliasIds: ['5']}) + assert.deepEqual(wordList[1], {value: 'doe', aliasIds: ['5']}) + }) + }) }) })